vortdog
YaBB Newbies
Offline
Posts: 6
Re: causing pixels to fall
Reply #4 - Dec 7th , 2008, 9:46am
wow, thank you so much PhiLho, really appreciate it. o.k., so from the rotating suggestion, i went onto mapping my 2d image to 3d and have caused some pixels to fall. (which i was very excited about : ) !) when you click the mouse, the pixels fall away (watch carefully) they only fall away once though. http://itp.nyu.edu/~lg1285/ICM/final2/ now, my wish is to be able to have a history of where my mouse has been. to make a path of dropped pixels to get to the image underneath. the suggestion i have gotten so far was to create a 2d array to hold my pixels and a boolean array..... i have started declaring them (haven't initialized them yet) and wrote a couple "if" statements. the code i am stuck on is commented out between the rows of ====== questions : -where do i initialize these arrays? my code is getting complex and i still can't swing elegant/simplified code (still don't quite understand classes) - are width and height what i want to be passing into my arrays? or would it be the number of pixels, such as the dimensions? - anyone know why i lost some of the opacity of my images? thanks! not sure why i can't load my a new applet so here is the code with the commented out parts that i'm stuck on. here is the code: PImage img; // The source image PImage img1; int cellsize = 5; // Dimensions of each cell in the grid int columns, rows; // Number of columns and rows in our system ============================= /* int[][] pixelLoc = new int [width][height]; boolean[] beenTouched = new boolean [width,height]; */ ============================= void setup() { size(600, 450, P3D); img1 = loadImage("grey.4.jpg"); img = loadImage("layer.2.jpg"); // Load the image columns = img.width / cellsize; // Calculate # of columns rows = img.height / cellsize; // Calculate # of rows } int speed = 0; int gravity = 1; void draw() { background(img1); int mx = mouseX; int my = mouseY; // 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 + cellsize/2; // x position int y = j*cellsize + cellsize/2; // y position int loc = x + y*img.width; // Pixel array location color c = img.pixels[loc]; // Grab the color float distance = dist(x,y,mouseX,mouseY); float z = 0; if (distance < 10 && mousePressed == true) { y = y + speed; speed = speed + gravity; } ========================== /* if (distance < 10) { beenTouched[i][j]= true; } if (y > height) { y = 0; } */ ========================= // 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(); } } updatePixels(); }