xxxxxxxxxx
50
var a;
var b;
var c;
var d = 0;
function setup() {
createCanvas(400, 400);
frameRate(60);
}
function draw() {
background(0);
stroke(255);
line(200,200,mouseX,mouseY);
var x = ave(200,mouseX);
var y = ave(200,mouseY);
var x2 = ave(200,x);
var y2 = ave(200,y);
var x3 = ave(x,mouseX);
var y3 = ave(y,mouseY);
fill(a,b,c);
ellipse(x,y,d+30,d+30);
fill(b,a,c);
ellipse(x2,y2,d+30,d+30);
fill(c,b,a);
ellipse(x3,y3,d+30,d+30);
a = random(0,255);
b = random(0,255);
c = random(0,255);
if (keyIsDown(UP_ARROW)){
d = d + 5;
}
if (keyIsDown(DOWN_ARROW)){
d = d -5;
}
if (d < -30){
d = -30;
}
//challenge: use the ave function again to make
//a green dot half way between the center and the
//red dot
//var x2 = ??
//var y2 = ??
//fill(0,255,0);
//ellipse(x2,y2,30,30);
}
function ave(num1, num2){
return (num1 + num2) / 2; // replace with code to return average of the two arguments
}