Skip to content

Instantly share code, notes, and snippets.

@milesmcc
Created November 15, 2017 18:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save milesmcc/ca6433a682f6d963c5ccc67631c91c3e to your computer and use it in GitHub Desktop.
Save milesmcc/ca6433a682f6d963c5ccc67631c91c3e to your computer and use it in GitHub Desktop.
Image explosion; Processing program for ART309
PImage img; // The source image
int cellsize = 2; // Dimensions of each cell in the grid
int columns, rows; // Number of columns and rows in our system
void setup() {
size(720, 720, P3D);
img = loadImage("/Users/Miles/Desktop/Jeremy Mann/IMG_7044.jpg"); // Load the image
columns = img.width / cellsize; // Calculate # of columns
rows = img.height / cellsize; // Calculate # of rows
}
void draw() {
background(0);
// Begin loop for columns
for ( int i = 0; i < columns; i++) {
// Begin loop for rows
for ( int j = 0; j < rows; j++) {
int x = i*cellsize; // x position
int y = j*cellsize; // y position
int loc = x + y*img.width; // Pixel array location
color c = img.pixels[loc]; // Grab the color
// Calculate a z position as a function of mouseX and pixel brightness
float z = (mouseX*3 / float(width)) * brightness(img.pixels[loc]);
// Translate to the location, set fill and stroke, and draw the rect
pushMatrix();
translate(x, y, z);
fill(c, 204);
noStroke();
rectMode(CENTER);
rect(0, 0, cellsize, cellsize);
popMatrix();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment