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 › getting environment state from PGraphics
Page Index Toggle Pages: 1
getting environment state from PGraphics? (Read 395 times)
getting environment state from PGraphics?
Dec 28th, 2005, 4:27pm
 
Hey all.  I'm working on a "turtle graphics" sketch (which I hope to turn into a library after I get it working).  It would be very helpful to be able to check the current stroke color so that code like this would work:

Turtle t = new Turtle();
stroke(color(0));
t.move(100);
t.rotateLeft(90);
stroke(color(128));
t.move(100);

That code starts the turtle at the center of the screen, has him walk 100 pixels east, turn left 90 degrees (to the north), and walk another 100 pixels.  Unfortunately, since I don't know how to access the environment, the lines are all drawn black.  The northbound segment should be gray.

I've easily gotten it to work by implementing Turtle::stroke() but it would be so much nicer if the turtle could be environmentally aware =)  I looked through the JavaDoc and the source code to PApplet and PGraphics, and the closest thing I could find was to use recorder.strokeColor.  Unfortunately, at the point where I try to access it, recorder is null.  Is there any way to do this?  Thanks!

Regards,
Matt

edit: changed "fill" to "stroke" -- stupid mistake on my part
Re: getting environment state from PGraphics?
Reply #1 - Dec 28th, 2005, 6:13pm
 
public PGraphics g (in PApplet)
public strokeColor, strokeFill (in PGraphics, read only)

g.strokeColor
g.fillColor

Page Index Toggle Pages: 1