Turtle Visualizer
This visualizer interprets a sequence as instructions for a drawing machine, often known as a "turtle" after a simple drawing robot built in the 1960s. For some domain of possible values, each entry in the sequence determines an angle and step length. The visualizer displays the resulting polygonal path.
There are two ways that the resulting path shown might change with each frame, which may be used individually or in combination:
-
You can select that the length of path drawn on each frame will increase by a fixed amount, starting from an empty path. (This type of path growth is the default behavior; the alternative is to draw the entire path at once.)
-
You can set non-zero values for the fold and stretch parameters in the "morphing controls" section, so that the angles and/or step lengths defining the turtle's path gradually change over time, resulting in a visual effect reminiscent of protein folding.
Parameters
- Domain: a list of numbers. These are the values that that the turtle should pay attention to when appearing as entries of the sequence. Values of the sequence not occurring in this list will be skipped. (One way to ensure a small number of possible values is to use a sequence that has been reduced with respect to some small modulus. But some sequences, like A014577 "The regular paper-folding sequence", naturally have a small domain.)
The following set of parameters give the instructions for the turtle's path (and how it changes from frame to frame). Each one can be a single number, in which case it is used for every element of Domain. Or it can be a list of numbers the same length as Domain, in which case the numbers correspond in order: the first number is used when an entry is equal to the first value in Domain, the second number is used for entries equal to the second value, and so on. For example, if the Step length(s) parameter below is "10", then a segment 10 pixels long will be drawn for every sequence entry in Domain, whereas if Domain is "0 1 2" and Step length(s) is "20 10 0", then the turtle will move 20 pixels each time it sees a sequence entry of 0, 10 pixels for each 1, and it won't draw anything when an entry is equal to 2 (but it might turn).
- Angle(s): Determines the bearing angle (in degrees) for the turtle before each step (corresponding to one sequence entry in Domain). Angles are measured so that positive angles run counterclockwise, and negative clockwise.
- Angle is...: specifies whether the angle for each step is taken directly as the new bearing of the turtle (counterclockwise from moving horizontally to the right), or as a turn (counterclockwise change in bearing) from its previous bearing. In either case, the turtle takes on its new bearing before taking its next step.
- Step length(s): Specifies (in pixels) how far the turtle should move (and draw a line segment as it goes) for each sequence entry in Domain. Note negative values (for moving backward) are allowed.
- Folding rate(s): Specifies (in units of 0.00001 degree) how each angle changes from one frame to the next. For example, if there is just one entry of "5" here, then in each frame of the visualization, the angle for every element of Domain will increase by 0.00005 degree. Similarly, if Domain is "0 1" and this list is "200 -100" then in each frame the angle for 0 entries will increase by 0.002 degrees, and the angle for 1 entries will decrease by 0.001 degree. These increments might seem small, but with so many steps in a turtle path, a little goes a long way.
- Stretch rate(s): Specifies (in units of 0.01 pixel) how each step length changes from one frame to the next.
- Stroke width(s): Gives the width of the segment drawn for each entry, in pixels.
- Stroke color(s): One or more colors, corresponding to the elements in
Domain just as all of the above parameters do. You can add a color by
clicking the
+button, and delete a color by selecting it and pressing theDeletekey.
(Note that as an advanced convenience feature, useful mainly when Domain has many elements, you may specify fewer entries in any of the above lists than there are elements in Domain, and the last one will be re-used as many times as necessary. Using this feature will display a warning, in case you inadvertently left out a value.)
- Background color: The color of the visualizer canvas.
- Draw path...: What portion of the path to show on each frame. If the default option "Incrementally" is selected, the display begins with an empty path, and the length of the path shown is increased by a fixed amount on each frame. If "All at once" is selected, the entire path is (re)drawn on every frame (so if there are no stretching or folding rates, the image is static).
- Steps per frame: a positive whole number. If the "Draw path..." parameter is set to "Incrementally," this parameter specifies how many steps longer the path should be each time it is drawn. The path will continue to lengthen as long as there are additional entries of the sequence to display. To avoid display lag, the steps per frame are limited to 1000.
- Rule mode: You may select "List" or "Formula". Generally speaking, the parameters above are used to control the Turtle visualization when this Rule mode parameter has its default value of "List". The parameters below are used when the Rule mode is "Formula". (Note that Background color and Turtle speed are used in either case.) Broadly, in Formula mode, you can enter expressions that calculate the different aspects of each segment of the turtle's path (angle, step length, color, etc.) directly from the sequence entries. In each of these formulas, you may use the following variables, the values of which will be filled in for you:
n The index of the entry in the sequence being visualized.
a The value of the entry.
k The serial number of the step starting from one for the first step
that the turtle takes.
m The minimum index of the sequence being visualized. Note that the
above definitions mean that n, k, and m are related by n = m + k - 1.
M The Maximum index of the sequence being visualized. Note this value
may be Infinity for sequences that are defined and can be calculated in
principle for any index.
f The frame number of this drawing pass. If you use this variable, the
visualization will be redrawn from the beginning on every frame,
altering the shape of the path accordingly.
b The current bearing of the turtle, in degrees counterclockwise from its
initial bearing. Note this value represents the bearing before the
new one when the angle formula is being computed, and the resulting new
bearing when all of the other formulas are being computed. For example,
if you compute the color of the stroke using the b variable, it will
correctly base the color on the bearing of that stroke (not on the previous
one).
x The current x-coordinate of the turtle (before the upcoming step).
y The current y-coordinate of the turtle.
You may also use the symbol A as a function symbol in your formula, and it
will provide access to the value of the sequence being visualized for any
index. For example, the formula A(n+1) - A(n) or equivalently A(n+1) - a
would produce the so-called "first differences" of the sequence.
Note that as you change parameters in List mode, the formulas will be updated in the background to match for you, but not vice versa: If you switch to List mode, the visualization will change to reflect the last List mode values you set. That's because most changes you might make in Formula mode can't possibly be captured in the simpler List mode. Hence, the Turtle visualizer simply doesn't try to keep the List values in sync with Formula changes.
- Angle formula: an expression to compute the angle for a given step of the turtle's path. Just as in list mode, the Angle is... parameter above specifies whether the value of this expression is taken directly as the new Bearing of the turtle, or whether the turtle makes a (counterclockwise) Turn by this angle before taking its next step.
- Angle measure: whether the result of the Angle formula should be
interpreted in degrees or radians. Note that the selection also gives the
units in which the value of the
b(bearing) variable that can be used in formulas will be determined. - Step formula: an expression to compute the pixel length of each step of the turtle's path.
- Width formula: an expression to compute the pixel width of each step of the turtle's path.
- Color formula: an expression to compute the color of each step of the turtle's path.
- Color chooser: This color picker does not directly control the display. Instead, whenever you select a color with it, the corresponding color string is inserted in the Color formula box.
- Viewpoint: The coordinates of the point that will initially be centered in the display.
- Viewscale: The initial scaling factor of the display.
