xxxxxxxxxx
67
//press the mouse
//zhiying deng, oct 31
//declare global variables x,y and d
let x, y;
let col;
const w = 10;
function setup() {
createCanvas(windowWidth, windowHeight);
background(0);
noStroke();
col = color(random(255), random(255), random(255));
x = width / 2;
y = height / 2;
frameRate(20);
rectMode(CENTER);
}
function draw() {
blendMode(LIGHTEST);
let ran = random();
if (ran < 0.25) x += w;
else if (ran < 0.5) y += w;
else if (ran < 0.75) x -= w;
else y -= w;
if (ran < 0.2) {
fill(255, 0, 200);
rect(x, y, w);
} else if (ran < 0.4) {
fill(col, 200, 200);
ellipse(x, y, w);
} else if (ran < 0.6) {
fill(200, col, 255);
rect(x, y, w);
} else if (ran < 0.8) {
fill(col);
ellipse(x, y, w);
} else {
fill(255);
rect(x, y, w);
}
// fill(col);
if (x > windowWidth) {
x = x - w;
}
if (y > windowHeight) {
y = x - w;
}
if (x < 0) {
x = x + w;
}
if (y < 0) {
y = y + w;
}
//press the mouse
if(mouseIsPressed){
x = mouseX;
y = mouseY;
}
rect(mouseX, mouseY, w);
}