visual-modeling/ch_2_code.ld

177 lines
4.6 KiB
Plaintext
Raw Permalink Normal View History

2025-01-04 04:14:50 +00:00
&&&&& Code examples from Chapter 2
&&& Common "library" functions
fn ngon!
fn cngon!
fn arrow!
fn flash!
&&& FIGURE 16
fn pipegon! (pipe_rad
roll_rad
& flash_len
theta
total_angle
n) -> {
if lt? (n, 1) then cngon! (90, pipe_rad)
else {
penup! ()
forward! (add (pipe_rad, roll_rad))
pendown! ()
left! (mult (total_angle, div (pipe_rad, roll_rad)))
& flash! (flash_len)
& cngon! (2, roll_rad)
arrow! (mult (-1.5, roll_rad))
cngon! (90, roll_rad)
rt! (mult (total_angle, div (pipe_rad, roll_rad)))
penup! ()
back! (add (pipe_rad, roll_rad))
left! (theta)
pipegon! (pipe_rad
roll_rad
& flash_len
theta
add (total_angle
theta)
dec (n))
}
}
pipegon! (60, -30, inv (6), 0, 6)
&&& FIGURE 17
fn pipegon! (pipe_rad
roll_rad
& flash_len
theta
total_angle
n) -> {
if lt? (n, 1) then cngon! (90, pipe_rad)
else {
penup! ()
forward! (add (pipe_rad, roll_rad))
pendown! ()
left! (mult (total_angle, div (pipe_rad, roll_rad)))
& flash! (flash_len)
& cngon! (2, roll_rad)
arrow! (mult (-1.5, roll_rad))
& cngon! (90, roll_rad)
rt! (mult (total_angle, div (pipe_rad, roll_rad)))
penup! ()
back! (add (pipe_rad, roll_rad))
left! (theta)
pipegon! (pipe_rad
roll_rad
& flash_len
theta
add (total_angle
theta)
dec (n))
}
}
pipegon! (60, -30, inv (180), 0, 180)
&&& FIGURE 18
fn pipegon! (pipe_rad
roll_rad
& flash_len
theta
total_angle
n) -> {
if lt? (n, 1) then cngon! (90, pipe_rad)
else {
penup! ()
forward! (add (pipe_rad, roll_rad))
pendown! ()
left! (mult (total_angle, div (pipe_rad, roll_rad)))
& flash! (flash_len)
cngon! (2, roll_rad)
& arrow! (mult (-1.5, roll_rad))
& cngon! (90, roll_rad)
rt! (mult (total_angle, div (pipe_rad, roll_rad)))
penup! ()
back! (add (pipe_rad, roll_rad))
left! (theta)
pipegon! (pipe_rad
roll_rad
& flash_len
theta
add (total_angle
theta)
dec (n))
}
}
pipegon! (60, -30, inv (180), 0, 180)
&&& FIGURE 19
fn pipegon! (pipe_rad
roll_rad
flash_len
theta
total_angle
n) -> {
if lt? (n, 1) then cngon! (90, pipe_rad)
else {
penup! ()
forward! (add (pipe_rad, roll_rad))
pendown! ()
left! (mult (total_angle, div (pipe_rad, roll_rad)))
flash! (flash_len)
& cngon! (2, roll_rad)
& arrow! (mult (-1.5, roll_rad))
& cngon! (90, roll_rad)
rt! (mult (total_angle, div (pipe_rad, roll_rad)))
penup! ()
back! (add (pipe_rad, roll_rad))
left! (theta)
pipegon! (pipe_rad
roll_rad
flash_len
theta
add (total_angle
theta)
dec (n))
}
}
pipegon! (60, -30, 40, inv (180), 0, 180)
&&& FIGURE 20
& The mathematics of spirographs
& The "degree of symmetrey" is the denominator of the
& most reduced fraction of the ratio of the two circle dimensions
& And, drawing something internally (as opposed to externally)
& the star doubles its number of points.
& To draw a 40-pointed star (which is what is in _VMwL), you need
& a fraction with a prime number in the numerator and 20 in the
& denominator.
& The other determinant of what the pipegon spirograph looks like
& is the frequency with which you draw your "stripe"
& I believe the diagrams in the book use 72 iterations/rotation,
& for 5º per iteration. That's what's below, but there are many
& I prefer. 45 iterations gives a lovely pentagon in the middle, 100
& iteration is lovely.
& the iteration of these below is s_pipegon!
pipegon! (400, -140, inv (72), 0, mult (1, 72))
pipegon! (400, -140, inv (72), 0, mult (2, 72))
pipegon! (400, -140, inv (72), 0, mult (3, 72))
pipegon! (400, -140, inv (72), 0, mult (4, 72))
pipegon! (400, -140, inv (72), 0, mult (5, 72))
pipegon! (400, -140, inv (72), 0, mult (6, 72))
pipegon! (400, -140, inv (72), 0, mult (7, 72))
&&& FIGURE 21.1-4: larger roller than pipe, internally
& Again, all are s_pipegon!s
& 21.1
pipegon! (500, -600, inv (72), 0, mult (3, 72))
& 21.2
rt! (inv (18)); pipegon! (450, -500, inv (72), 0, mult (5, 72))
& 21.3
rt! (0.125); pipegon! (400, -600, inv (72), 0, mult (3, 72))
& 21.4
pipegon! (200, -600, inv (72), 0, mult (3, 72))