Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- PImage img; // The source image
- int cellsize = 2; // Dimensions of each cell in the grid
- int cols, rows; // Number of columns and rows in our system
- float theta;
- void setup() {
- img = loadImage("3d.jpg"); // Load the image
- size(400, 400, P3D);
- cols = width/cellsize; // Calculate # of columns
- rows = height/cellsize; // Calculate # of rows
- }
- void draw() {
- background(0);
- loadPixels();
- // 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*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/(float)width) * brightness(img.pixels[loc]) - 100.0;
- float vari = map(sin(theta),-1,1,0,1);
- float z = vari * brightness(img.pixels[loc]) - 100.0;
- // Translate to the location, set fill and stroke, and draw the rect
- pushMatrix();
- rotateY(0.5);
- translate(x+50,y,z);
- fill(c);
- noStroke();
- rectMode(CENTER);
- //box(cellsize);
- rect(0,0,cellsize, cellsize);
- popMatrix();
- }
- }
- theta += 0.0523*2;
- //if (frameCount%3==0 && frameCount<121) saveFrame("image-###.gif");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement