Last active
December 15, 2015 08:18
-
-
Save rm-hull/5229369 to your computer and use it in GitHub Desktop.
Demo clojurescript gist to test out http://programming-enchiladas.destructuring-bind.org/ -- draws a simple pentagon and other geometric stars using turtle graphics
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; 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)] | |
(take | |
(* steps (count basic-op)) | |
(cycle basic-op)))) | |
(def commands | |
(list | |
: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