Advertisement
xeromino

spheresSpace

May 22nd, 2017
292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.71 KB | None | 0 0
  1. import com.hamoid.*;
  2.  
  3. import peasy.*;
  4. import peasy.org.apache.commons.math.*;
  5. import peasy.org.apache.commons.math.geometry.*;
  6.  
  7. PeasyCam cam;
  8. VideoExport videoExport;
  9. ArrayList <Globe> globes = new ArrayList<Globe>();
  10. float theta;
  11. int num = 200;
  12.  
  13. void setup() {
  14.   size(1920, 1080, P3D);
  15.   background(0);
  16.  
  17.   for (int i=0; i<num; i++) {
  18.     globes.add(new Globe(PI/num*i));
  19.   }
  20.  
  21.   cam = new PeasyCam(this, width/2, height/2, 0, 800);
  22.   cam.setMinimumDistance(50);
  23.   cam.setMaximumDistance(1000);
  24.  
  25.   videoExport = new VideoExport(this, "internetVideo.mp4");
  26.   videoExport.setFrameRate(30);
  27.   videoExport.setQuality(85, 128);
  28.   //videoExport.startMovie();
  29.  
  30.   frameRate(30);
  31. }
  32.  
  33. void draw() {
  34.   strokeWeight(.9);
  35.   stroke(255, 15);
  36.   lights();
  37.   translate(width/2, height/2, 200);
  38.   rotateY(frameCount/50.0);
  39.    rotateX(frameCount/75.0);
  40.    rotateZ(frameCount/200.0);
  41.   for (Globe gl : globes) {
  42.     gl.update();
  43.     gl.drawSpheres();
  44.   }
  45.  
  46.   //videoExport.saveFrame();
  47.  
  48.   //if (frameCount%35==0) saveFrame("image-####.png");
  49.  
  50.   theta += 0.01;
  51. }
  52.  
  53. void keyPressed() {
  54.   if (key == 'q') {
  55.     videoExport.endMovie();
  56.     exit();
  57.   }
  58. }
  59.  
  60. class Globe {
  61.  
  62.   float offSet, r, p, t, x, y, z;
  63.  
  64.   Globe(float _offSet) {
  65.     offSet = _offSet; //
  66.     //offSet = random(TWO_PI);
  67.   }
  68.  
  69.   void update() {
  70.  
  71.     r = map(sin(theta+offSet), -1, 1, 100, 300);
  72.     //r = 250;
  73.     p = map(sin(theta+offSet), -1, 1, -PI/2, PI/2);
  74.     t = map(sin(theta+offSet), -1, 1, 0, TWO_PI);
  75.  
  76.     x = r * sin(p)*cos(t);
  77.     y = r * sin(p)*sin(t);
  78.     z = r * cos(p);
  79.   }
  80.  
  81.   void drawSpheres() {
  82.     pushMatrix();
  83.     translate(x, y, z);
  84.     noStroke();
  85.     fill(255, 200);
  86.     sphere(10);
  87.     popMatrix();
  88.   }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement