Advertisement
xeromino

ellipsoRect

Jun 4th, 2015
503
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.41 KB | None | 0 0
  1. int num = 240, dotsSide = num/4, spaceBetween = 5, counter, frames = 180;
  2. float x, y, radius, theta, sz = 2;
  3. PVector[] dotsRect = new PVector[num];
  4. PVector[] dotsCircle = new PVector[num];
  5.  
  6. void setup() {
  7.   size(540, 540);
  8.   background(0);
  9.   noStroke();
  10.   for (int j=1; j<=4; j++) {
  11.     for (int i=0; i<dotsSide; i++) {
  12.       switch (j) {
  13.       case 1:
  14.         x = i*spaceBetween;
  15.         y = 0;
  16.         break;
  17.       case 2:
  18.         x = dotsSide*spaceBetween;
  19.         y = i*spaceBetween;
  20.         break;
  21.       case 3:        
  22.         x = dotsSide*spaceBetween - i*spaceBetween;
  23.         y = dotsSide*spaceBetween;
  24.         break;
  25.       case 4:
  26.         x = 0;
  27.         y = dotsSide*spaceBetween - i*spaceBetween;
  28.         break;
  29.       }
  30.       dotsRect[counter] = new PVector(x, y);
  31.       counter++;
  32.     }
  33.   }
  34.   radius = (dotsSide*spaceBetween)/2;
  35.   for (int i=0; i<num; i++) {
  36.     x = radius + cos(PI+PI/4+TWO_PI/num*i)*radius*.8;
  37.     y = radius + sin(PI+PI/4+TWO_PI/num*i)*radius*.8;
  38.     dotsCircle[i] = new PVector(x, y);
  39.   }
  40. }
  41.  
  42. void draw() {
  43.   background(0);
  44.   translate((width-2*radius)/2, (width-2*radius)/2);
  45.   fill(255);
  46.   for (int i=0; i<num; i++) {
  47.     float offSet = map(i, 0, num-1, 0, TWO_PI);
  48.     float lerpValue = map(sin(theta), -1, 1, 0, 1);
  49.     PVector newV = PVector.lerp(dotsRect[i], dotsCircle[i], lerpValue);
  50.     ellipse(newV.x, newV.y, sz, sz);
  51.   }
  52.   theta += TWO_PI/frames;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement