42 lines
937 B
Plaintext
42 lines
937 B
Plaintext
& Lesson 12: c_ngon
|
|
& Clayson walks you through this step by step
|
|
& It's just high school trigonometry
|
|
& But that probably strikes terror into the hearts of PhD students in the humanities
|
|
& So I've adapted his solution.
|
|
& He walks you carefully through it on pp. 24-31.
|
|
|
|
fn ngon! (sides, size) -> repeat sides {
|
|
fd! (size)
|
|
rt! (inv (sides))
|
|
}
|
|
|
|
fn c_ngon! (sides, radius) -> {
|
|
& first, some fancy trigonometry
|
|
& don't read this if you don't want to
|
|
& but: there are two hard problems here
|
|
& how far to turn before drawing the ngon
|
|
& and how long each side should be to fit inside the radius
|
|
let entry_turn = sub (
|
|
0.5
|
|
mult (
|
|
0.25
|
|
sub (sides, 2)
|
|
inv (sides)))
|
|
|
|
let side_length = mult (
|
|
2
|
|
radius
|
|
sin (div (0.5, sides)))
|
|
|
|
& now that we have the math: what do we need the turtle to do
|
|
pu! ()
|
|
fd! (radius)
|
|
pd! ()
|
|
rt! (entry_turn)
|
|
ngon! (sides, side_length)
|
|
lt! (entry_turn)
|
|
pu! ()
|
|
bk! (radius)
|
|
pd! ()
|
|
}
|