Skip to content

Instantly share code, notes, and snippets.

@ericrobskyhuntley
Created April 16, 2025 22:07
Show Gist options
  • Save ericrobskyhuntley/fc5c861c10721175761db36f470db410 to your computer and use it in GitHub Desktop.
Save ericrobskyhuntley/fc5c861c10721175761db36f470db410 to your computer and use it in GitHub Desktop.
Processing script written as part of the introduction sequence for a series of interviews conducted by members of the Agora: Urban Planning and Design editorial board between September 2013 and January 2014. Relocated from personal github repo.
/**
* Granular FlyIn
*
* Built using Daniel Shiffman's "Explode" sketch as a base.
*
* Animates breaking apart of image, converging on z=0 plane.
* Maps pixels from a 2D image into 3D space.
* Saves exported frames as a numbered series of TIF files.
* Haven't actually looked at this since 2014 so this is
* probably extremely suboptimal.
*/
String img_path = "path/to/image.ext";
PImage img;
int cellsize = 1;
int cols, rows;
float frame = 40;
float[][] zArray;
float[][] bArray;
void setup() {
img = loadImage(img_path); // Load the image
size(img.width, img.height, P3D);
cols = img.width / cellsize / 2; // Calculate # of columns
rows = img.height / cellsize; // Calculate # of rows
zArray = new float[cols][rows];
bArray = new float[cols][rows];
frameRate(24);
for ( int q = 0; q < cols; q++) {
for (int r = 0; r < rows; r++) {
zArray[q][r] = random(50,100) * 0.1;
}
}
for ( int q = 0; q < cols; q++) {
for (int r = 0; r < rows; r++) {
bArray[q][r] = random(70,100) * 0.01;
}
}
}
void draw() {
background(0);
if ( frame >= -40) {
//Begin loop for columns
for ( int i = 0; i < cols; i++) {
// Begin loop for rows
for ( int j = 0; j < rows; j++) {
int x = i*cellsize + cellsize/2; // x position
int y = j*cellsize + cellsize/2; // y position
int loc = x + y*img.width; // Pixel array location
color c = img.pixels[loc]; // Grab the color
float z = frame*zArray[i][j];
// Translate to the location, set fill and stroke, and draw the rect
pushMatrix();
translate(x, y, z);
fill(c,brightness(img.pixels[loc])*bArray[i][j]*random(90,100)*0.01);
noStroke();
rectMode(CENTER);
rect(0, 0, cellsize, cellsize);
popMatrix();
}
}
saveFrame("data/output/01/01_####.tif");
frame = frame - (-8.5 * (1/(10*sqrt(TWO_PI))) * pow(2.71828, -pow((frame), 2)/40) + 0.5);
}
else {
noLoop();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment