import processing.opengl.*; PImage[] images; float[] xpos; float[] ypos; float[] xvel; float[] yvel; float[] rotvel; float[] rotpos; int[] textureIndex; int objectCount = 150; java.util.Map sortedIndexes = new java.util.TreeMap(); int boxWidth = 200; int boxhalfwidth = 50; void setup () { size(800, 800, OPENGL); // needs to be P3D / OPENGL since we use texture() frameRate(60); smooth(); images = new PImage[10]; textureIndex = new int[objectCount]; xpos = new float[objectCount]; ypos = new float[objectCount]; xvel = new float[objectCount]; yvel = new float[objectCount]; rotpos = new float[objectCount]; rotvel = new float[objectCount]; for ( int i = 0; i < 10; i++) { // images[i] = loadImage("tex" + i + ".png"); images[i] = loadImage("tex12.png"); } for ( int j = 0; j < objectCount; j++) { xpos[j] = random(width); ypos[j] = random(height); rotpos[j] = random(PI); rotvel[j] = (random(200) - 100) / 60000; textureIndex[j] = (int)random(10); xvel[j] = (random(200) - 100) / 300; sortedIndexes.put(new Float(-xvel[j]),new Integer(j)); } noStroke(); } void draw() { // see: http://processing.org/reference/vertex_.html background(2); // for (int i = 0; i < objectCount; i++) int i; Iterator iter = sortedIndexes.values().iterator(); while(iter.hasNext()) { Integer index = (Integer)iter.next(); i = index.intValue(); if (i == objectCount-1) { return; } float zpos = (-xvel[i]) * 50; pushMatrix(); translate(xpos[i],ypos[i],zpos); rotateZ(rotpos[i]); drawShape(images[textureIndex[i]]); popMatrix(); moveShape(i); } } void drawShape(PImage z) { noStroke(); beginShape(); texture(z); vertex( -boxhalfwidth, -boxhalfwidth, -boxhalfwidth, -boxhalfwidth); vertex( boxhalfwidth, -boxhalfwidth, boxhalfwidth, -boxhalfwidth); vertex( boxhalfwidth, boxhalfwidth, boxhalfwidth, boxhalfwidth); vertex( -boxhalfwidth, boxhalfwidth, -boxhalfwidth, boxhalfwidth); endShape(); } void moveShape(int i) { rotpos[i] += rotvel[i]; xpos[i] += xvel[i]; ypos[i] += yvel[i]; if (xpos[i] < -boxWidth) { xpos[i] = width + boxWidth; } if (xpos[i] > width + boxWidth) { xpos[i] = -boxWidth; } }