dynamic drawingvar angle = 0;
function setup() {
createCanvas(600, 450);
}
function draw() {
if (mouseY < height/7) {
background (188, 210, 232); } else if (mouseY < (height/7)*2) {
background (145, 186, 214);
} else if (mouseY < (height/7)*3) {
background (115, 165, 198);
} else if (mouseY < (height/7)*4) {
background (82, 138, 174);
} else if (mouseY < (height/7)*5) {
background (46, 89, 132);
} else if (mouseY < (height/7)*6) {
background (30, 63, 102);
} else {
background (23, 47, 77); }
stroke(0);
strokeWeight(3);
line(250, 175, 250, 275); line(250, 175, 350, 175); line(350, 175, 350, 275); line(250, 275, 350, 275); fill(79, 37, 37); rect(250, 175, 100, 100);
if (mouseX < 250 & mouseY > 175 && mouseY < 275) { line(200, 150, 250, 175);
line(200, 300, 250, 275);
var r = 255; var g = 180;
var b = 200;
fill(r, g, b);
circle(mouseX, mouseY, 300-mouseX); fill(r-mouseX, g-mouseX, b-mouseX); circle(0, mouseY, mouseX);
} else if (mouseX > 350 & mouseY > 175 && mouseY < 275) { line(350, 175, 400, 150);
line(350, 275, 400, 300);
if(mouseX > 350 & mouseX <450) {
fill(235, 207, 52); } else {
fill(52, 235, 116); }
push();
translate(350, 225);
rotate(radians(angle));
rectMode(CENTER);
rect(50, 50, mouseX-300, mouseX-300); pop();
if (mouseX > 350 & mouseX < 450){ angle += 3; } else { angle -= 3; }
} else if (mouseY < 175 & mouseX > 250 && mouseX < 350) { line(200, 150, 250, 175);
line(350, 175, 400, 150);
var circleX = 300;
var circleY = 150;
var size = constrain(dist(mouseX, mouseY, circleX, circleY),0, 30);
fill(115, 105, 205); circle(circleX, circleY, size); circle(circleX, circleY-30, size*2); circle(circleX, circleY-60, size); circle(circleX, circleY-90, size*2); circle(circleX, circleY-120, size);
} else if (mouseY > 275 & mouseX > 250 && mouseX < 350) { line(200, 300, 250, 275);
line(350, 275, 400, 300);
stroke(255, 230, 0); line(287.5, 362.5, mouseX, mouseY);
line(287.5, 362.5, mapx, mapy+180);
line(287.5, 362.5, mapx+40, mapy);
line(287.5, 362.5, mapx, mapy+200);
var mapx = map(mouseX, 250, 350, 210, 310); var mapy = map(mouseY, 275, 450, 235, 410);
stroke(122, 255, 105); line(287.5, 362.5, mapx, mapy);
line(287.5, 362.5, mapx-130, mapy-50);
line(287.5, 362.5, mapx-40, mapy-20);
line(287.5, 362.5, mapx-130, mapy+150);
line(287.5, 362.5, mapx-150, mapy-39);
stroke(248, 59, 255); line(287.5, 362.5, mapx*2, mapy*2);
line(287.5, 362.5, mapx*1.1, mapy);
line(287.5, 362.5, mapx, mapy+220);
line(287.5, 362.5, mapx+50, mapy);
line(287.5, 362.5, mapx-80, mapy);
stroke(150, 255, 250); line(287.5, 362.5, mapx*1.5, mapy);
line(287.5, 362.5, mapx-195, mapy+239);
line(287.5, 362.5, mapx-230, mapy+180);
line(287.5, 362.5, mapx+10, mapy+50);
line(287.5, 362.5, mapx, mapy+190);
line(287.5, 362.5, mapx*0.2, mapy*2);
stroke(255, 150, 217); line(287.5, 362.5, mapx-20, mapy);
line(287.5, 362.5, mapx-100, mapy);
line(287.5, 362.5, mapx-170, mapy+20);
}
}
The idea behind this drawing is a box that reveals different changing elements depending on where you put your mouse. The most challenging part of this project was figuring out how to make the elements change based on their interaction with mouseX and mouseY. I had to do some trial-and-error to get the effects that I wanted.