Function Repository Resource:

TurtleArt

Source Notebook

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["TurtleQ"]whether the turtle is being shown
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
TurtleArt["PenDown"][]lower the turtle's pen so that it will draw
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]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/8cd72eaa-58f5-40f5-8c75-9d863c2e4676"]
Out[1]=

Set the screen color:

In[2]:=
ResourceFunction["TurtleArt"]["FillScreen"][70, 98]

Show the turtle icon:

In[3]:=
ResourceFunction["TurtleArt"]["ShowTurtle"][]

Move forward the turtle a distance of 100 units:

In[4]:=
ResourceFunction["TurtleArt"]["Forward"][100]

Rotate the turtle 35° to the right:

In[5]:=
ResourceFunction["TurtleArt"]["Right"][35]

Move forward again 100 units:

In[6]:=
ResourceFunction["TurtleArt"]["Forward"][100]

Draw the turtle's art:

In[7]:=
ResourceFunction["TurtleArt"]["Draw"][]
Out[7]=

Obtain the new values of position, heading and background:

In[8]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/51941e5a-dd0f-4c5c-ae4f-592ce1801b7d"]
Out[8]=

Clean and hide the turtle:

In[9]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/d3d82b8c-09d7-4a47-be65-79b5304ac14c"]
Out[11]=

Possible Issues (3) 

Invalid fields return unevaluated code:

In[12]:=
ResourceFunction["TurtleArt"]["Z"]
Out[12]=

Invalid commands return a Failure object:

In[13]:=
ResourceFunction["TurtleArt"]["ArcRight"][40, 30]
Out[13]=

Invalid command parameters return a Failure object:

In[14]:=
ResourceFunction["TurtleArt"]["SetXY"][
RGBColor[0, 0, 0]]
Out[14]=

Neat Examples (15) 

Dandelion (1) 

Draw dandelion:

In[15]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/a38c7bba-2748-45cf-92b7-034f2f1bef3d"]
Out[15]=

Neonsqi (1) 

Draw neonsqi:

In[16]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/cd3ffc87-f519-486f-9859-e10cf8fa25d4"]
Out[16]=

Beginning (1) 

Draw beginning:

In[17]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/c7c11700-12c0-43f5-9ebf-c7006c59e234"]
Out[17]=

Curls (1) 

Draw curls:

In[18]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/90bec4ef-ed20-45e9-a56f-5ce88bfbaf36"]
Out[18]=

Waves (1) 

Draw waves:

In[19]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/f906e300-a354-4d86-813c-3343f1b6c6a2"]
Out[19]=

Old Sol (1) 

Draw old sol:

In[20]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/5d1dcdb9-5faa-4998-974c-90b4742da3a2"]
Out[20]=

Spaceframe (1) 

Draw spaceframe:

In[21]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/801ec673-6c69-47ab-bbd4-6e18364253ad"]
Out[21]=

Brushes (1) 

Draw brushes:

In[22]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/323286e9-5b17-461b-8032-db01f93f344b"]
Out[22]=

Fireworks (1) 

Draw fireworks:

In[23]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/0e46643d-3cae-4bcc-83ee-d64c6d882771"]
Out[23]=

Dark Sun (1) 

Draw dark sun:

In[24]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/16568a02-7c32-47ad-a8c1-1c085717d536"]
Out[24]=

Whole Flower (1) 

Draw whole flower:

In[25]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/0ef051ee-4cd6-4c14-90d5-e820bc2f00bf"]
Out[25]=

Pinwheel (1) 

Draw pinwheel:

In[26]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/7da320ee-d1c1-433b-acdb-837815e59f9e"]
Out[26]=

Springy (1) 

Draw springy:

In[27]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/f826223d-e15f-4e48-ba2a-78a8e1d17d98"]
Out[27]=

Yellow Jacket (1) 

Draw yellow jacket:

In[28]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/105f383f-2363-4d61-a6be-08dc766a250e"]
Out[28]=

Three Spirals (1) 

Draw three spirals:

In[29]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/6374a8e2-62bb-4fd8-aeef-99ade19bf780"]
Out[29]=

Interactive Examples (2) 

UFO (2) 

Setup a dynamic screen:

In[30]:=
ResourceFunction["TurtleArt"]["Clean"][];
Dynamic[ResourceFunction["TurtleArt"]["Draw"][]]
Out[31]=

Execute the following code and visualize the artwork:

In[32]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/55b84d6e-fc0e-4bc6-b115-2a58d3b74725"]

Publisher

Daniel Sanchez

Version History

  • 1.1.0 – 27 June 2025
  • 1.0.0 – 25 January 2022

Related Resources

License Information