- Work out the geometric structure of the family of polar roses. The key is
to construct some auxiliary isoceles triangles and work out the angles between
them. One sees that they are parametrized by two varaibles
n: number of petals
k: petal increment
k ≠ n ÷ 2
- Handle the case when
gcd(n, k) > 1, i.e. more than one closed loop.
- The positive
xdirection goes to the right; the positive
ydirection goes down.
ThinkJulia.Reposition(t::Turtle, x, y)to reposition the turtle.
turn(t::Turtle, θ)to turn
ThinkJulia.Orientation(t::Turtle, θ)to restore the turtle’s orientation after the move.
I spend three days writing and testing this function.
To test this function, one can issue a few lines.
include("polar_rose.jl"); 🐢 = Turtle(); @svg begin polar_rose(🐢, 8, 3, 100) end
The book’s solution is much simpler than mine. I’ve overthought this problem by
thinking about the “petal increment”, concentric petal curves and closed loops.
The author simply draws one single petal with an auxiliary function
petal (t::Turtle, r, angle), which is a simple
function petal(t, r, angle) for i in 1:2 arc(t, r, angle) turn(t, angle-180) end end
The logic behind this loop is that
arc(t::Turtle, r, angle) turns
-angle degrees due to the line
turn(t, -angle) in the
polyline(t::Turtle, n, len, angle) called by
arc(t, r, angle).
function polyline(t, n, len, angle) for i in 1:n forward(t, len) turn(t, -angle) end end
N.B.: Since the
y-axis is inverted in Luxor, so as the sign of an angle.