1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import processing.opengl.*;
import javax.media.opengl.*;

PGraphicsOpenGL pgl;
GL gl;

ArrayList boxes;

void setup() {
  background(0);
  size(500,500,OPENGL);
  boxes = new ArrayList();
  colorMode(HSB);
  
  frameRate(10);

  boxes.add(new MyBox(0, 0, 0, color(244), 10, 10, 10));
  //noLoop();
  //noStroke();
  smooth();
  lights();
}

void draw() {
  background(0);
  
  pgl = (PGraphicsOpenGL) g;
  gl = pgl.gl;
  
  pgl.beginGL();
  gl.glEnable(GL.GL_DEPTH_TEST);
  gl.glEnable(GL.GL_BLEND);
  gl.glBlendFunc(GL.GL_SRC_ALPHA,GL.GL_ONE);
  //gl.glShadeModel(GL.GL_SMOOTH);
  pgl.endGL();

  MyBox box = (MyBox)boxes.get(boxes.size()-1);
  
  camera(box.x+110, noise(frameCount * 0.005)*100-50, noise(frameCount * 0.001)*100-50, box.x, 0, 0, 1, 0, 0);
  
  float y = noise(frameCount * 0.02) * 100 - 50;
  float z = noise(frameCount * 0.06) * 100 - 50;
  boxes.add(box.addX(random(10,50), random(20,40), random(20,40), color(frameCount%255, 255, 24), y, z));

  for (int i=1; i<boxes.size(); i++) {
    MyBox theBox = (MyBox)boxes.get(i);
    theBox.display();
  }
  //saveFrame("save/frame-####.png");
}

class MyBox {
  float x;
  float y;
  float z;
  color c;
  float w;
  float h;
  float d;
  
  MyBox(float _x, float _y, float _z, color _c, float _w, float _h, float _d) {
    x = _x; y = _y; z = _z; c = _c; h = _h; w = _w; d = _d;
  }
  
  void display() {
    pushMatrix();
    translate(x,y,z);
    fill(c);
    box(w,h,d);
    popMatrix();
  }
  
  MyBox addX(float _w, float _h, float depth, color _c, float _y, float _z) {
    return new MyBox(x+w, _y, _z, _c, _w, _h, depth);
  }
}