xxxxxxxxxx
26
function setup() {
createCanvas(400, 400);
}
function draw() {
background(0);
stroke(255);
line(200,200,mouseX,mouseY);
var x = ave(200,mouseX);
var y = ave(200,mouseY);
fill(255,0,0);
ellipse(x,y,30,30);
// challenge: use the ave function again to make
// a green dot half way between the center and the
// red dot
var x2 = ave(200,x)
var y2 = ave(200,y)
fill(0,255,0);
ellipse(x2,y2,30,30);
}
function ave(x, y){
return (x+y)/2; // replace with code to return average of the two arguments
}