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

@ -1112,6 +1112,7 @@ fn render_turtle! () -> {
let #{heading
:pencolor (pen_r, pen_g, pen_b, pen_a)
:position (x, y)
pendown?
...} = state
let first = mult ((0, 1), turtle_radius)
let (x1, y1) = first
@ -1128,7 +1129,7 @@ fn render_turtle! () -> {
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?
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))
:ok
}
@ -1251,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) -> {
@ -1287,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)
}
}
@ -1395,6 +1408,7 @@ pkg Prelude {
gte? & math
heading & turtles
heading/vector & math
hideturtle! & turtles
home! & turtles
inc & math
inv & math
@ -1464,6 +1478,7 @@ pkg Prelude {
set? & sets
setheading! & turtles
show & strings
showturtle! & turtles
sin & math
slice & lists tuples strings
some & values

View File

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