xxxxxxxxxx
62
let speedX=5;
let speedY = 5;
let x = 20;
let y = 200;
let c = 0;
let xOffset = 0;
let yOffset = 0;
let n =0;
//initial setup
function setup() {
createCanvas(400, 400);
background(255);
noStroke();
imageMode(CENTER);
}
function draw() {
//drawing and moving the ellipse
fill(c);
ellipse(x,y, 40,40);
x+= speedX;
y+=speedY
//bounce on x
if (x>=width-20 || x<=20){
speedX*=-1;
xOffset +=5;
}
//choose a rnaomd color and bounce on y
if (y>=height-20 || y<=20){
speedY*=-1;
c = random(255);
y+=speedY*3;
yOffset+=5;
}
//create boxes with noise on y axis
for(let i =0; i <= 1000; i+=50){
for(let j =0; j <= 1000; j+=50){
n = noise( (i+xOffset)*0.005, (j*yOffset)*0.005);
n*=j;
rect(n, j, 20,20);
}
}
//create boxes with noise on x axis
for(let i =0; i <= 1000; i+=50){
for(let j =0; j <= 1000; j+=50){
n = noise( (i+xOffset)*0.005, (j*yOffset)*0.005);
n*=i;
j+=n;
rect(i, n, 20,20);
}
}
}