ICM – Week 3

I cannot for the life of me figure out why a code taken directly from Dan’s video (4.2) will not run. Here’s a screenshot of what’s going on:

Anyway, here’s the homework assignment for this week. I added a spiraling circle to the canvas:


function setup() {
createCanvas(640, 360);
}
function draw() {
background(255);
for (var y = 0; y < height; y += 20) {
for (var x = 0; x < width; x += 20) { if (random(1) > 0.5) {
line(x, y, x + 20, y + 20);
} else {
line(x, y + 20, x + 20, y);
}
}
}
noLoop();
}

Then I added an if statement to add a green background when the mouse is pressed.

And here’s the final result:

(This code was loosely based on a chapter of Getting Started with p5.js. p.135)

………………………………………………………………………………………………………………..

To change parts of my partners code I altered the background color, made the ellipses bigger and added a strokeWeight around each ellipse.

Here is the final result and code:

let x=0;
let y=0;
function setup() {
createCanvas(400, 400);
}
function draw() {
background(0);
if(mouseIsPressed){
background(210,0,random(150));
for(let x=mouseX; x<= width;x+=40){
for(let y=mouseY; y<= height; y+=40){
strokeWeight(2);
fill(random(200),random(200),0);
ellipse(x,y,50);
}
}
}
}