Advertisement
xeromino

bez2

Sep 13th, 2015
594
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.33 KB | None | 0 0
  1. PVector a, b, c, d;
  2. float sz = 8, theta, theta2;
  3. int frames = 600, dir=1, pos=0, fc=1, fc2;
  4. PVector[] points = new PVector[frames];
  5. PVector[] v = new PVector[6];
  6. boolean save;
  7.  
  8. void setup() {
  9.   size(540, 540, P2D);
  10.   smooth(8);
  11.   a = new PVector(50, 500);
  12.   b = new PVector(100, 25);
  13.   c = new PVector(350, 50);
  14.   d = new PVector(500, 350);
  15.  
  16.   initStuff();
  17. }
  18.  
  19. void draw() {
  20.   background(20);
  21.   strokeWeight(3);
  22.   float l = map(sin(theta-PI/2), -1, 1, 0, 1);
  23.  
  24.   v[0] = PVector.lerp(a, b, l);
  25.   v[1] = PVector.lerp(b, c, l);
  26.   v[2] = PVector.lerp(c, d, l);
  27.   v[3] = PVector.lerp(v[0], v[1], l);
  28.   v[4] = PVector.lerp(v[1], v[2], l);
  29.   v[5] = PVector.lerp(v[3], v[4], l);
  30.  
  31.   stroke(#577287);
  32.   drawLine(a, b);
  33.   drawLine(b, c);
  34.   drawLine(c, d);
  35.   stroke(#00bd3a);
  36.   drawLine(v[0], v[1]);
  37.   drawLine(v[1], v[2]);
  38.   stroke(#ffaf18);
  39.   drawLine(v[3], v[4]);
  40.  
  41.   stroke(#577287);
  42.   fill(255);
  43.   drawEllipse(a);
  44.   drawEllipse(b);
  45.   drawEllipse(c);
  46.   drawEllipse(d);
  47.  
  48.   stroke(255);
  49.   fill(#577287);
  50.   for (int i=0; i<3; i++) drawEllipse(v[i]);
  51.  
  52.   fill(#00bd3a);
  53.   for (int i=3; i<5; i++) drawEllipse(v[i]);
  54.  
  55.   fill(#ffaf18);
  56.   drawEllipse(v[5]);
  57.  
  58.   points[pos]= v[5].get();
  59.   println(points.length);
  60.  
  61.   for (int i=0; i<=pos; i++) {
  62.     fill(#ff1935);
  63.     if (i==pos) {
  64.       stroke(255);
  65.     } else {
  66.       noStroke();
  67.     }
  68.     ellipse(points[i].x, points[i].y, sz, sz);
  69.   }
  70.  
  71.   if (dir>0) {
  72.     pos++;
  73.   } else {
  74.     pos--;
  75.   }
  76.  
  77.   if ((fc)%((frames/2))==0) {
  78.     dir *=-1;
  79.   }
  80.   theta += TWO_PI/frames;
  81.   theta2 += TWO_PI/(frames/2);
  82.   fc++;
  83.  
  84.   if (save) {
  85.     if (frameCount%5==0 && frameCount<=(fc2+frames)) saveFrame("image-###.gif");
  86.   }
  87.  
  88.   if (frameCount>(fc2+frames)) save=false;
  89. }
  90.  
  91. void drawLine(PVector p1, PVector p2) {
  92.   line(p1.x, p1.y, p2.x, p2.y);
  93. }
  94.  
  95. void drawEllipse(PVector p) {
  96.   ellipse(p.x, p.y, sz, sz);
  97. }
  98.  
  99. void initStuff() {
  100.   background(20);
  101.   theta = 0;
  102.   theta2 = 0;
  103.   pos = 0;
  104.   fc = 1;
  105.   dir = 1;
  106.   v = new PVector[6];
  107.   points = new PVector[frames];
  108.   a = new PVector(random(width), random(height));
  109.   b = new PVector(random(width), random(height));
  110.   c = new PVector(random(width), random(height));
  111.   d = new PVector(random(width), random(height));
  112. }
  113.  
  114. void mouseReleased() {
  115.   initStuff();
  116. }
  117.  
  118. void keyPressed() {
  119.   fc2 = frameCount;
  120.   save = true;
  121. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement