From: Randolph Wang <rywang@CS.Princeton.EDU>
Date: Mon, 1 Mar 2004 20:08:24 -0500 (EST)
To: mh@princeton.edu
Cc: randy_class@CS.Princeton.EDU, allisonl@princeton.edu, jinhee@princeton.edu, drufat@princeton.edu, elleny@princeton.edu, <ien@princeton.edu, ttullius@princeton.edu, tbroderi@princeton.edu, mh@princeton.edu, rli@princeton.edu, ehoa@princeton.edu, rgottron@princeton.edu, kamarebe@princeton.edu, ksalerno@princeton.edu, szeleung@princeton.edu, ajwang@princeton.edu, jjjin@princeton.edu
Subject: Re: color

>  Hi, 
>   
>    
>   
>  I was wondering how you get colors to print out for our creative art 
>  recursion.  I tried looking through turtle.java but I didn't find anything 
>  other than setColor.  Do you know what the syntax is to print a spectrum of 
>  colors, or to fill polygons with a certain color?  Thanks. 
>   
>    
>   
>  michael   

(1)

http://www.cs.princeton.edu/introcs/24inout/colors.html

(2)

There are several different ways of defining colors.  In particular,
if you look at the Laplace.java program, in which we display a gradual
transition of colors from red to blue, you'll see some example use of
colors.

http://dsh.cs.washington.edu:8000/Projects/04s126/precepts/files/06/Laplace.java

(3)

I'm not aware of Turtle primitives for filling a polygon.  If this is
what you want, you'll have to "do it yourself."  In the extreme case,
you can always plot one pixel at a time.  Again, the Laplace.java
example above does essentially that.  (It plots a dot of radius 2
because Turtle.spot(1) didn't work in some cases.)

(4)

Rachel asked me a good question on the relationship between setColor()
and recursion.  The question is that when you come back from a
recursive function, which changed the color to something else, upon
return, do you get your old color back?

The answer is no.  setColor() is kind of a "global" operation and
there's no "memory" of old colors after you have changed it to
something else in any function calls, including recursive ones.

So what do you do if you want your old color back?  You need to call
setColor() explicitly again to set the desired old color after
returning from a recursive function, if this is what you want.


(5)

Lastly, a meta-point.  I'm cc'ing this answer to everyone.  But in
general, I won't spam everyone.  What I will do is that I will cc my
answers to people's questions (or other stuff) to our little web site:

http://dsh.cs.washington.edu:8000/Projects/04s126/

(Anything to randy_class@cs.princeton.edu gets sent to this site.)

If you feel like it, you can check it once in a while to see what, if
anything, I have been saying to other people.  But you don't have
to---for things that I think are sufficiently useful for everyone
to see, I'll just spam everyone.


Randy


Re: color / Randolph Wang