I needed something to do on the airplane tripe over to Hawaii, so I took motivation from the the airport ceiling:
and made this flippy floppy animation
import processing.opengl.*;
ArrayList boxes;
PImage side1, side2;
PImage itexture1, itexture2;
int x = 0;
boolean c = true;
class mrbox {
int x;
int y;
PImage t1, t2;
int r = 0;
int s = 100;
int rinc = 1;
boolean ani=true;
mrbox(int x, int y, PImage t1, PImage t2) {
this.t1 = t1;
//this.t1.blend(itexture1,0,0,100,100,0,0,100,100,MULTIPLY);
this.t2 = t2;
//this.t1.blend(itexture2,0,0,100,100,0,0,100,100,MULTIPLY);
this.x = x;
this.y = y;
rinc = floor(random(1, 3));
rinc = 5;
}
void restart() {
ani = true;
//rinc = floor(random(1, 10));
}
boolean draw() {
pushMatrix();
translate(x, y, -100);
rotateX(radians(r)) ;
if (ani) {
r+=rinc;
if (r < 0 ) {
ani=false;
rinc = 1 * floor(random(1, 5));
r=1;
}
if (r > 180) {
ani = false;
r=179;
rinc = -1 * floor(random(1, 5)) ;
}
}
textureMode(NORMALIZED);
beginShape();
texture(t1);
vertex(0, -s/2, 1, 0, 0);
vertex(s, -s/2, 1, 1, 0);
vertex(s, s/2, 1, 1, 1);
vertex(0, s/2, 1, 0, 1);
endShape();
beginShape();
texture(t2);
vertex(0, -s/2, 2, 0, 0);
vertex(s, -s/2, 2, 1, 0);
vertex(s, s/2, 2, 1, 1);
vertex(0, s/2, 2, 0, 1);
endShape();
popMatrix();
return ani;
}
}
void setup() {
size(800, 800, OPENGL);
side1 = loadImage("img1.jpg");
side2 = loadImage("img2.jpg");
itexture1 = loadImage("box1.png");
itexture2 = loadImage("box2.png");
boxes =new ArrayList();
for (int x=0; x< width; x+=100) {
for (int y=0; y < height; y+=100) {
boxes.add( new mrbox(x, y, side1.get(x, 700-y, 100, 100), side2.get(x, y, 100, 100)) );
}
}
}
int z=-100;
int zinc=4;
boolean drawmore = true;
void draw() {
background(0, 90);
/*
z+=zinc;
if (z < -1200) {
zinc = 4;
}
if (z > -300) {
zinc = -4;
}
translate(0, 0, z);
*/
drawmore = false;
for (int i=0; i < boxes.size(); i++) {
mrbox b = (mrbox) boxes.get(i);
if ( b.draw() ) {
drawmore = true;
}
}
if ( ! drawmore ) {
for (int i=0; i < boxes.size(); i++) {
mrbox b = (mrbox) boxes.get(i);
b.restart();
}
}
saveFrame("output/out####.jpg");
f
}