xeromino

thingie

May 8th, 2014
488
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.09 KB | None | 0 0
  1. int fc, num = 80, edge = 200;
  2. ArrayList ballCollection;
  3. boolean save = false;
  4.  
  5. void setup() {
  6.   size(500, 500);
  7.   background(0);
  8.   ballCollection = new ArrayList();
  9.   createStuff();
  10. }
  11.  
  12. void draw() {
  13.   background(0);
  14.  
  15.   for (int i=0; i<ballCollection.size(); i++) {
  16.     Ball mb = (Ball) ballCollection.get(i);
  17.     mb.run();
  18.   }
  19.  
  20.   if (save) {
  21.     if (frameCount%2==0 && frameCount < fc + (121)) saveFrame("image-####.tif");
  22.   }
  23. }
  24.  
  25. void keyPressed() {
  26.   fc = frameCount;
  27.   save = true;
  28. }
  29.  
  30. void mouseReleased() {
  31.   background(0);
  32.   createStuff();
  33. }
  34.  
  35. void createStuff() {
  36.   ballCollection.clear();
  37.   for (int i=0; i<num; i++) {
  38.     float radius = random(50, 100);
  39.     float angle = TWO_PI/num*i;
  40.     println(angle);
  41.  
  42.     float offSet = random(TWO_PI);
  43.  
  44.     Ball myBall = new Ball(radius, angle, offSet);
  45.     ballCollection.add(myBall);
  46.   }
  47. }
  48.  
  49. class Ball {
  50.  
  51.   PVector loc = new PVector(0, 0);
  52.   float sz = 5;
  53.   float theta, angle, radius, offSet, scal, x2, y2;
  54.   int s, c, dir, d = 40;
  55.  
  56.   Ball(float _radius, float _angle, float _offSet) {
  57.     angle = _angle;
  58.     radius = _radius;
  59.     offSet = _offSet;
  60.   }
  61.  
  62.   void run() {
  63.     move();
  64.     display();
  65.     lineBetween();
  66.   }
  67.  
  68.   void move() {
  69.     scal = map(sin(theta+offSet), -1, 1, .50, 2.1);
  70.     loc.x = width/2 + sin(angle)*radius*scal;
  71.     loc.y = height/2 + cos(angle)*radius*scal;
  72.     theta += 0.0523;
  73.   }
  74.  
  75.   void lineBetween() {
  76.     for (int i=0; i<ballCollection.size(); i++) {
  77.       Ball other = (Ball) ballCollection.get(i);
  78.       float distance = loc.dist(other.loc);
  79.       if (distance >0 && distance < d) {
  80.         c = (int) map(loc.x, 100, width-100, 0, 360);
  81.         colorMode(HSB, 360, 100, 100);
  82.         //stroke(#ffffff,150);
  83.         stroke(c, 90, 90, 200);
  84.         line(loc.x, loc.y, other.loc.x, other.loc.y);        
  85.         colorMode(RGB);
  86.       }
  87.     }
  88.   }
  89.  
  90.   void display() {
  91.     noStroke();
  92.     fill(255);
  93.     ellipse(loc.x, loc.y, sz, sz);
  94.     stroke(255);  
  95.     x2 = width/2 + sin(angle)*220;
  96.     y2 = height/2 + cos(angle)*220;
  97.     line(loc.x, loc.y, x2, y2);
  98.   }
  99. }
Advertisement
Add Comment
Please, Sign In to add comment