I posted a while back about the wonders of Fourier Curves, and I’ve posted many times about Euler’s Formula and other graphical wonders of the complex plane. Recently, a **Numberphile** video introduced me to another graphical wonder: **Euler Spirals**. They’re one of those very simple ideas that results in almost infinite variety (because of chaos).

As it turned out, the video (videos, actually) led to a number of fun diversions that have kept me occupied recently. (Numberphile has inspired more than a few projects over the years. Cool ideas I just had to try for myself.)

This all has to do with virtual turtles.

Or more precisely, ** turtle graphics** — a vector-based approach to computer-controlled drawing so simple that it’s taught to kids. Turtle graphics is the central feature of the widely implemented

**Logo**language, and it’s a direct analogue to how pen plotters (and some machine tools) work.

Basically, one moves around a virtual “turtle” using simple commands: *forward 10 units* or *turn left 45 degrees*. The turtle has a “pen”, which can be “up” or “down”, and which can be any width or color desired. Obviously, if the pen is down, the turtle draws a line as it moves along.

The instruction set is usually quite simple. One can move (forward, always forward) some distance (or move *to* some specific location), turn left or right by some angle (or to some specific heading), or manipulate the pen. That’s about it. It’s a little like an Etch-A-Sketch, but better (you can make it stop drawing, for one thing).

As an aside, in some systems, such as pen plotters or machine tools, the turtle is physical and has a function (drawing, cutting, or machining). The turtle can even be a robot moving around the floor.

**§**

The notion behind Euler spirals is simple: Each step, move forward some fixed distance and then turn an angle that increases by a fixed amount each step. For example, if we increase by **1°** each step, the turn angles increase like 1°, 2°, 3°, 4°… for as long as we go.

When we take *a lot* of steps, interesting patterns develop:

The pattern is highly dependent on the angle increase selected. (The distance we go each step is irrelevant. It only affects the total image size.) A small angle makes small-scale curves smoother, but even large angles lead to curved large-scale structures. I’ve gotten good results with angles around one degree.

But not *exactly* one degree (or two or one-half or any other “ordinary” angle). Integer angles and regular fractions of angles (such as 1/2) result in symmetrical patterns. In some cases, in very *simple* symmetrical patterns.

As one might figure, the pattern *forward*, *turn*, *repeat*, generates a spiral. What might be a surprise is that, if we keep going, we end up walking *out* of the spiral. What happens next depends on the angle. Some angles create apparently chaotic spirals, some create symmetrical patterns. In the latter, after some (possibly large) number of steps, the pattern stops growing and repeats. Certain “resonant” angles create symmetrical patterns with just two spirals:

This is what we get with an angle of exactly **1.0°** (or any other angle that evenly divides 360°). Less regular angles result in more interesting pictures. For instance, *Euler Spiral #1* above, increases the angle by **1.23456°** every step. That turns out to be a symmetrical pattern. The turtle retraces the same 370,000 steps (or so) over and over.

Incidentally, the red line in these images connects the start point (blue dot) and end point (red dot). I found it useful to know where the plot begins and ends. In the more symmetrical cases, only the red dot shows because I ended the plot with the turtle at the symmetry center point, which is also the start point.

Here’s another symmetrical pattern:

It’s a bit different from *Euler Spiral #1* but is based on nearly the same angle, **1.2345°** — the difference is a dropped final digit in the angle.

[If you know the story about how Lorentz dropped the final digits of some weather data that he input for a computer program and, as a result, stumbled on chaos theory as we know it, these images illustrate that nicely.]

Here’s one more related image:

In this case I *added* a digit to the angle, but all three images use the same basic angle of **1.2345°** — it’s only an extra digit or two difference between them (think of it as **1.234500°** and **1.234560°** and **1.234567°**).

**§**

Some patterns are symmetrical, but others are not (or, if they are, they need many millions or billions of steps to show it). Some patterns seem to “walk” off into infinity like repeating wallpaper (and have a symmetry only in how the “gait” repeats).

Here’s an example of one that seems asymmetrical (at least after 10,000 steps):

Notice that the pattern does have some symmetry about the center, but as it continues, it wanders off. After 100,000 it’s wandered into a what looks like a giant spiral made of little spirals:

After 1,000,000 steps the giant spiral pattern is apparent (and without any obvious symmetry other than the regularity of groups of little spirals — the “gait” of the large path):

The giant spiral pattern is emerging after 10,000,000 steps (and still no obvious symmetry):

But who knows what happens if we keep going? It’s something of a black swan situation. More precisely, it’s another example of the Turing Halting Problem. There’s no way to be sure what happens if we keep going.

**§**

The simple process of repeatedly moving forward and turning by an increasing angle is subject to chaos. Tiny variations in the input settings (in this case, the increment angle) result in radically different output results.

We can develop some sense of what’s going on by looking at some examples with large increment angles. *Figure 1* shows the “spiral” generated by increasing the angle by **45°** each step.

The large angle makes the spiral very jagged and basic, but it also lets us see clearly how the increasing angle leads the path back out.

Start at the center (red dot), go east (right), and turn left 45°. Now go north-east and turn left 90°. Now north-west and turn left 135° (we’re at the top facing south now). The next step takes us south and we turn 180° — which faces us right back north. Step north and turn left 225° — which is the same as turn right 135° (so we’re facing south-east now). Three more steps, with effective turn angles of right 90° (left 270°), right 45° (left 315°), and 0° (left 360°), bring us back to the center facing west to create the lower spiral.

When the angle divides 360 evenly, and here we have 360/45=8, we get the dual-spiral. That division also tells us it takes eight steps to draw a spiral — to walk in and walk back out. (In a sense, the spirals are twisted circles.) Obviously, it takes twice that, 16 steps, to draw both spirals.

