Advertisement
xeromino

sun

Jun 26th, 2015
344
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 = 15, min=150, max=300, fc = 100;
  2. PVector[] loc = new PVector[num];
  3. PVector[] vel = new PVector[num];
  4. float[] sz = new float[num];
  5.  
  6. void setup() {
  7.   size(1080, 720, P2D);
  8.   blendMode(ADD);
  9.   background(0);
  10.   noFill();
  11.   stroke(8, 4, 2);
  12.   initStuff();
  13. }
  14.  
  15. void draw() {
  16.   drawElement();
  17.   if (frameCount%fc==0) {
  18.     save(fc+".jpg");
  19.     fc += 100;
  20.   }
  21. }
  22.  
  23. void drawElement() {
  24.   float outside = min;
  25.   for (int i=0; i<loc.length; i++) {
  26.     loc[i].add(vel[i]);
  27.     if (loc[i].x > width+outside || loc[i].x<-outside) {
  28.       vel[i].x *= -1;
  29.     }
  30.     if (loc[i].y > height+outside || loc[i].y<-outside) {
  31.       vel[i].y *= -1;
  32.     }
  33.   }
  34.  
  35.   for (int i=0; i<loc.length; i++) {
  36.     for (int j=0; j<loc.length; j++) {
  37.       float distance=dist(loc[i].x, loc[i].y, loc[j].x, loc[j].y);
  38.       if (distance>min && distance<max) {
  39.         //stroke(8, 4, 2);
  40.         if (i != j) line(loc[i].x, loc[i].y, loc[j].x, loc[j].y);
  41.       }
  42.     }
  43.   }
  44. }
  45.  
  46. void keyPressed() {
  47.   if (key=='s') save(random(23232)+".jpg");
  48.   if (key=='1') stroke(8, 4, 2);
  49.   if (key=='2') stroke(1, 3, 2);
  50.   if (key=='3') stroke(3, 1, 1);
  51. }
  52.  
  53. void mouseReleased() {
  54.   initStuff();
  55. }
  56.  
  57. void initStuff() {
  58.   background(0);
  59.   float r = 4;
  60.   for (int i=0; i<num; i++) {
  61.     float x = random(width);
  62.     float y = random(height);
  63.     loc[i] = new PVector(x, y);
  64.     vel[i] = new PVector(random(-r, r), random(-r, r));
  65.   }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement