Advertisement
xeromino

box

Jul 6th, 2015
359
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.20 KB | None | 0 0
  1. int d=180, num=250, l=100, v=3;
  2. PVector[] location = new PVector[num];
  3. PVector[] velocity = new PVector[num];
  4. float r=-.25, sz=15;
  5.  
  6. void setup() {
  7.   size(500, 500, P3D);
  8.   colorMode(HSB, 360, 100, 100);
  9.   smooth(8);
  10.   sphereDetail(30);
  11.   for (int i=0; i<num; i++) {
  12.     location[i] = new PVector(random(-l, l), random(-l, l), random(-l, l));
  13.     velocity[i] = new PVector(random(-v, v), random(-v, v), random(-v, v));
  14.   }
  15. }
  16.  
  17. void draw() {
  18.   randomSeed(1234);
  19.   background(#000000);
  20.   for (int i=0; i<num; i++) {
  21.     location[i].add(velocity[i]);
  22.   }
  23.   translate(width/2, height/2, -170);
  24.   rotateY(r);
  25.   noFill();
  26.   stroke(#ffffff, 150);
  27.   box(2*d, 2*d, 2*d);
  28.   for (int i=0; i<num; i++) {
  29.     pushMatrix();
  30.     translate(location[i].x, location[i].y, location[i].z);
  31.     if (location[i].x<-d+sz || location[i].x>d-sz) velocity[i].x *= -1;
  32.     if (location[i].y<-d+sz || location[i].y>d-sz) velocity[i].y *= -1;
  33.     if (location[i].z<-d+sz || location[i].z>d-sz) velocity[i].z *= -1;
  34.     noStroke();
  35.     fill(random(180,360), 90, 90);
  36.     //fill(255);
  37.     lights();
  38.     sphere(sz);
  39.     popMatrix();
  40.   }
  41.  
  42.   r += 0.005;
  43.   //saveFrame("image-###.tif");
  44.   //if (frameCount>130) noLoop();
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement