Skip to content

Instantly share code, notes, and snippets.

@sabotai
Created March 27, 2017 19:48
Show Gist options
  • Save sabotai/37173f838bd1dbb017adb3cda91a555d to your computer and use it in GitHub Desktop.
Save sabotai/37173f838bd1dbb017adb3cda91a555d to your computer and use it in GitHub Desktop.
//using variables to keep track of x and y positions of both ellipses
int eX, eY;
int eX2, eY2;
int dia;
void setup(){
size(1280, 720);
eX = width/4;
eY = height/2;
eX2 = int(width * 0.75);
eY2 = height/2;
dia = 200;
}
void draw(){
//we create the variable distance
//we then assign it to the distance between our mouse (mouseX, mouseY) and the first ellipse (eX, eY)
float distance = dist(mouseX, mouseY, eX, eY);
println(distance);
//*important* we set the fill color to be the same as the distance BEFORE we draw the ellipse
fill(distance);
//draw the ellipse using the fill we set above
ellipse(eX, eY, dia, dia);
//now we will use our same variable "distance" to store the other distance
distance = dist(mouseX, mouseY, eX2, eY2);
println(distance);
//now we use the new distance to set the new fill before we draw our second ellipse
fill(distance);
//only after setting the distance and fill do we draw the second ellipse
ellipse(eX2, eY2, dia, dia);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment