Q, E to change depth, left and right to change pixelation.
xxxxxxxxxx
PImage img, dimg, img1, img2, dimg1, dimg2;
float dMult = 0.25;
float pixy = 5;
String shape = "box";
void setup() {
size(750, 750, P3D);
background(50);
textSize(64);
textAlign(CENTER, CENTER);
img1 = loadImage("chrom.jpg");
dimg1 = loadImage("chrom-depthmap.jpg");
img2 = loadImage("Mango.jpg");
dimg2 = loadImage("Mango-depthmap.jpg");
img = img1;
dimg = dimg1;
}
void draw() {
background(50);
noStroke();
fill(255);
if (img.width == 0 || dimg.width == 0) {
text("Loading...", 250, 375);
return;
}
camera(mouseX, mouseY, 500 + constrain(dMult * 200, 50, dMult * 200 + 1), width / 2, height / 2, 0, 0, 1, 0);
for (int y = 0; y < img.height; y += pixy) {
for (int x = 0; x < img.width; x += pixy) {
int loc = x + y * img.width;
color pixC = img.pixels[loc];
if (keyPressed) {
if (key == ' ') {
pixC = dimg.pixels[loc];
}
}
float zB = 255 - brightness(dimg.pixels[loc]);
tile nT = new tile((x / 1.5) + 250, (y / 1.5) + 255, zB, pixC);
nT.render(dMult);
}
}
lights();
if (keyPressed) {
if (key == 'q' || key == 'Q') {
dMult += 0.01;
}
if (key == 'e' || key == 'E') {
dMult -= 0.01;
}
if (keyCode == RIGHT) {
pixy++;
}
if (keyCode == LEFT) {
pixy--;
if (pixy < 5)
pixy = 5;
}
}
}
void keyPressed() {
if (key == '1') {
img = img1;
dimg = dimg1;
}
if (key == '2') {
img = img2;
dimg = dimg2;
}
if (key == 'b') {
shape = "box";
} else if (key == 's') {
shape = "sphere";
} else if (key == 'r') {
shape = "rect";
}
}
class tile {
int x, y, z;
color pixC;
tile(int nX, nY, nZ, color nC) {
x = nX;
y = nY;
z = nZ;
pixC = nC;
}
void render(float dph) {
pushMatrix();
translate(x, y, (z * dph));
fill(pixC);
switch (shape) {
case "box":
box(pixy * .7);
break;
case "sphere":
sphere(pixy * .7);
break;
case "rect":
rect(0, 0, pixy * .7, pixy * .7);
break;
}
popMatrix();
}
}