xxxxxxxxxx
45
var bx;
var by;
var vx = 2.1;
var vy = 2.3;
var diam;
function setup() {
createCanvas(600, 600);
by = height / 2;
bx = width / 2;
diam = width / 20;
}
function draw() {
background(0);
strokeWeight(2);
fill('white');
ellipse(bx, by, diam, diam);
bx = bx + vx;
by = by + vy;
var off = diam /2;
if( bx < off){
vx *= -1;
}
if(by > height - off || by < off){
vy *= -1;
}
var rectHeight = width / 20;
var rectWidth = 4 * rectHeight;
noStroke();
rectMode(CORNERS);
rect(500, mouseY, 500 + rectHeight, mouseY + rectWidth);
var b = by >= mouseY && by <= mouseY + rectWidth ;
if(bx > 500 - off && b){
vx *= - 1;
vy *= -1;
}
}