Advertisement
xeromino

emoji3D

Jan 30th, 2015
1,322
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.47 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. int frames = 60;
  6.  
  7. void setup() {
  8.  
  9.   img  = loadImage("http://emoji.ink/assets/160x160/750.png"); // Load the image
  10.   size(500, 500, P3D);
  11.   cols = img.width/cellsize;             // Calculate # of columns
  12.   rows = img.height/cellsize;            // Calculate # of rows
  13. }
  14.  
  15. void draw() {
  16.   background(0);
  17.   loadPixels();
  18.   // Begin loop for columns
  19.   for ( int i = 0; i < cols;i++) {
  20.     // Begin loop for rows
  21.     for ( int j = 0; j < rows;j++) {
  22.       int x = i*cellsize + cellsize/2; // x position
  23.       int y = j*cellsize + cellsize/2; // y position
  24.       int loc = x + y*img.width;           // Pixel array location
  25.       color c = img.pixels[loc];       // Grab the color
  26.       // Calculate a z position as a function of mouseX and pixel brightness
  27.       //float z = (mouseX/(float)width) * brightness(img.pixels[loc]) - 100.0;
  28.       float vari = map(sin(theta),-1,1,0,1);
  29.       float z = vari * brightness(img.pixels[loc]) - 50.0;
  30.       // Translate to the location, set fill and stroke, and draw the rect
  31.       pushMatrix();
  32.       rotateY(0.1);
  33.       translate(x+150,y+150,z);
  34.       stroke(c);
  35.       strokeWeight(cellsize);
  36.       rectMode(CENTER);
  37.       point(0,0);
  38.       popMatrix();
  39.     }
  40.   }
  41.   theta += TWO_PI/frames;
  42.  
  43.   //if (frameCount<=frames) saveFrame("image-###.gif");
  44.  
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement