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 › Using MouseY To Increase Size of Looped Objects
Page Index Toggle Pages: 1
Using MouseY To Increase Size of Looped Objects (Read 551 times)
Using MouseY To Increase Size of Looped Objects
Dec 4th, 2009, 6:11pm
 
Hi, I apologise for asking such a basic question (I'm a newbie) but I can't quite see in my code where my problem of not being able to use mouseY interaction to increase the size of some rectangles. I want the rectangles to increase in height every time the mouse "touches" them.

I am using dist:

float distance = dist(mouseX,mouseY,xPos,yPos);    //?

Here is my code:

//float distance = dist(mouseX,mouseY,10,10);

float xPos=0;        //these are the initial coordinates/position of the row of rectangles but I want the mouse to be detected along all of them separately.
float yPos=250;

float w=100;
float h=100;
float xBase=150;
float yBase=150;

float increaseHeight=12.5;

void setup()
{
 size(500,500);
 background(255);
 smooth();
 stroke(0);
 strokeWeight(1);
}

void draw()
{
 //background(255);
 float distance = dist(mouseX,mouseY,xPos,yPos);    //shouldn't the xPos and yPos mean that wherever the rectangle is the mouse will affect it?
 
 fill(0,0,255);
 if (distance < 12.5)
 {
   rect(xPos,yPos,100,increaseHeight);    //?
   xPos=xPos+100;
   increaseHeight=increaseHeight+12.5;  //increase rectangle height when mouse "touches"
 }
 rect(xPos,yPos,100,increaseHeight);    // I have the rectangle outside and inside the if statement because I'm not sure which one it belongs inside?
 xPos=xPos+100;


 noFill();
 stroke(1);
 
   for(xBase=0; xBase<500; xBase=xBase + 100)
 {
   rect(xBase, yBase, w, h);
 }
}
Re: Using MouseY To Increase Size of Looped Objects
Reply #1 - Dec 5th, 2009, 1:25am
 
Wow, lot of question marks...
First, if you remove the background() call, you won't see much, as you will draw over previous drawings...
Second, dist() is OK to check collision of two circles, but inappropriate for checking if mouse is over a rectangle. For this, you verify if the mouse position is between the bounds of the rectangle: x over left side and below right side, idem for y.
The rect call inside/outside of if. Neither, you have to draw the rectangle like the others, in the loop, but change its height depending on previous test.
Page Index Toggle Pages: 1