Advertisement
xeromino

sphere

Jul 7th, 2015
512
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.37 KB | None | 0 0
  1. int d=250, num=200, l=100, v=3;
  2. PVector[] location = new PVector[num];
  3. PVector[] velocity = new PVector[num];
  4. float r=-.25, sz=10;
  5.  
  6. void setup() {
  7.   size(500, 500, P3D);
  8.   colorMode(HSB, 360, 100, 100);
  9.   smooth(8);
  10.  
  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.   rotateX(0.5);
  26.   noFill();
  27.   stroke(#ffffff, 100);
  28.   sphereDetail(20);
  29.   sphere(d);
  30.   for (int i=0; i<num; i++) {
  31.     float distance = dist(0, 0, 0, location[i].x, location[i].y, location[i].z);
  32.     pushMatrix();
  33.     translate(location[i].x, location[i].y, location[i].z);
  34.     /*if (location[i].x<-d+sz || location[i].x>d-sz) velocity[i].x *= -1;
  35.      if (location[i].y<-d+sz || location[i].y>d-sz) velocity[i].y *= -1;
  36.      if (location[i].z<-d+sz || location[i].z>d-sz) velocity[i].z *= -1;
  37.      */
  38.     if (distance>d-sz) velocity[i].mult(-1);
  39.     noStroke();
  40.     fill(random(0, 360), 90, 90);
  41.     //fill(255);
  42.     lights();
  43.     sphereDetail(30);
  44.     sphere(sz);
  45.     popMatrix();
  46.   }
  47.  
  48.   r += 0.005;
  49.   if (frameCount%3==0 && frameCount<180) saveFrame("image-###.tif");
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement