xxxxxxxxxx
26
let a=0;
let aspeed=1;
function setup() {
createCanvas(windowWidth, windowHeight);
colorMode(HSB,360,100,100);
noStroke();
speed=1;
}
function draw() {
background(220);
a+=aspeed;
aspeed=bounce(a,0,360,aspeed);
for(let i=0;i<2;i++){
let h=i*a;
h%=360;
fill(h,100,100);
let x=i*width/2;
rect(x,0,width/2,height)
}
}
function bounce(pos,low,high,speed){
if(pos<low||pos>high) return speed*=-1;
else return speed;
}