import toxi.geom.*; import processing.opengl.*; import damkjer.ocd.*; Particle [] ps; Camera cam; Vec3D camVelocity; void setup() { size(720, 576, OPENGL); ps = new Particle[20]; for(int i = 0; i < ps.length; i++) { ps[i] = new Particle(); } fill(255); cam = new Camera(this, 100, -width/4, -300,0,0,0); camVelocity = new Vec3D(0,0,0); cam.zoom(-0.2); } void axes() { fill(255,0,0); pushMatrix(); translate(50,0,0); box(100,2,2); popMatrix(); pushMatrix(); translate(width/2,width/2,0); box(20); popMatrix(); fill(0,255,0); pushMatrix(); translate(0,50,0); box(2,100,2); popMatrix(); fill(0,0,255); pushMatrix(); translate(0,0,50); box(2,2,100); popMatrix(); } void ground() { fill(0,100,0); pushMatrix(); translate(0,10,0); box(10000,10,10000); popMatrix(); } void draw() { background(255); sphereDetail(3); //axes(); //ground(); fill(255); for(int i = 0; i < ps.length; i++) { pushMatrix(); //translate(width/2, height/2); ps[i].draw(); popMatrix(); } cam.feed(); if(keyPressed) { switch(keyCode) { case UP: camVelocity.z -= 0.1; break; case DOWN: camVelocity.z += 0.1; break; case LEFT: camVelocity.x -= 0.1; break; case RIGHT: camVelocity.x += 0.1; break; } } else { camVelocity.scaleSelf(0.95); } // limit z if(cam.position()[1]>0) { camVelocity.z = -0.01; } cam.arc(camVelocity.z/100); cam.circle(camVelocity.x/10); } void mouseMoved() { // cam.circle(radians(mouseX - pmouseX)); //cam.arc(radians(mouseY - pmouseY)); } void mouseClicked() { for(int i = 0; i < ps.length; i++) { ps[i].init(); } } class Particle { int size; Vec3D s; Vec3D u; Vec3D offset; int bounce; float t; float a; int superT; Particle() { a = 0.1; init(); } void init() { s = new Vec3D(0, 0, 0); offset = new Vec3D(0,0,0); u = new Vec3D(random(-1,1),random(-8,-3),random(-1,1)); t = 0; superT = 0; bounce = 0; size = (int)random(5, 40); } void draw() { superT++; s = u.scale(t); s.y += 0.5 * a * pow(t,2); fill(255,100,100, 255-(superT)*2/3); stroke(0, 255-(superT)*3/4); if(s.y>0) { bounce++; if(bounce>12) { init(); println("spawn"+new java.util.Date().getTime()); return; } offset = new Vec3D(s).add(offset); u.scaleSelf(0.7); t = 0; s = u.scale(t); s.y += 0.5 * a * pow(t,2); } //s = ut + 1/2at^2 s.addSelf(offset); translate(s.x, s.y, s.z); rotateX(s.x/10.f); rotateZ(s.z/10.f); box(size); t++; } }