Function Repository Resource:

# TurtleArt

Make art with code

Contributed by: Brian Silverman and Daniel Sanchez
 ResourceFunction["TurtleArt"]["field"] returns the specified ResourceFunction["TurtleArt"] field. ResourceFunction["TurtleArt"]["command"][] executes the specified ResourceFunction["TurtleArt"] command. ResourceFunction["TurtleArt"]["command"][params] executes the command with the parameters params.

## Details

A turtle follows a sequence of commands: draw lines and arcs, rotate, draw in different colors, go to a specific place on the screen, etc.
ResourceFunction["TurtleArt"] was inspired by the LOGO programming language and was designed to be easy enough for children and yet powerful enough for people of all ages.
The following fields are supported:
 TurtleArt["Background"] the screen color TurtleArt["Color"] the color of the turtle's pen TurtleArt["Heading"] the heading of the turtle TurtleArt["PenQ"] True if the pen is down; False otherwise TurtleArt["Pensize"] the width of the turtle's pen TurtleArt["Shade"] the shade of the turtle's pen TurtleArt["X"] the x (horizontal) coordinate of the turtle TurtleArt["Y"] the y (vertical) coordinate of the turtle
For appropriate fields, ResourceFunction["TurtleArt"]["field"]=val can be used to set the value of a field.
The following commands are supported:
 TurtleArt[“Arc”][a,r] move the turtle in an arc with an angle a and a distance of r units TurtleArt[“Back”][n] move the turtle backward n units TurtleArt[“Clean”][] clear the screen and reposition the turtle to the center TurtleArt["Draw"][] draw to the screen TurtleArt[“FillScreen”][c,s] fill the screen with a color c and a shade s TurtleArt["Forward"][n] move the turtle forward n units TurtleArt["HideTurtle"][] hide the turtle icon TurtleArt["Left"][n] turn the turtle left n units ResourceFunction["TurtleArt"]["PenDown"][] lower the turtle's pen so that it will draw ResourceFunction["TurtleArt"]["PenUp"][] raise the turtle's pen so that it will not draw TurtleArt["Right"][n] turn the turtle right n units TurtleArt["SetColor"][c] set the color of the turtle's pen to c TurtleArt["SetHeading"][h] set the heading of the turtle to h TurtleArt["SetPensize"][w] set the width of the turtle's pen to w TurtleArt["SetShade"][s] set the shade of the turtle's pen to s TurtleArt["SetXY"][x,y] set the position of the turtle to {x,y} TurtleArt["ShowTurtle"][] show the turtle icon
ResourceFunction["TurtleArt"] works with a coordinate system. The turtle's default position is {0,0}, which is the middle of the screen:
The heading of the turtle is given in degrees, where 0 degrees means the turtle is directed upwards.
In ResourceFunction["TurtleArt"], the color and shade numbers are between 0 and 100. The default color is 0 and the default shade is 50:

## Examples

### Basic Examples (9)

Obtain the turtle's initial position, heading and background:

 In[1]:=
 Out[1]=

Set the screen color:

 In[2]:=

Show the turtle icon:

 In[3]:=

Move forward the turtle a distance of 100 units:

 In[4]:=

Rotate the turtle 35° to the right:

 In[5]:=

Move forward again 100 units:

 In[6]:=

Draw the turtle's art:

 In[7]:=
 Out[7]=

Obtain the new values of position, heading and background:

 In[8]:=
 Out[8]=

Clean and hide the turtle:

 In[9]:=
 Out[11]=

### Possible Issues (3)

Invalid fields return unevaluated code:

 In[12]:=
 Out[12]=

Invalid commands return a Failure object:

 In[13]:=
 Out[13]=

Invalid command parameters return a Failure object:

 In[14]:=
 Out[14]=

### Neat Examples (15)

#### Dandelion (1)

Draw dandelion:

 In[15]:=
 Out[15]=

#### Neonsqi (1)

Draw neonsqi:

 In[16]:=
 Out[16]=

#### Beginning (1)

Draw beginning:

 In[17]:=
 Out[17]=

#### Curls (1)

Draw curls:

 In[18]:=
 Out[18]=

#### Waves (1)

Draw waves:

 In[19]:=
 Out[19]=

#### Old Sol (1)

Draw old sol:

 In[20]:=
 Out[20]=

#### Spaceframe (1)

Draw spaceframe:

 In[21]:=
 Out[21]=

#### Brushes (1)

Draw brushes:

 In[22]:=
 Out[22]=

#### Fireworks (1)

Draw fireworks:

 In[23]:=
 Out[23]=

#### Dark Sun (1)

Draw dark sun:

 In[24]:=
 Out[24]=

#### Whole Flower (1)

Draw whole flower:

 In[25]:=
 Out[25]=

#### Pinwheel (1)

Draw pinwheel:

 In[26]:=
 Out[26]=

#### Springy (1)

Draw springy:

 In[27]:=
 Out[27]=

#### Yellow Jacket (1)

Draw yellow jacket:

 In[28]:=
 Out[28]=

#### Three Spirals (1)

Draw three spirals:

 In[29]:=
 Out[29]=

### Interactive Examples (2)

#### UFO (2)

Setup a dynamic screen:

 In[30]:=
 Out[31]=

Execute the following code and visualize the artwork:

 In[32]:=

Daniel Sanchez

## Version History

• 1.0.0 – 25 January 2022