Advertisement
xeromino

3d

May 9th, 2014
679
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.44 KB | None | 0 0
  1. PImage img;       // The source image
  2. int cellsize = 2; // Dimensions of each cell in the grid
  3. int cols, rows;   // Number of columns and rows in our system
  4. float theta;
  5.  
  6. void setup() {
  7.  
  8.   img  = loadImage("3d.jpg"); // Load the image
  9.   size(400, 400, P3D);
  10.   cols = width/cellsize;             // Calculate # of columns
  11.   rows = height/cellsize;            // Calculate # of rows
  12. }
  13.  
  14. void draw() {
  15.   background(0);
  16.   loadPixels();
  17.   // Begin loop for columns
  18.   for ( int i = 0; i < cols;i++) {
  19.     // Begin loop for rows
  20.     for ( int j = 0; j < rows;j++) {
  21.       int x = i*cellsize + cellsize/2; // x position
  22.       int y = j*cellsize + cellsize/2; // y position
  23.       int loc = x + y*width;           // Pixel array location
  24.       color c = img.pixels[loc];       // Grab the color
  25.       // Calculate a z position as a function of mouseX and pixel brightness
  26.       //float z = (mouseX/(float)width) * brightness(img.pixels[loc]) - 100.0;
  27.       float vari = map(sin(theta),-1,1,0,1);
  28.       float z = vari * brightness(img.pixels[loc]) - 100.0;
  29.       // Translate to the location, set fill and stroke, and draw the rect
  30.       pushMatrix();
  31.       rotateY(0.5);
  32.       translate(x+50,y,z);
  33.       fill(c);
  34.       noStroke();
  35.       rectMode(CENTER);
  36.       //box(cellsize);
  37.       rect(0,0,cellsize, cellsize);
  38.       popMatrix();
  39.     }
  40.   }
  41.   theta += 0.0523*2;
  42.  
  43.   //if (frameCount%3==0 && frameCount<121) saveFrame("image-###.gif");
  44.  
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement