Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Turtle Demo
;; Draws a simple pentagon and other geometric stars using turtle graphics
;; Scale it to fit in a bounding-box of 750x550 px
(ns turtle.demo
(:use [turtle.core :only [draw!]]
[turtle.renderer.canvas :only [->canvas]]
[jayq.core :only [show]]
[enchilada :only [ctx canvas]]))
(defn move-to [x y]
(list :origin, :pen :up, :fwd y, :right 90, :fwd x, :pen :down))
(defn polygon [turn-angle line-length steps]
(let [basic-op (list :fwd line-length, :right turn-angle)]
(* steps (count basic-op))
(cycle basic-op))))
(def commands
:color :blue
(move-to 50 50)
(polygon 144 100 5)
:color :red
(move-to 200 100)
(polygon 72 70 5)
:fill :yellow
:color :green
(move-to 200 200)
(polygon 135 100 8)))
(show canvas)
(print (flatten commands))
(draw! (->canvas ctx) commands [750 550])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.