top of page

ICM W5

DO: The idea this week is to explore re-organizing your code. It is 100% legitimate to turn in a version of a previous assignment where nothing changes for the end user, but the code has been restructured. You may, however, choose to try a new experiment from scratch. Aim to keep setup() and draw() as clean as possible, and do everything (all calculations, drawing, etc.) in functions that you create yourself. Possibilities (choose one or more):

Reorganize "groups of variables" into objects. | How to do this.Break code out of setup() and draw() into functions.Use a function to draw a complex design multiple times with different arguments.If you are feeling ambitious, try embedding a function into an object.




link to sketch:


Code:

let x, y;

let on = false;


function setup() {

createCanvas(400, 400);

x = width / 2;

y = height / 2;

}


function draw() {

background(13, 3, 152);

moon(48,48);

followmouse();

cloud(100,50);

}


function moon(sizeX, sizeY) {

noStroke();

fill(255, 246, 107);

ellipse(x, y, sizeX, sizeY);

}


function followmouse(){

x += (mouseX - x) / 120;

y += (mouseY - y-25) / 120;

}


function cloud(x,y){

if (on){

noStroke();

fill('white');

arc(mouseX-30, mouseY, 30, 30, PI, 0);

arc(mouseX-15, mouseY, 25, 40, PI, 0);

arc(mouseX, mouseY, 40, 50, PI, 0);

arc(mouseX+20, mouseY, 30, 30, PI, 0);

}

}


function mousePressed() {

on = !on;

}



Post: Blog2_Post
bottom of page