show and hide turtle

This commit is contained in:
Scott Richmond 2024-06-20 12:10:07 -04:00
parent b9e721e4e2
commit 98180507e4
2 changed files with 18 additions and 3 deletions

View File

@ -1252,6 +1252,16 @@ fn setheading! {
(heading as :number) -> add_command! ((:setheading, heading))
}
fn showturtle! {
"If the turtle is hidden, shows the turtle. If the turtle is already visible, does nothing."
() -> add_command! ((:show))
}
fn hideturtle! {
"If the turtle is visible, hides it. If the turtle is already hidden, does nothing."
() -> add_command! ((:hide))
}
fn heading/vector {
"Takes a turtle heading, and returns a unit vector of that heading."
(heading) -> {
@ -1288,6 +1298,8 @@ fn apply_command {
(:penwidth, pixels) -> assoc (state, :penwidth, pixels)
(:pencolor, color) -> assoc (state, :pencolor, color)
(:setheading, heading) -> assoc (state, :heading, heading)
(:show) -> assoc (state, :visible?, true)
(:hide) -> assoc (state, :visible?, false)
}
}
@ -1396,6 +1408,7 @@ pkg Prelude {
gte? & math
heading & turtles
heading/vector & math
hideturtle! & turtles
home! & turtles
inc & math
inv & math
@ -1465,6 +1478,7 @@ pkg Prelude {
set? & sets
setheading! & turtles
show & strings
showturtle! & turtles
sin & math
slice & lists tuples strings
some & values

View File

@ -49,10 +49,11 @@
(set (out :draw) (post :draw))
(-> out j/encode string))
(comment
# (do
# (comment
(do
(def source `
butlast ([1, 2, 3])
hideturtle! ()
showturtle! ()
`)
(def out (-> source
ludus