Polar Rose in Julia

Background

I’m doing exercise 4.9 of Think Julia, which asks for a function for a polar rose using Luxor’s turtle graphics.

Difficulties

  1. 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 and k.
    • n: number of petals
    • k: petal increment
    • constraint: k ≠ n ÷ 2
  2. Handle the case when gcd(n, k) > 1, i.e. more than one closed loop.
  3. The positive x direction goes to the right; the positive y direction goes down.

Attempt

  1. Use ThinkJulia.Reposition(t::Turtle, x, y) to reposition the turtle.
  2. Use turn(t::Turtle, θ) to turn t
  3. Use ThinkJulia.Orientation(t::Turtle, θ) to restore the turtle’s orientation after the move.

Code

I spend three days writing and testing this function.

[Read More]