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 › built-in shape data types
Page Index Toggle Pages: 1
built-in shape data types (Read 534 times)
built-in shape data types
Aug 25th, 2009, 4:27pm
 
I come from dynamically typed languages so I have to ask newbie questions about data types. Sorry.

Since the Processing shapes are instantiated without the ceremonial "new" and it appears they aren't of their own data type, ie. an ellipse isn't a data type "ellipse", it seems like the state is immutable. This is fine, I am just not sure at this point if their state is or isn't immutable. How would you resize, delete, change color etc?

Also I am unsure about sub-classing one of these primitives since they seem so different than objects I am used to dealing with. If I am missing an obvious resource that explains these things, please let me know.
Re: built-in shape data types
Reply #1 - Aug 25th, 2009, 5:41pm
 
they're routines -- they paint the shape and are forgotten.  If you want an ellipse you can move around, resize, change colors, delete, etc. you'd probably want a class that renders an ellipse, something like:

Quote:
class ellipseThing(){
  float midpointX, midpointY, ellipseWidth, ellipseHeight;
  color ellipseColor;
  ellipseThing(float x, float y, float w, float h){
    midpointX=x;
    midpointY=y;
    ellipseWidth=w;
    ellipseHeight=h;
    ellipseColor = color(random(255),random(255),random(255));
  }
  void render(){
    fill(ellipseColor);
    ellipse(midpointX,midpointY,ellipseWidth,ellipseHeight);
  }
}


Where you'd be calling myEllipseThing.render() each frame, after background(...);

--Ben
Re: built-in shape data types
Reply #2 - Aug 25th, 2009, 8:58pm
 
Thanks, that explains exactly what I was hoping to find out.
Page Index Toggle Pages: 1