Added set-nib! for variable width lines.

This commit is contained in:
Simon Brooke 2025-08-30 18:48:42 +01:00
parent 1b5aeeb52e
commit 8edc8fe180
3 changed files with 28 additions and 11 deletions

View file

@ -1,6 +1,6 @@
(ns tittle)
(def turtle (atom {:theta 0 :x 0 :y 0 :pen :up :ink "blue"}))
(def turtle (atom {:theta 0 :x 0 :y 0 :pen :up :nib 3 :ink "blue"}))
(defn log-turtle!
"Prints the state of the turtle to the browser console."
@ -105,6 +105,7 @@
(.setAttribute elt "x2" x)
(.setAttribute elt "y2" y)
(.setAttribute elt "stroke" (or (:ink @turtle) "blue"))
(.setAttribute elt "stroke-width" (or (:nib @turtle) 3))
(.appendChild playing-field elt)))
(swap! turtle assoc :x x :y y))))
@ -151,6 +152,12 @@
(when (string? colour)
(swap! turtle assoc :ink colour)))
(defn set-nib!
"Set the nib (width) of the pen to this `n`, which should be a number."
[n]
(when (number-or-error! n)
(swap! turtle assoc :nib n)))
(defn draw-tree!
"Draw a tree. This is a fairly crude tree-drawing algorithm;
there's lots of ways it can be improved, consider it a place