xxxxxxxxxx
28
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);
var x2 = ave(x,200) ;
var y2 = ave(y, 200);
fill(0,255,0);
ellipse(x2,y2,30,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
}