plot
::Turtle
“turtle graphics” (imperative drawings)
MuPAD® notebooks are not recommended. Use MATLAB® live scripts instead.
MATLAB live scripts support most MuPAD functionality, though there are some differences. For more information, see Convert MuPAD Notebooks to MATLAB Live Scripts.
plot::Turtle(commands
, <a = a_{min} .. a_{max}
>, options
)
Turtle graphics define a line drawing by a sequence of commands to an abstract robot.
plot::Turtle
defines a graphic by sending
movement commands to an abstract robot. This robot starts heading
up and standing at the origin, with its pen ready for drawing (“down”)
and the line color taken from the attribute LineColor
.
The following commands are known to the robot:
Left(α)
Turn left by the angle α (in radians).
Right(α)
Turn right by the angle α (in radians).
Forward(d)
Move forward distance d.
Up
Lift the “pen”, i.e., subsequent movement commands do not draw lines.
Down
Lower the “pen”, i.e., subsequent movement commands do draw lines.
Push
Remember the current state (position, angle, line color).
Pop
Restore the last remembered state and remove it from the list of remembered states.
Noop
This command is ignored.
LineColor(c)
Set the line color to the colorc
.
The commands not taking an argument may also be entered with
empty parentheses ()
after, e.g., Push()
.
A plot::Turtle
object can be manipulated
dynamically by calling its methods left
, right
, forward
, penUp
, penDown
, push
, pop
,
and setLineColor
, with the obvious connections
to the commands above. These methods append a new command to the end
of the list. Cf. Example 3.
For long command sequences, it is highly recommended to give
the commands directly using the syntax above or by setting the CommandList
attribute
directly.
Both angles and distances can be animated. Colors can not.
Attribute  Purpose  Default Value 

AffectViewingBox  influence of objects on the ViewingBox of
a scene  TRUE 
AntiAliased  antialiased lines and points?  TRUE 
Color  the main color  RGB::Blue 
CommandList  turtle movement commands  [] 
Frames  the number of frames in an animation  50 
Legend  makes a legend entry  
LegendText  short explanatory text for legend  
LegendEntry  add this object to the legend?  FALSE 
LineColor  color of lines  RGB::Blue 
LineWidth  width of lines  0.35 
LineStyle  solid, dashed or dotted lines?  Solid 
LinesVisible  visibility of lines  TRUE 
Name  the name of a plot object (for browser and legend)  
ParameterEnd  end value of the animation parameter  
ParameterName  name of the animation parameter  
ParameterBegin  initial value of the animation parameter  
ParameterRange  range of the animation parameter  
PointSize  the size of points  1.5 
PointStyle  the presentation style of points  FilledCircles 
PointsVisible  visibility of mesh points  FALSE 
TimeEnd  end time of the animation  10.0 
TimeBegin  start time of the animation  0.0 
TimeRange  the real time span of an animation  0.0 .. 10.0 
Title  object title  
TitleFont  font of object titles  [" sansserif " , 11 ] 
TitlePosition  position of object titles  
TitleAlignment  horizontal alignment of titles w.r.t. their coordinates  Center 
TitlePositionX  position of object titles, x component  
TitlePositionY  position of object titles, y component  
Visible  visibility  TRUE 
VisibleAfter  object visible after this time value  
VisibleBefore  object visible until this time value  
VisibleFromTo  object visible during this time range  
VisibleAfterEnd  object visible after its animation time ended?  TRUE 
VisibleBeforeBegin  object visible before its animation time starts?  TRUE 
A square can be drawn by four times moving forward, each time turning right 90°:
plot(plot::Turtle([Forward(1), Right(PI/2), Forward(1), Right(PI/2), Forward(1), Right(PI/2), Forward(1), Right(PI/2)]))
Using the $
operator, this command list can be
written much shorter:
plot(plot::Turtle([(Forward(1), Right(PI/2))$4]))
In the same fashion, we can draw any regular nsided polygon:
n := 7: plot(plot::Turtle([(Forward(1), Right(2*PI/n)) $ n]))
The distance to move may contain an animation parameter:
plot(plot::Turtle([Forward(1+a), Right(PI/2), Forward(12*a), Right(PI/2), Forward(1+3*a), Right(PI/2), Forward(14*a), Right(PI/2), Forward(1+5*a)], a=0..2))
Likewise, the angle can be animated:
plot(plot::Turtle([(Forward(1), Right(a))$10], a = 0.25..2.5))
It is also possible to successively append commands to the list:
t := plot::Turtle()
t::forward(1)
for i from 1 to 9 do t::left(3*PI/5); t::forward(1); end_for
plot(t)
As an extension to the original turtle model, the line color may be changed while plotting:
t := plot::Turtle(): t::setLineColor(RGB::Red): t::forward(1): p := float(PI/5): for i from 1 to 9 do t::left(108*PI/180); t::setLineColor([cos(i*p), sin(i*p), 0.0]); t::forward(1); end_for;
plot(t)
Note that the color within one line segment is constant.
Another extension to the turtle model is that plot::Turtle
supports
a stack of saved states, enabling the robot to return to previous
positions:
t := plot::Turtle(): t::forward(5): for i from 3 to 4 do t::push(); t::left(PI/18*i); t::forward(3); t::pop(); end_for: plot(t)
Using small steps, it is possible to create appealing curves
with plot::Turtle
:
t := plot::Turtle(LineColor = RGB::Green): t::forward(2): for dir in [1, 1] do t::push(); t::left(dir*PI/30); for i from 1 to 10 do t::forward(0.2); t::left(dir*PI/30); end_for; t::left(dir*2/3*PI); for i from 1 to 10 do t::forward(0.2); t::left(dir*PI/30); end_for; t::pop() end_for: t::forward(3): t::setLineColor(RGB::Red): for dir from 5 to 5 do t::push(); t::left(dir*2*PI/11); for i from 1 to 10 do t::forward(0.1); t::left(PI/30); end_for; t::left(2*PI/3); for i from 1 to 10 do t::forward(0.1); t::left(PI/30); end_for; t::pop() end_for: plot(t)

A list of commands. See below for command definitions.


Animation parameter, specified as 