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)) (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 { fn heading/vector {
"Takes a turtle heading, and returns a unit vector of that heading." "Takes a turtle heading, and returns a unit vector of that heading."
(heading) -> { (heading) -> {
@ -1288,6 +1298,8 @@ fn apply_command {
(:penwidth, pixels) -> assoc (state, :penwidth, pixels) (:penwidth, pixels) -> assoc (state, :penwidth, pixels)
(:pencolor, color) -> assoc (state, :pencolor, color) (:pencolor, color) -> assoc (state, :pencolor, color)
(:setheading, heading) -> assoc (state, :heading, heading) (:setheading, heading) -> assoc (state, :heading, heading)
(:show) -> assoc (state, :visible?, true)
(:hide) -> assoc (state, :visible?, false)
} }
} }
@ -1396,6 +1408,7 @@ pkg Prelude {
gte? & math gte? & math
heading & turtles heading & turtles
heading/vector & math heading/vector & math
hideturtle! & turtles
home! & turtles home! & turtles
inc & math inc & math
inv & math inv & math
@ -1465,6 +1478,7 @@ pkg Prelude {
set? & sets set? & sets
setheading! & turtles setheading! & turtles
show & strings show & strings
showturtle! & turtles
sin & math sin & math
slice & lists tuples strings slice & lists tuples strings
some & values some & values

View File

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