Facebook
From Harmless Hedgehog, 3 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 44
  1. int circleX, circleY;
  2. int r = 100;  
  3. boolean circleOver = false;
  4. void setup() {
  5. size(800, 800);
  6. strokeWeight(3);
  7. background(255, 255, 255);
  8. }
  9.  
  10. boolean overCircle(int x, int y){
  11.   float disX = x - mouseX;
  12.   float disY = y - mouseY;
  13.   if(sqrt(sq(disX) + sq(disY)) < r ) {
  14.     return true;
  15.   } else {
  16.     return false;
  17.   }
  18. }
  19.  
  20. void update(int x, int y) {
  21.   if( overCircle(circleX, circleY) ) {
  22.     circleOver = true;
  23.   }else{
  24.     circleOver = false;
  25.   }
  26. }
  27.  
  28. void draw() {
  29.   update(mouseX, mouseY);
  30.   if (circleOver){
  31.     circleX = int (random(100,700));
  32.     circleY = int (random(100,700));
  33.   }else{
  34.     clear();
  35.     background(255, 255, 255);
  36.   }
  37.   circle(circleX, circleY, r);
  38. }