SHARE
TWEET

Untitled

a guest Apr 25th, 2016 145 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. void setup() {
  2.   size (800, 600);
  3.   background = loadImage("Background.jpg");
  4.   Ballimage=loadImage("ball.png");
  5. }
  6. PImage background;
  7. PImage Ballimage;
  8. float time;
  9. float interval;
  10. int last=0;
  11.  
  12.  
  13.  
  14. class Bubble {
  15.   float ballsize;
  16.   PImage Ballimage;
  17.   float randomx =random(width);
  18.   float randomy=random(height);        
  19.   float timestart;
  20. }
  21.  
  22. ArrayList<Bubble>bubbles= new ArrayList(10);
  23.  
  24.  
  25. ArrayList<Bubble>toRemove=new ArrayList();
  26.  
  27. void draw() {
  28.   background(0);
  29.   image (background, 0, 0, width, height);
  30.   time=time+1;
  31.   for (Bubble bub : bubbles) {
  32.     bub.ballsize=50-(50*sin(((0.5)*(bub.timestart-time))/7)+50);
  33.     //above is just a function that controlss the size of the bubbles appearing on screen
  34.     image(Ballimage, bub.randomx-bub.ballsize/2, bub.randomy-bub.ballsize/2, bub.ballsize, bub.ballsize);
  35.     if (bub.ballsize<1) {
  36.       toRemove.add (bub);
  37.     }
  38.   }
  39.   bubbles.removeAll(toRemove);
  40.   toRemove.clear();
  41.  
  42.  
  43.   if (millis() - last > 1000) {
  44.     last=millis();
  45.     while (true) {
  46.       Bubble bub = new Bubble();
  47.       bub.timestart=time;
  48.       boolean clash = false;
  49.       if (bub.randomx<50 || bub.randomx>width-50||bub.randomy<50||bub.randomy>height-50) {
  50.         clash=true;
  51.       }
  52.       for (Bubble b : bubbles) {
  53.         if (100>dist(b.randomx, b.randomy, bub.randomx, bub.randomy)) {
  54.           clash = true;
  55.         }
  56.       }
  57.       if (!clash) {
  58.         if (bubbles.size()<10) {
  59.           bubbles.add(bub);
  60.           return;
  61.         }
  62.       }
  63.     }
  64.   }
  65. }
  66. void mouseClicked() {
  67.   Bubble b = null;
  68.   float minDist = Float.MAX_VALUE;
  69.   for (Bubble b2 : bubbles) {
  70.     float d = dist(b2.randomx, b2.randomy, mouseX, mouseY);
  71.     if (d < minDist) {
  72.       minDist = d;
  73.       b = b2;
  74.     }
  75.   }
  76.   if (b == null) {
  77.     return;
  78.   }
  79.   if (minDist<b.ballsize/2) {
  80.     toRemove.add (b);
  81.   } else {
  82.     println(b.ballsize, mouseX, mouseY);
  83.   }
  84.  
  85.   bubbles.removeAll(toRemove);
  86.   toRemove.clear();
  87. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top