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 › interacting instances of a class
Page Index Toggle Pages: 1
interacting instances of a class (Read 315 times)
interacting instances of a class
Aug 17th, 2006, 7:04pm
 
As my primitive knowledge in programming does not allow me to solve my problem,I need to ask you how can I create a function that allows each instance of a class to be related to another one..
For example:
there is a class that creates shapes(defined by several vertices) in random position and I need to have lots of them.This class also allows the shapes to scale and stretch randomly as well.
The basic problem is that I need a function which would define that each shape generated by this class is attached to one of the previous shape's vertices.
Is there a way to do this?
...does anyone have an idea?
Re: interacting instances of a class
Reply #1 - Aug 17th, 2006, 7:58pm
 
You could make it so that your shapes can have shapes of their own:

Code:
class shape
{
shape[] children;
float x,y... etc

shape(float _x, float _y, etc...)
{
//setup stuff
}

void addShape(float _x, float _y, etc...)
{
shape[] tmp=children;
children=new shape[tmp.length+1];
for(int i=0;i<tmp.length;i++)
{
children[i]=tmp[i];
}
children[tmp.length]=new shape(_x,_y,etc...);
}

void draw()
{
pushMatrix();
//draw us;
for(int i=0;i<children.length;i++)
{
children[i].draw();
}
popMatrix();
}
}
Page Index Toggle Pages: 1