From: Randolph Wang <rywang@CS.Princeton.EDU>
Date: Fri, 27 Feb 2004 05:03:58 -0500 (EST)
To: rgottron@princeton.edu
Cc: randy_class@CS.Princeton.EDU
Subject: Re: recursive program
Hi Rachel,
A quick hint :)
The function that's responsible for drawing a single star should take
the *center* of the star as its arguments. Repeat, *center*, not top.
(Just to make sure I wasn't fibbing, I actually wrote the program
myself and just for the heck of it, I'll send the images generated by
the star program...)
Randy
> From: "Rachel Gottron" <rgottron@princeton.edu>
> To: <rywang@CS.Princeton.EDU>
> Subject: recursive program
> Date: Fri, 27 Feb 2004 00:42:25 -0500
> Content-Type: text/plain;
> charset="us-ascii"
> X-Priority: 3 (Normal)
> X-MSMail-Priority: Normal
> X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2600.0000
> Importance: Normal
> In-Reply-To:
> X-Spam-Checker-Version: SpamAssassin 2.63 (2004-01-11) on
> memphis.CS.Princeton.EDU
> X-Spam-Status: No, hits=-100.0 required=5.0 tests=USER_IN_WHITELIST
> autolearn=no version=2.63
> X-Spam-Level:
>
> Hi,
>
> I actually got the HTree.java program to work, and now I'm working on my
> own Art.java program. I'm trying to do the 5-point star fractal
> pattern, where at each vertex of the star a new star is drawn. I've
> been working on this for HOURS, and I can't figure out what to do. I've
> drawn the original star in 2 ways: one by
>
> Turtle.fly(x,y)
> Turtle.rotate(-72);
> Turtle.goForward(size);
> Turtle.rotate(-144);
> Turtle.goForward(size);
> Turtle.rotate(-144);
> Turtle.goForward(size);
> Turtle.rotate(-144);
> Turtle.goForward(size);
> Turtle.rotate(-144);
> Turtle.goForward(size);
>
> And the other one by:
>
> Turtle.fly(x, y);
> x = x + size*(Math.cos(72*3.14/180));
> y = y - size*(Math.sin(72*3.14/180));
> Turtle.go(x, y);
> x = x - size*Math.sin(54*3.14/180);
> y = y + size*Math.cos(54*3.14/180);
> Turtle.go(x, y);
> x = x + size;
> Turtle.go(x, y);
> x = x - size*Math.sin(54*3.14/180);
> y = y - size*Math.cos(54*3.14/180);
> Turtle.go(x, y);
> x = x + size*Math.sin(18*3.14/180);
> y = y + size*Math.cos(18*3.14/180);
> Turtle.go(x, y);
>
> Both of these programs lead to drawing the original star. However, I
> don't know how to do this recursively. The locations of the star
> vertices are much more complicated than the HTree. Is there a way to
> change the axes? If I try to write a recursive program to draw the
> stars, I have no way to refer to the vertices. The only way I can think
> of to do this is to draw one segment of the star, then rotate and draw
> the first segment of a new, smaller star, then rotate and draw the first
> segment of a new and still smaller star, until I've arrived at the
> correct depth, at which point I start completing the stars.
> Unfortunately, it seems like this program will be very complicated and
> it could be tail-recursive. I'm giving up for tonight, cause I don't
> know what else to do. Let me know if I can explain this better. I'll
> be in precept tomorrow and I'll probably stay for office hours (but I'm
> worried that there will be a lot of people there). Thanks for your
> time!
>
> ~Rachel
>
Re: recursive program / Randolph Wang