Advertisement
xeromino

puls

Jan 3rd, 2014
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.36 KB | None | 0 0
  1. int amount = 40;
  2. color s = #202020;
  3. color f = #ffffff;
  4. Thing[] things = new Thing[amount];
  5.  
  6. void setup() {
  7.   size(500, 500);
  8.   background(255);
  9.   stroke(0);
  10.   //f = s;
  11.   float theta=0;
  12.   for (int i=0; i<amount; i++) {
  13.     float x = sin(theta);
  14.     float y = cos(theta);
  15.     PVector vOrg = new PVector(x, y);
  16.     vOrg.normalize();
  17.     int cat = amount%2;
  18.     println(cat);
  19.     things[i]= new Thing(vOrg, theta, cat);
  20.     theta += TAU/amount;
  21.   }
  22. }
  23.  
  24.  
  25. void draw() {
  26.   background(255);
  27.   for (int i=0; i<things.length; i++) {
  28.     things[i].run(200);
  29.   }
  30.   fill(255);
  31.   noStroke();
  32.   ellipse(width/2, height/2, 20, 20);
  33.  
  34.   if (frameCount % 2 == 0 && frameCount < 241) saveFrame("image-####.gif");
  35. }
  36.  
  37. class Thing {
  38.   PVector vOrg, vDepl;
  39.   int cat;
  40.   float sz, x, y, theta, mg, mag;
  41.  
  42.   Thing(PVector _vOrg, float _theta, int _cat) {
  43.     vOrg = _vOrg;
  44.     vDepl = vOrg.get();
  45.     cat = _cat;
  46.     theta = _theta;
  47.   }
  48.  
  49.   void run(int _mag) {
  50.     mag = _mag;
  51.     move();
  52.     display(mag);
  53.   }
  54.  
  55.   void move() {
  56.     mg = map(sin(theta*5), -1, 1, mag-80, mag);
  57.     sz = map(sin(theta*5), -1, 1, 10, 20);
  58.     vOrg.setMag(mg);
  59.     x = width/2 + vOrg.x;
  60.     y = height/2 + vOrg.y;
  61.     theta += 0.0523/2;
  62.   }
  63.  
  64.  
  65.   void display(float mag) {
  66.  
  67.     stroke(s);
  68.     line(width/2, height/2, x, y);
  69.     fill(f);
  70.     ellipse(x, y, sz, sz);
  71.   }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement