xxxxxxxxxx
49
//objects
var circle1 = {
x : 0,
y : 50,
diam : 50
};
var circle2 = {
x : 400,
y : 0,
diam : 70
};
var color1 = {
r : 100,
g : 50,
b : 255,
};
function setup() {
createCanvas(400, 400);
}
function draw() {
background(220);
//circle 1 move from left to right infinitly
fill(255,0,0);
noStroke();
ellipse (circle1.x, circle1.y, circle1.diam, circle1.diam);
circle1.x+=2;
if (circle1.x >width) {
circle1.x =0; }
//circle 2 move from top right to bottom left and change colors
fill(color1.r,color1.g,color1.b);
ellipse (circle2.x, circle2.y, circle2.diam, circle2.diam-10);
circle2.x-=2;
circle2.y+=3;
if (circle2.x <0) {
circle2.x =400; }
else if (circle2.y >400) {
circle2.y=0;
}
color1.r++; color1.g+=2; color1.b++;
if (color1.r>255) {color1.r=0;} else if (color1.g>255) {color1.g=0;}
else if (color1.b>255) {color1.b=0;}
}