*Figure 2* shows another large angle that’s only slightly smaller: **30°** (and since 360/30=12, it takes 24 steps to draw the full dual-spiral pattern).

The spiral is still very jagged and barely recognizable as a spiral, but the simplicity of the pattern makes it easy to trace each step.

Note that the increasing left angle gets as large as 180° and effectively starts getting smaller again because a left turn greater than 180° is a right turn less than 180°.

And because circles only have 360°, turns larger than 360° “wrap around” the same way clock hands do, so the actual turn angle just varies constantly between 0° and 180°.

*Figure 3* shows what’s still a large angle: **15°** (and 360/15=24, so the full pattern has 48 steps).

The spirals are starting to look more like spirals, but it’s getting harder to track the 24 steps that comprise one.

A crucial point is that the even division of 360 means we always hit a point where the turn is exactly 180°, which reverses our direction, and we walk out along the same path as we walked in on. That lets us return to our starting point.

With the more complicated symmetrical patterns above, the path wanders a lot before it hits a turn that reverses it. That doesn’t always happen, at least not in any reasonable number of steps. Some patterns seem asymmetrical and chaotic, and some appear to wander off into infinity. (It’s possible that they show symmetry if they go on long enough.)

*Figure 4* makes one last jump and shows a **5°** angle (another even division with 144 steps to draw the whole pattern).

Decent spirals now but forget about trying to track the 72 steps it takes to make a spiral.

The chaotic element lies in how the path out of the spiral usually isn’t the same path as going in. That means the path goes in a new direction rather than return to start.

Small angles mean lots of steps to draw the spiral. That makes the exit path unpredictable, which leads to the diverse patterns.

By the way: Don’t assume that large angles, because they make such jagged spirals, can’t make interesting patterns if they go on for a while. They can and do:

The large-scale structure hides the small-scale jaggedness!

**§ §**

Euler spirals offer a simple illustration of chaos based on a simple Logo program:

for step from 1 to MaxSteps: turtle.forward(Distance) turtle.left(Angle*step)

As with the Mandelbrot, a simple, *but chaotic*, process iterated many times leads to unpredictable results that are hugely input-dependent.

This isn’t the only fun to be had with virtual turtles, though. The Numberphile video demonstrated one I had to try: *using the decimal digits of pi to steer the turtle*.

We’ll let each *digit* (**0** to **9**) represent an angle: **360/10 * digit** (so we have

**0**=0°,

**1**=36°,

**2**=72°,

**3**=108°,

**4**=144°,

**5**=180°,

**6**=216°,

**7**=252°,

**8**=288°,

**9**=324°). The process is: Get a digit, turn to that heading, and move (some fixed distance) in that direction. Repeat for as many digits as desired.

**§**

Here’s the picture we get from the first **10** (decimal) digits:

From the starting point (blue dot), **1**=36°, **4**=144°, **1**=36°, **5**=180°, etc. An interesting aspect of this is the constraint that we can only move in one of ten directions, although it doesn’t constrain the path as much as one might think.

Here’s what **100** digits of *pi* looks like (rendered per the above protocol):

*Pi* is thought to be a *normal* number, meaning its digits are evenly distributed. That should keep the turtle relatively close to home. From the above we can see that appears to be the case.

Now we jump another order of magnitude to **1,000** digits:

The pattern is getting interesting, but there does seem something of a bias in movement. Everything seems north and somewhat east of the starting point.

Another order of magnitude brings us to **10,000** digits:

We’re losing the fine detail now, but the picture is certainly interesting. The east bias has been replaced by a stronger west bias, and there is now a fair bit of travel south of the starting point.

Next magnitude jump takes us to **100,000** digits:

What I like about this one is how, after 100,000 digits, the end point has returned to the vicinity of the starting point.

The penultimate image involves **1,000,000** digits:

Now the end point is pretty far away from the starting point!

Each of these images has ten times as many steps, so they have ten times as much area covered. Note what small patches the previous images are of the following ones.

Lastly, ten-million digits of *pi* (all that I have):

Again, remember that this is ten times the area of the previous image! *Pi Paths #6* is a tiny portion of this one.

Now the end point (red dot upper left) is quite some distance from the start point (blue dot center) and there does seem more activity west than east. On the other hand, the start point is roughly centered, so the *limits* of turtle travel seem about equal.

**§**

I’ll leave you with another video:

It starts by drawing each step. After 600 steps it pauses then moves in increments of 10 steps each frame. After 600 steps, it pauses again and then moves in increments of 100 steps. Each pause increases the number of steps per frame by an order of magnitude. By the end, it’s moving at the rate of 5,000 steps each frame.

**§ §**

There is more fun to be had with random walks, fixed angles, and colors, but those will all have to wait for another post. That’s all for this time.

Stay moving and turning, my friends! Go forth and spread beauty and light.

∇

April 27th, 2022 at 7:14 am

Here’s the Numberphile video about Euler Spirals:

April 27th, 2022 at 7:15 am

Here’s the Numberphile video about plotting the digits of pi:

April 27th, 2022 at 7:40 am

This post is where math, science, art and reality can all come together in one pixel.

April 27th, 2022 at 7:48 am

Yes, very true! And I love it when that happens. It’s why I’ve always loved the Mandelbrot images and zoom videos.

May 1st, 2022 at 12:45 pm

Huh.

May 19th, 2022 at 12:09 pm

Not a blue funk, let alone a black funk, but a white noise funk. Static in both senses.

July 14th, 2022 at 3:26 am

Turtle graphics, take two,…

July 16th, 2022 at 12:33 pm

Here’s a much-improved version of the

Paths of Pi:(I’m getting better at making these little movies!)