Advertisement
xeromino

mccc1115

Nov 4th, 2015
319
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.64 KB | None | 0 0
  1. color[] col = {#2537b5, #ff3804}; // the theme colors
  2.  
  3. int num = 11; //number of circles
  4. int frms = 200; // number of frames for animation
  5. float angle, destx, desty, dif;
  6. float[] px = new float[num];
  7. float[] py = new float[num];
  8. float[] psz = new float[num];
  9. float scal = 1.2;
  10.  
  11. void setup() {
  12.   size(350, 350, P2D);
  13.   background(255);
  14.  
  15.   destx = width/2; // horizontal center of the image
  16.   desty = height/2; // vertical center of the image
  17.  
  18.   initCircles();
  19. }
  20. void draw() {
  21.   background(255);
  22.   drawCircles();
  23.   //if (frameCount%frms==0) initCircles();
  24.   if (frameCount<=frms) saveFrame("image-###.gif");
  25. }
  26.  
  27. void initCircles() {
  28.  
  29.   float sz = width*.75; //start size for the left series of circles
  30.   float incr = sz/num*1.7; // value the circles decrease each step
  31.   float sz2 = sz-incr/2; //start size for the right series of circles
  32.   dif = incr/4; //value added to x to get the center for the right series of circles
  33.   float sw = dif*.45; //strokeWeight
  34.  
  35.   for (int i=0; i<num; i++) {
  36.     float x = destx + sin(angle)*width*scal;
  37.     float y = desty + cos(angle)*height*scal;
  38.     px[i] = x;
  39.     py[i] = y;
  40.     angle -= TWO_PI/num;
  41.     if (i%2==0) {
  42.       sz -= incr;
  43.       psz[i] = sz;
  44.     } else {
  45.       sz2 -= incr;
  46.       psz[i] = sz2;
  47.     }
  48.   }
  49.   strokeWeight(sw);
  50. }
  51.  
  52. void drawCircles() {
  53.   for (int i=0; i<num; i++) {
  54.     py[i] = lerp(py[i], desty, 0.05);
  55.     if (i%2==0) {
  56.       fill(col[0]);
  57.       px[i] = lerp(px[i], destx, 0.05);
  58.       ellipse(px[i], py[i], psz[i], psz[i]);
  59.     } else {
  60.       fill(col[1]);
  61.       px[i] = lerp(px[i], destx+dif, 0.1);
  62.       ellipse(px[i], py[i], psz[i], psz[i]);
  63.     }
  64.   }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement