つよくなりたいなあ

地に足をつけず世界を生きぬくブログです

3D空間を飛び回る球体

f:id:heyassy:20181118211724p:plain

/*
 * 2018/11/18
 */


float x = random(500);
float y = random(500);
float z = random(500);

void setup() {
  size(720, 720, P3D);
}

void draw() {
  //background(0);
  directionalLight(125, 50, 255, 0, -1, 1); //blue bottom to top
  directionalLight(70, 200, 175, 1, 1, 0); //green right bottom to left up
  directionalLight(150, 125, 152, -1, 0, -1); //red right bottom to left up

  if (frameCount%100 == 0) {
    x = random(500);
  }
  if (frameCount%100 == 0) {
    y = random(500);
  }
  if (frameCount%100 == 0) {
    z = random(500);
  }
  camera(x * sin(frameCount * 0.03), y, z * cos(frameCount*0.02), 
    0, 0, 0, //center of camera
    0, 1, 0); 

  noStroke();
  fill(255);
  //box(1000);

  for (int i = 1; i <= 100; i++) {
    pushMatrix();
    translate(i * 50 * sin(frameCount*0.01 * i), 
      i * 50 * cos(frameCount * 0.01 * i), 
      i * 50 * sin(frameCount * 0.02*i));

    sphere(50);
    popMatrix();
  }
  //saveFrame("frames/###.tif");
}