Advertisement
xeromino

bubbles

Jun 1st, 2015
570
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.09 KB | None | 0 0
  1. float x, y, scale, rotation, sz, time, theta;
  2. int frames = 120, num = 100, fc;
  3. long rs;
  4. boolean save = false;
  5.  
  6. void setup() {
  7.   size(540, 540);
  8.   smooth(8);
  9.   noStroke();
  10.   rs = (long) random(10000);
  11. }
  12.  
  13. void draw() {
  14.   randomSeed(rs);
  15.   background(#490A3D);
  16.   time = (frameCount % frames)/float(frames);
  17.   for (int i=0; i<num; i++) {
  18.     drawBubble(i);
  19.   }
  20.   if (save) {
  21.     saveFrame("image-###.gif");
  22.     if (frameCount==fc+frames) noLoop();
  23.   }
  24.   theta += TWO_PI/frames;
  25. }
  26.  
  27. void drawBubble(int i) {
  28.   x = random(width);
  29.   y = random(height);
  30.   scale = random(1, 3);
  31.   rotation = random(-.01, 0.1);
  32.   float m = map(sin(theta+TWO_PI/num*i), -1, 1, .5, 2);
  33.   sz = random(20, 50)*m;
  34.   resetMatrix();
  35.   scale(scale);
  36.   translate(x, y);
  37.   rotate(rotation);
  38.   fill(#F8CA00, 200);
  39.   if (random(1)>.9)   fill(#BD1550, 200);
  40.   if (random(1)>.9)   fill(#8A9B0F, 200);
  41.   ellipse(0, -time*height+height, sz, sz);
  42.   ellipse(0, -time*height, sz, sz);
  43. }
  44.  
  45. void mouseReleased() {
  46.   rs = (long) random(10000);
  47. }
  48.  
  49. void keyPressed() {
  50.   save = true;
  51.   fc = frameCount;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement