diff --git a/prelude.ld b/prelude.ld index b5fa3c0..26f7304 100644 --- a/prelude.ld +++ b/prelude.ld @@ -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 diff --git a/src/ludus.janet b/src/ludus.janet index 6bc71ae..a19b305 100644 --- a/src/ludus.janet +++ b/src/ludus.janet @@ -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