Skip to content

Commit

Permalink
hilbert turtle
Browse files Browse the repository at this point in the history
  • Loading branch information
cormullion committed Jan 17, 2019
1 parent 463eb17 commit 1a07696
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 3 deletions.
4 changes: 3 additions & 1 deletion docs/src/animation.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ Sometimes you want to construct an animation that has different components, laye

As an example, consider a simple example showing the sun for each hour of a 24 hour day.

sun24demo = Movie(400, 400, "sun24", 0:23)
```
sun24demo = Movie(400, 400, "sun24", 0:23)
```

The `backgroundfunction()` draws a background that's used for all frames (animated GIFs like constant backgrounds):

Expand Down
2 changes: 1 addition & 1 deletion docs/src/transforms.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ nothing # hide
![scale](assets/figures/scale.png)


`rotate()` rotates the current workspace by the specifed amount about the current 0/0 point. It's relative to the previous rotation, not to the document's original.
`rotate()` rotates the current workspace by the specified amount about the current 0/0 point. It's relative to the previous rotation, not to the document's original.

```@example
using Luxor, Random # hide
Expand Down
44 changes: 44 additions & 0 deletions docs/src/turtle.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,50 @@ nothing # hide

![many turtles](assets/figures/manyturtles.svg)

A turtle graphics approach lends itself well to recursive programming. This short recursive function draws a Hilbert curve.

```@example
using Luxor, Colors # hide
Drawing(400, 400, "assets/figures/hilbertturtle.svg") # hide
origin() # hide
background("black") # hide
function hilbert(t::Turtle, level, angle, lengthstep)
level == 0 && return
HueShift(t, 0.1)
Turn(t, angle)
hilbert(t, level-1, -angle, lengthstep)
Forward(t, lengthstep)
Turn(t, -angle)
hilbert(t, level-1, angle, lengthstep)
Forward(t, lengthstep)
hilbert(t, level-1, angle, lengthstep)
Turn(t, -angle)
Forward(t, lengthstep)
hilbert(t, level-1, -angle, lengthstep)
Turn(t, angle)
end
setline(2)
setlinecap("round")
hilbert(Turtle(first(BoundingBox()) + (12, 12), true, 0, (1, 0, 0)),
6, # level
90, # turn angle, in degrees
6 # steplength
)
finish() # hide
nothing # hide
```

![hilbert turtle](assets/figures/hilbertturtle.svg)

```@docs
Turtle
Forward
Expand Down
3 changes: 2 additions & 1 deletion src/Turtle.jl
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@ end
HueShift(t::Turtle, inc=1.0)
Shift the Hue of the turtle's pen forward by `inc`. Hue values range between
0 and 360.
0 and 360. (Don't start with black, otherwise the saturation and brightness values
will be black.)
"""
function HueShift(t::Turtle, inc=1.0)
r, g, b = t.pencolor
Expand Down

0 comments on commit 1a07696

Please sign in to comment.