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 › making a shape appear and grow with mouse
Page Index Toggle Pages: 1
making a shape appear and grow with mouse (Read 483 times)
making a shape appear and grow with mouse
Feb 16th, 2010, 5:47pm
 
Hi, this is for a class project im doing.

I want to be able to click the mouse button and a circle appears where i clicked and grows bigger and bigger. And i want that to happen every time I click the mouse button.

It seems like itd be so simple but I just cant figure out how to do it with my current limited knowledge Sad
Re: making a shape appear and grow with mouse
Reply #1 - Feb 16th, 2010, 7:25pm
 
It's not *that* simple unless you have a limited number of circles.  Each frame, you need to know:
1. where each circle is (x,y)
2. how large each circle is. (r)

There is a class, PVector, which can take 3 variables (intended to be used for x,y, and z, but you could use z for r).  If you don't want to learn to write classes, that is a possible approach.  (An array of PVectors.)

However, ideally you'd have a 'circle' class, instances of which are generated on click, and put into a list with a flexible number of elements, like an ArrayList or Vector.  If you're using Vectors, the syntax looks like this:

Vector circleList = new Vector();
void mousePressed(){ circleList.add(new circle()); }
for (int i=0;i<circleList.size();i++){
  ((circle)circleList.get(i)).expand();
  ((circle)circleList.get(i)).render();
}

etc.

Then a circle class, which could look something like this:

class circle{
 float x,y,r;
 circle(){
    x = mouseX;
    y = mouseY;
    r = 1;
 }
 void expand(){
    r++;
 }
 void render(){
    etc.
 }
}

Hope this is clear
--Ben
Page Index Toggle Pages: 1