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 › Click to resize an object
Page Index Toggle Pages: 1
Click to resize an object (Read 431 times)
Click to resize an object
Jun 1st, 2006, 6:47pm
 
Hi there,

I am new to programming and I have spent hours trying to figure out how to do the following mouse interaction in Processing. If anyone could give some guidance I would be really grateful.

Basically what I want is a simple box on screen, that re-sizes or changes location each time the mouse is pressed. Ideally the shape should animate between each new size/location. The locations could be random, or ideally specified as target coordinates.

The problem I am having is writing the code that checks the current location/size then moves the shape towards a new target.

If anyone has seen some code that does a similar thing that would be really helpful.

Many thanks in advance,
Windy

Re: Click to resize an object
Reply #1 - Jun 1st, 2006, 7:07pm
 
i hope this is not your homework! Smiley

F

Code:

float bx, by;
float mx,my;

void setup () {

size( 200, 200 );

}

void draw ()
{
background(125);
bx = bx + (mx-bx) / 100.0;
by = by + (my-by) / 100.0;
rect ( bx, by, 10, 10 );
}


void mousePressed ()
{
mx = mouseX;
my = mouseY;
}
Re: Click to resize an object
Reply #2 - Jun 1st, 2006, 7:22pm
 
Ha ha no. Just experimenting with Processing. Thanks for the code. That helps a lot.

Smiley
Page Index Toggle Pages: 1