Advertisement
xeromino

eldorado

Jun 17th, 2015
372
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.51 KB | None | 0 0
  1. int spaceBetween = 20;
  2. int numX, numY, counter;
  3. float theta=0, maxDist=40;
  4. int frames = 240, num=20;
  5. ArrayList<Node> nodes = new ArrayList<Node>();
  6. ArrayList<Orb> orbs = new ArrayList<Orb>();
  7.  
  8. void setup() {
  9.   size(1080, 720, P2D);
  10.   blendMode(ADD);
  11.   background(0);
  12.   stroke(8, 4, 2);
  13.   numX = width/spaceBetween;
  14.   numY = height/spaceBetween;
  15.   initObjects();
  16. }
  17.  
  18. void draw() {
  19.   for (Orb o : orbs) {
  20.     o.display();
  21.   }
  22.   theta += TWO_PI/frames;
  23. }
  24.  
  25. void keyPressed() {
  26.   save(random(1212)+".jpg");
  27. }
  28.  
  29. void initObjects() {
  30.   nodes.clear();
  31.   for (int x=0; x<numX; x++) {
  32.     for (int y=0; y<numY; y++) {
  33.       Node n = new Node((x+.5)*spaceBetween, (y+.5)*spaceBetween);
  34.       nodes.add(n);
  35.     }
  36.   }
  37.   for (int i=0; i<num; i++) {
  38.     float radius = map(i, 0, num-1, height*.1, height*.4);
  39.     int dir = i%2==0 ? 1: -1;
  40.     Orb o = new Orb(radius, dir);
  41.     orbs.add(o);
  42.   }
  43. }
  44.  
  45. class Node {
  46.  
  47.   PVector loc;
  48.  
  49.   Node(float x, float y) {
  50.     loc = new PVector(x, y);
  51.   }
  52. }
  53.  
  54. class Orb {
  55.  
  56.   float radius, r, sz = 40;
  57.   int dir;
  58.  
  59.   Orb(float _radius, int _dir) {
  60.     radius = _radius;
  61.     r = random(TWO_PI);
  62.     dir = _dir;
  63.     counter++;
  64.   }
  65.  
  66.   void display() {
  67.     float x = width/2 + sin(theta*dir+r)*radius;
  68.     float y = height/2 + cos(theta*dir+r)*radius;
  69.     noFill();
  70.     stroke(8, 4, 2);
  71.     for (Node n : nodes) {
  72.       float d = dist(x, y, n.loc.x, n.loc.y);
  73.       if (d<maxDist) {
  74.         stroke(8, 4, 2);
  75.         line(x, y, n.loc.x, n.loc.y);
  76.       }
  77.     }
  78.   }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement