Help for Mathematica
- To: mathgroup at smc.vnet.net
- Subject: [mg34139] Help for Mathematica
- From: bardin.caroline at caramail.com (Caroline)
- Date: Sun, 5 May 2002 04:48:49 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
Hello! I have a little problem with mathematica. Could someone help me, please? Well, I have this package called turtle and I must write a function "tree" with arguments : length, depth, angle, ratio to draw a binary tree. Then I must also write the Sierpinski's triangle with the function tree. Thanks for helping me. Caro P.S : Sorry for the bad english, I'm french. BeginPackage["Turtle`] (* This package provides four functions for controlling the movement and orientation of a "turtle" graphics device. It maintains a list of the points visited by the turtle in "path", which can then be manipulated and displayed as a Graphics object. The calling routine must begin by invoking initialize[]; it can end by either showturtlepath, or by its own Show[Graphics[Line[path]], options] command. *) initialize::usage = "initialize[p;{0, 0}] places the turtle at p (default is {0, 0}), points it in direction {1, 0}, and sets path to {p}." showturtlepath::usage = "showturtlepath" displays the turtle's path." right::usage = "right[a] turns the turtle a degree to the right." left::usage = "left[a] turns the turtle a degree to the left." forward::usage = "forward[s] moves the turtle forward s units, and appends the coordinates of the new position to path." back::usage = "back[s] moves the turtle back s units, and appends the coordinates of the new position to path." Begin["Turtle`Private`"] initialize[start_:{0, 0}] := (X = start; U = {1, 0}; path = {X}) right[a_] := U = {{Cos[aa = a Degree//N], Sin[aa]}, {-Sin[aa], Cos[aa]}} . U left[a_] := U = {{Cos[aa = a Degree//N], -Sin[aa]}, {Sin[aa], Cos[aa]}} . U forward[s_] := AppendTo[path, X += s U] back[s_] := AppendTo[path, X -= s U] showturtlepath := Show[Graphics[{{RGBColor[0, 0, 1], Line[path]}}], PlotRange->All, AspectRatio->1] End[] EndPackage[]
- Follow-Ups:
- Re: Help for Mathematica
- From: Murray Eisenberg <murraye@attbi.com>
- Re: Help for Mathematica