"turtle graphics" (imperative drawings)
This functionality does not run in MATLAB.
plot::Turtle(commands, <a = amin .. amax>, 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:
Turn left by the angle α (in radians).
Turn right by the angle α (in radians).
Move forward distance d.
Lift the "pen", i.e., subsequent movement commands do not draw lines.
Lower the "pen", i.e., subsequent movement commands do draw lines.
Remember the current state (position, angle, line color).
Restore the last remembered state and remove it from the list of remembered states.
This command is ignored.
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.
Note: 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.
|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|
|TitleFont||font of object titles||[" sans-serif ", 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|
|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:
In the same fashion, we can draw any regular n-sided 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(1-2*a), Right(PI/2), Forward(1+3*a), Right(PI/2), Forward(1-4*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()
for i from 1 to 9 do t::left(3*PI/5); t::forward(1); end_for
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;
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.
commands is equivalent to the attribute CommandList.
Animation parameter, specified as a = amin..amax, where amin is the initial parameter value, and amax is the final parameter value.