Lieve
YaBB Newbies
Offline
Posts: 8
change mouse code to square
Mar 21st , 2007, 4:45pm
Greetings, I'm new to the forum and fairly new to processing. I tried to find a topic that discussed this already but didn't find one so hope i'm not repeating questions. We're learning it at multimedia in school but this is the first year we're learning about it so i'm certainly still a novice at it( to put it in a polite way :p). We were given an assignment to work around an object and i took a cowboy hat, now we had to do something in processing about it. I found a really good example here that i liked to use, called explosion. But i'd like to change the mouse movement into a bullet (square) that will hit my picture and then make it explode. here's the coding; 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 void setup() { size(200, 200, P3D); img = loadImage("eames.jpg"); // Load the image COLS = width/cellsize; // Calculate # of columns ROWS = height/cellsize; // Calculate # of rows colorMode(RGB,255,255,255,100); // Setting the colormode } void draw() { background(0); // 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.0f; // Translate to the location, set fill and stroke, and draw the rect pushMatrix(); translate(x,y,z); fill(c); noStroke(); rectMode(CENTER); rect(0,0,cellsize,cellsize); popMatrix(); } } } I tried different things but i'm still new to this and a bit clueless, any help would be welcome. Thanks in advance. ps: I apolegize for my english, it's not my native language hehe, hope i was clear.