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 › Values from Class
Page Index Toggle Pages: 1
Values from Class (Read 452 times)
Values from Class
May 21st, 2009, 7:01am
 
Hello,

I'm pretty new to processing but i already started to love it!
My problem right now is that i can't manage to figure out how to call or to get x,y values of an object (ellipse center) from a class to another one... If you could help me figure it out, i would be very happy  Smiley
I've tried to search for something like this on the web, but probably i was not using the correct "term" since nothing useful came up.

It's pretty urgent so please HELP!

Thanks in advance
Re: Values from Class
Reply #1 - May 21st, 2009, 7:54am
 
Your request is a bit vague, so I made an example sketch showing various ways to do so.
I made direct access to class fields. In real world Java application, these fields would be private and would have accessors (methods to read or write them), but in most Processing sketches, it is enough.
Code:
void setup()
{
size(500, 500);
Ellipse e1, e2, e3;
e1 = new Ellipse(100, 100, 120, 190);
fill(255);
stroke(#0077AA);
strokeWeight(4);
e1.Draw();
e2 = new Ellipse(e1);
e2.rh /= 1.2;
e2.rv /= 1.2;
stroke(#0099CC);
e2.Draw();
stroke(#00BBFF);
e3 = new Ellipse(20, 50, 20, 90);
e3.Draw();
e3.cx = e1.cx;
e3.cy = e1.cy;
e3.Draw();
}

class Ellipse
{
int cx, cy;
int rh, rv;

// Regular constructor
Ellipse(int x, int y, int h, int v)
{
cx = x; cy = y;
rh = h; rv = v;
}
// Copy constructor
Ellipse(Ellipse e)
{
cx = e.cx; cy = e.cy;
rh = e.rh; rv = e.rv;
}
void Draw()
{
ellipse(cx, cy, rh, rv);
}
}
Page Index Toggle Pages: 1