Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
I found myself in a popular electronics emporium recently; I was transfixed by the on-screen advertisements of a certain manufacturer, which seemed to encourage consumer conformity and consistency - and felt driven to reproduce it's iconography crudely here. See
(ns enchilada.aspirational-vanity-product
[enchilada :refer [ctx canvas]]
[big-bang.core :refer [big-bang]]
[jayq.core :refer [show attr css]]
[monet.canvas :refer [begin-path move-to line-to clear-rect
stroke stroke-style stroke-width stroke-cap
save restore translate rotate]]))
(def two-pi (* 2 Math/PI))
(def increment (/ two-pi 360))
(def one-third (/ two-pi 3))
(def initial-state {:angle 0})
(defn update-state [event world-state]
(update-in world-state [:angle] (partial + increment))) ; 1 degree
(defn draw-shape [ctx]
(dotimes [i 3]
(move-to 0 5)
(line-to 0 95)
(rotate one-third)))
(defn draw-array [ctx x y n dir angle]
(dotimes [i n]
(translate (+ x (* i 200)) y)
(rotate (* dir angle))
(defn render [{:keys [angle] :as world-state}]
(clear-rect {:x 0 :y 0 :w 800 :h 600})
(stroke-style :#444)
(stroke-cap :round)
(stroke-width 5)
(draw-array 74 -64 5 -1 angle)
(draw-array -25 110 5 +1 angle)
(draw-array 75 282 5 -1 angle)
(draw-array -25 454 5 +1 angle)
(draw-array 74 626 5 -1 angle)
(show canvas)
:tick-rate 60
:initial-state initial-state
:on-tick update-state
:to-draw render)
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.