Skip to content

Instantly share code, notes, and snippets.

@Sose

Sose/turtle.cljs Secret

Created May 19, 2021 18:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sose/b07f44536f3e97fd1307b1edfa8b5840 to your computer and use it in GitHub Desktop.
Save Sose/b07f44536f3e97fd1307b1edfa8b5840 to your computer and use it in GitHub Desktop.
(defn turtle-repeat! [[times {:keys [:instructions :index]}]]
(doseq [x (range times)]
(do-script! instructions (count instructions))))
(defn do-script! [script until-step]
(doseq [step-n (range until-step)]
(let [[instr & data] (nth script step-n)]
(case instr
:move (move-turtle! (first data) step-n)
:turn-right (turn-right! (first data))
:turn-left (turn-left! (first data))
:repeat (turtle-repeat! data)
:pen nil)))) ;; pen instructions are handled by (pen-down? step-n)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment