From 57be0a2f8858aa217f1b64c4c5847da8ba4814a3 Mon Sep 17 00:00:00 2001 From: Scott Richmond Date: Mon, 2 Dec 2024 13:25:59 -0500 Subject: [PATCH] add fig 13 --- ch_1_intro.md | 12 ++- fig_13.1.svg | 151 ++++++++++++++++++++++++++++++ fig_13.2.svg | 251 ++++++++++++++++++++++++++++++++++++++++++++++++++ fig_13.3.svg | 118 ++++++++++++++++++++++++ 4 files changed, 530 insertions(+), 2 deletions(-) create mode 100644 fig_13.1.svg create mode 100644 fig_13.2.svg create mode 100644 fig_13.3.svg diff --git a/ch_1_intro.md b/ch_1_intro.md index 958cca3..4b222cb 100644 --- a/ch_1_intro.md +++ b/ch_1_intro.md @@ -876,8 +876,10 @@ Here is the finished `cngon!`: ``` fn cngon! (n, radius) -> { - let angle = sub (inv (2), inv (n)) + let angle = add (inv (4), inv (mult (2, n))) + & ^... this is equation (5), above, solving for `d` let edge = mult (2, radius, sin (inv (mult (2, n)))) + & ^... this is equation (8), above, solving for `e` penup! () forward! (radius) @@ -918,7 +920,13 @@ Combine the ideas of `spingon!` with your newly constructed `cngon!`. Design a fancier `cngon!` that fills up a polygon with textures. Here are a few visual tips for Exercises 1.3 and 1.4: -{{Figure 13: `spincngon`s. Bottom of p. 32.}} +Nested squares. + +Twisty, nested nonagons. + +Twisty, nested triangles. + +##### Figure 13: `spincngon`s. #### Exercise 1.5 Design a Ludus function that puts polygons on the vertices of other polygons. diff --git a/fig_13.1.svg b/fig_13.1.svg new file mode 100644 index 0000000..9b33e85 --- /dev/null +++ b/fig_13.1.svg @@ -0,0 +1,151 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +fn ngon! (n, edge) -> { + repeat n { + forward! (edge) + right! (inv (n)) + } +} + +fn cngon! (n, radius) -> { + let angle = add (inv (4), inv (mult (2, n))) + let edge = mult (2, radius, sin (inv (mult (2, n)))) + + penup! () + forward! (radius) + right! (angle) + pendown! () + ngon! (n, edge) + left! (angle) + penup! () + back! (radius) + pendown! () +} + +fn twisty_nonagons! (times, iter, radius, growth) -> { + if gte? (iter, times) then :ok + else { + cngon! (9, radius) + right! (inv (times)) + twisty_nonagons! (times, inc (iter), add (radius, growth), growth) + } +} + +& twisty_nonagons! (10, 0, 100, 3) + +fn centre_squares! (times, radius, growth) -> { + if lt? (times, 1) then :ok + else { + cngon! (4, radius) + centre_squares! (dec (times), add (radius, growth), growth) + } +} + +right! (0.125) +centre_squares! (10, 100, 4) + +fn twisty_triangles! (times, radius, angle, growth) -> { + if lt? (times, 1) then :ok + else { + cngon! (3, radius) + right! (angle) + twisty_triangles! (dec (times), sub (radius, growth), angle, growth) + } +} + +& right! (inv (6)) +& twisty_triangles! (8, 100, inv (120), 10) + +hideturtle! () + + + + diff --git a/fig_13.2.svg b/fig_13.2.svg new file mode 100644 index 0000000..9fa5886 --- /dev/null +++ b/fig_13.2.svg @@ -0,0 +1,251 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +fn ngon! (n, edge) -> { + repeat n { + forward! (edge) + right! (inv (n)) + } +} + +fn cngon! (n, radius) -> { + let angle = add (inv (4), inv (mult (2, n))) + let edge = mult (2, radius, sin (inv (mult (2, n)))) + + penup! () + forward! (radius) + right! (angle) + pendown! () + ngon! (n, edge) + left! (angle) + penup! () + back! (radius) + pendown! () +} + +fn twisty_nonagons! (times, iter, radius, growth) -> { + if gte? (iter, times) then :ok + else { + cngon! (9, radius) + right! (inv (times)) + twisty_nonagons! (times, inc (iter), add (radius, growth), growth) + } +} + +twisty_nonagons! (10, 0, 100, 3) + +fn centre_squares! (times, radius, growth) -> { + if lt? (times, 1) then :ok + else { + cngon! (4, radius) + centre_squares! (dec (times), add (radius, growth), growth) + } +} + +& right! (0.125) +& centre_squares! (10, 100, 4) + +fn twisty_triangles! (times, radius, angle, growth) -> { + if lt? (times, 1) then :ok + else { + cngon! (3, radius) + right! (angle) + twisty_triangles! (dec (times), sub (radius, growth), angle, growth) + } +} + +& right! (inv (6)) +& twisty_triangles! (8, 100, inv (120), 10) + +hideturtle! () + + + + diff --git a/fig_13.3.svg b/fig_13.3.svg new file mode 100644 index 0000000..1cbbadb --- /dev/null +++ b/fig_13.3.svg @@ -0,0 +1,118 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +fn ngon! (n, edge) -> { + repeat n { + forward! (edge) + right! (inv (n)) + } +} + +fn cngon! (n, radius) -> { + let angle = add (inv (4), inv (mult (2, n))) + let edge = mult (2, radius, sin (inv (mult (2, n)))) + + penup! () + forward! (radius) + right! (angle) + pendown! () + ngon! (n, edge) + left! (angle) + penup! () + back! (radius) + pendown! () +} + +fn twisty_nonagons! (times, iter, radius, growth) -> { + if gte? (iter, times) then :ok + else { + cngon! (9, radius) + right! (inv (times)) + twisty_nonagons! (times, inc (iter), add (radius, growth), growth) + } +} + +& twisty_nonagons! (10, 0, 100, 3) + +fn centre_squares! (times, radius, growth) -> { + if lt? (times, 1) then :ok + else { + cngon! (4, radius) + centre_squares! (dec (times), add (radius, growth), growth) + } +} + +& right! (0.125) +& centre_squares! (10, 100, 4) + +fn twisty_triangles! (times, radius, angle, growth) -> { + if lt? (times, 1) then :ok + else { + cngon! (3, radius) + right! (angle) + twisty_triangles! (dec (times), sub (radius, growth), angle, growth) + } +} + +right! (inv (6)) +twisty_triangles! (8, 100, inv (120), 10) +hideturtle! () + + + +