xxxxxxxxxx
51
var position1, velocity1, size1;
var position2, velocity2, size2;
function setup() {
createCanvas(400, 400);
position1 = createVector(100,100);
velocity1 = createVector(2,1);
size1 = createVector(10, 10);
position2 = createVector(200,200);
velocity2 = createVector(-4,2);
size2 = createVector(10, 10);
}
function draw() {
background(240);
noStroke();
fill(200,0,200);
ellipse(position1.x, position1.y, size1.x, size1.y);
position1.add(velocity1);
if (position1.x > 400 || position1.x < 0) {
velocity1.x *= -1;
}
if (position1.y > 400 || position1.y < 0) {
velocity1.y *= -1;
}
noStroke();
fill(255,100,0);
ellipse(position2.x, position2.y, size2.x, size2.y);
position2.add(velocity2);
if (position2.x > 400 || position2.x < 0) {
velocity2.x *= -1;
}
if (position2.y > 400 || position2.y < 0) {
velocity2.y *= -1;
}
if (position1.x == position2.x) {
size1.x += 10;
size2.y += 10;
}
}