Compare commits

..

3 Commits

Author SHA1 Message Date
Scott Richmond
70e8b1ede8 comment repl cruft 2024-06-20 12:12:02 -04:00
Scott Richmond
98180507e4 show and hide turtle 2024-06-20 12:10:07 -04:00
Scott Richmond
b9e721e4e2 don't draw line on turtle if pen is up 2024-06-20 12:04:45 -04:00
2 changed files with 22 additions and 3 deletions

View File

@ -1111,7 +1111,8 @@ fn render_turtle! () -> {
add_call! ((:fill, r, g, b, a)) add_call! ((:fill, r, g, b, a))
let #{heading let #{heading
:pencolor (pen_r, pen_g, pen_b, pen_a) :pencolor (pen_r, pen_g, pen_b, pen_a)
:position (x, y) :position (x, y)
pendown?
...} = state ...} = state
let first = mult ((0, 1), turtle_radius) let first = mult ((0, 1), turtle_radius)
let (x1, y1) = first let (x1, y1) = first
@ -1128,7 +1129,7 @@ fn render_turtle! () -> {
add_call! ((:endShape)) add_call! ((:endShape))
& there's a happy bug here: the stroke will be the same width as the pen width. Keep this for now. Consider also showing the pen colour here? & there's a happy bug here: the stroke will be the same width as the pen width. Keep this for now. Consider also showing the pen colour here?
add_call! ((:stroke, pen_r, pen_g, pen_b, pen_a)) add_call! ((:stroke, pen_r, pen_g, pen_b, pen_a))
add_call! ((:line, 0, 0, x1, y1)) if pendown? then add_call! ((:line, 0, 0, x1, y1)) else nil
add_call! ((:pop)) add_call! ((:pop))
:ok :ok
} }
@ -1251,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) -> {
@ -1287,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)
} }
} }
@ -1395,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
@ -1464,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

@ -52,7 +52,11 @@
(comment (comment
# (do # (do
(def source ` (def source `
butlast ([1, 2, 3]) hideturtle! ()
showturtle! ()
penup! ()
pendown! ()
pencolor! (colors :red)
`) `)
(def out (-> source (def out (-> source
ludus ludus