xxxxxxxxxx
47
let x;
let a1, a2;
let aspeed1 = 0.1;
let aspeed2 = 0.1;
function setup() {
createCanvas(windowWidth, windowHeight);
noStroke();
a1 = 145;
a2 = 145;
x = width / 2;
}
function draw() {
background(0);
a1 += aspeed1;
a2 += aspeed2
a1 = constrain(a1, 0, 145);
a2 = constrain(a2, 0, 145);
fill(255, a1);
rect(0, 0, x, height);
fill(255, a2);
rect(x, 0, width - x, height);
}
function bounce(speed, loc, low, high) {
if (loc < low || loc > high) {
return speed *= -1;
}
return speed;
}
function mousePressed() {
x = mouseX;
}
function keyPressed() {
let speed = mouseY / height;
aspeed1 = aspeed1 > 0 ? 1 * speed : -1 * speed;
aspeed2 = aspeed2 > 0 ? 1 * speed : -1 * speed;
if (mouseX < x) aspeed1 *= -1;
else aspeed2 *= -1;
console.log(aspeed1, aspeed2, a1, a2);
}