Advertisement
xeromino

Bending

Oct 15th, 2013
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.24 KB | None | 0 0
  1. int num = 3;
  2. Thingie[] myThing = new Thingie[num];
  3. int vLines = 10;
  4. float space;
  5. float oy;
  6. float segment, margin;
  7.  
  8. void setup() {
  9.   size(500, 450);
  10.   background(0);
  11.   stroke(255);
  12.   oy = height/2;
  13.   segment = width/num;
  14.   margin = segment/3;
  15.   space = (segment-2*margin)/vLines;
  16.  
  17.   for (int i=0; i < num; i++) {
  18.     myThing[i] = new Thingie(i*segment, 75);
  19.   }
  20. }
  21.  
  22. void draw() {
  23.   background(0);
  24.   for (int i=0; i < num; i++) {
  25.     myThing[i].run();
  26.   }
  27.  
  28. }
  29. class Thingie {
  30.  
  31.   float y_up, y_down, x;
  32.   float incr, theta;
  33.   float maxSize, sw, a, a2;
  34.  
  35.   Thingie(float _x, float _maxSize) {
  36.     x = _x+margin;
  37.     maxSize = 50+ _maxSize;
  38.   }
  39.  
  40.   void run() {
  41.     move();
  42.     display();
  43.   }
  44.  
  45.   void move() {
  46.     incr = map(sin(theta), -1, 1, 10, maxSize);
  47.     sw=2;
  48.     a = map(sin(theta), -1, 1, PI, PI*1.5);
  49.     a2 = map(sin(theta), -1, 1, 0, PI*.5);
  50.     y_up = oy - incr;
  51.     y_down = oy + incr;
  52.     theta +=0.052358;
  53.   }
  54.  
  55.   void display() {
  56.     strokeWeight(sw);
  57.     for (int i=0; i<= vLines; i++) {
  58.       line(x+space*i, oy-incr, x+space*i, oy+incr); //vLine going up
  59.       noFill();
  60.       arc((x+space*i)+50, oy-incr-1, 100, 100, PI, a);
  61.       arc((x+space*i)-50, oy+incr+1, 100, 100, 0, a2);
  62.     }
  63.   }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement