We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › change mouse code to square
Page Index Toggle Pages: 1
change mouse code to square (Read 883 times)
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.
Re: change mouse code to square
Reply #1 - Mar 22nd, 2007, 10:00pm
 
Just want to add that i'm not planning to cheat or copy anything since i read a thread that mentioned this. My teacher is aware that i'm using that example and that i'm asking help on these forums. And the work wont be published outside the school.
Re: change mouse code to square
Reply #2 - Mar 22nd, 2007, 10:55pm
 
You can change the cursor to use an image:
http://processing.org/reference/cursor_.html

cursor(MyImage,MyImage.width/2,MyImage.height/2);
Re: change mouse code to square
Reply #3 - Mar 23rd, 2007, 4:35pm
 
Thanks very much for the reply, it brought me closer but it's not exactly what i wanted but i see that i didn't explain myself really well.
what i meant was that there would automaticly (or with an interaction) move a square from the left side towards the middle and when it reaches the photo, then explode.
Page Index Toggle Pages: 1