//Stereogram test #2 //(C) 2004 Haruka Kataoka JumpPanel jparr[]; float phase = 0.0; float v = 0.2; void setup() { size(500, 300); jparr = new JumpPanel[25]; for (int y=-2; y<=2; y++) { for (int x=-2; x<=2; x++) { jparr[5*(y+2)+(x+2)] = new JumpPanel(x*40-20, y*40-20, 40, 40); } } framerate(24); background(0, 0, 0); fill(0, 0, 80); stroke(0, 0, 80); } void loop() { if (phase <= 0.0) { phase = 2 * PI; for (int i=0; i<25; i++) { jparr[i].reset(); jparr[i].move(0); } }else{ float sn = sin(phase -= v); for (int i=0; i<25; i++) { jparr[i].move(sn); } } background(0, 0, 0); for (int i=0; i<25; i++) jparr[i].display(); } //class Jumping Panel class JumpPanel { int x, y, w, h; float z; float amplitude;// Anmplitude of Z moving float distance = 200; //distance from eye float parallax = 20.0;//default parallax //Constructor JumpPanel (int ax, int ay, int aw, int ah) { x = ax; y = ay; w = aw; h = ah; reset(); } //Reset Amplitude void reset() { amplitude = random(-100, 100); } //set z (k = [-1.0 , 1.0]) void move(float k) { z = k * amplitude; } //display void display() { float r = distance / (distance+z);//display size rate //display x, y, w, h and parallax int dw = (int)(w * r); int dh = (int)(h * r); int dx = (int)((x - (dw-w)/2) * r); int dy = (int)((y - (dh-h)/2) * r); int dp = (int)((parallax * r - parallax)/2.0); rect(dx+150+dp, dy+150, dw, dh);// left image rect(dx+350-dp, dy+150, dw, dh);// right image } }