daily pastebin goal
0%
SHARE
TWEET

Untitled

a guest Nov 17th, 2017 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. PImage img;       // The source image
  2. int cellsize = 2; // Dimensions of each cell in the grid
  3. int columns, rows;   // Number of columns and rows in our system
  4.  
  5. void setup() {
  6.   size(720, 720, P3D);
  7.   img = loadImage("/Users/Miles/Desktop/Jeremy Mann/IMG_7044.jpg");  // Load the image
  8.   columns = img.width / cellsize;  // Calculate # of columns
  9.   rows = img.height / cellsize;  // Calculate # of rows
  10. }
  11.  
  12. void draw() {
  13.   background(0);
  14.   // Begin loop for columns
  15.   for ( int i = 0; i < columns; i++) {
  16.     // Begin loop for rows
  17.     for ( int j = 0; j < rows; j++) {
  18.       int x = i*cellsize;  // x position
  19.       int y = j*cellsize;  // y position
  20.       int loc = x + y*img.width;  // Pixel array location
  21.       color c = img.pixels[loc];  // Grab the color
  22.       // Calculate a z position as a function of mouseX and pixel brightness
  23.       float z = (mouseX*3 / float(width)) * brightness(img.pixels[loc]);
  24.       // Translate to the location, set fill and stroke, and draw the rect
  25.       pushMatrix();
  26.       translate(x, y, z);
  27.       fill(c, 204);
  28.       noStroke();
  29.       rectMode(CENTER);
  30.       rect(0, 0, cellsize, cellsize);
  31.       popMatrix();
  32.     }
  33.   }
  34. }
RAW Paste Data
Top