updated 10 print example from fall class

This commit is contained in:
Matt Nish-Lapidus 2024-11-15 15:20:10 -05:00
parent 88d9e3b2e3
commit fc4b8dae8b

View File

@ -1,64 +1,49 @@
penup! ()
goto! (150, 150) & should be (-150, -150)
right! (0.25)
let cell_size = 10
let slash_length = mult(cell_size, sqrt(2))
let cols = 20
let rows = 4
let root_2 = 1.414213562
let cell_size = 15
let line_length = mult (root_2, cell_size)
fn upstroke! () -> {
print! (:up)
penup! ()
forward! (cell_size)
left! (0.125)
pendown! ()
back! (line_length)
penup! ()
forward! (line_length)
right! (0.125)
penwidth!(3)
fn forward_slash! () -> {
pd!()
rt!(0.125)
fd!(slash_length)
pu!()
bk!(slash_length)
lt!(0.125)
}
fn downstroke! () -> {
print! (:down)
pendown! ()
right! (0.125)
forward! (line_length)
left! (0.375)
penup! ()
forward! (cell_size)
right! (0.25)
fn back_slash! () -> {
pu!()
fd!(cell_size)
pd!()
rt!(0.375)
fd!(slash_length)
pu!()
lt!(0.125)
bk!(cell_size)
lt!(0.25)
}
fn up_or_down! () -> {
let rand = random ()
if lt? (rand, 0.5)
then upstroke! ()
else downstroke! ()
fn next_cell! () -> {
pu!()
rt!(0.25)
fd!(cell_size)
lt!(0.25)
}
fn newline! () -> {
penup! ()
back! (mult (grid_size, cell_size))
right! (0.25)
forward! (cell_size)
left! (0.25)
repeat rows {
repeat cols {
if random([true, false])
then forward_slash!()
else back_slash!()
next_cell!()
}
let grid_size = 20
fn randcolor! () -> pencolor! ((random (0, 255), random (0, 255), random (0, 255)))
repeat grid_size {
randcolor! ()
up_or_down! ()
lt!(0.25)
fd!(mult(cols, cell_size))
rt!(0.25)
back!(cell_size)
}
& repeat grid_size {
& newline! ()
& }