Hi all,

is this component below an idiomatic approach to deal with canvas
animations in reagent? I tried googling, but couldn't *any* examples
(which I find hard to believe):

(defn test-canvas
  "Creates animated clock based on seconds only."
  []
  (reagent/create-class
   {:component-did-mount
    #(reagent/next-tick
      (let [ctx (.getContext (reagent/dom-node %) "2d")]
        (fn update []
          (set! (.-fillStyle ctx) "red")
          (set! (.-textAlign ctx) "center")
          (let [now (js/Date.)
                sec (mod (.getTime now) 60000)
                hpi (/ Math/PI -2)
                phi (+ hpi (* (/ sec 60000) Math/PI 2))]
            (doto ctx
              (.clearRect 0 0 200 200)
              (.beginPath)
              (.arc 100 100 60 hpi phi false)
              (.arc 100 100 90 phi hpi true)
              (.fill)
              (.fillText (int (/ sec 1000)) 100 105))
            (reagent/next-tick update)))))
    :display-name "foo"
    :reagent-render (fn [] [:canvas {:width 200 :height 200}])}))

Are there any better solutions?

K.
-- 
Karsten Schmidt
http://postspectacular.com | http://thi.ng | http://toxiclibs.org

-- 
Note that posts from new members are moderated - please be patient with your 
first post.
--- 
You received this message because you are subscribed to the Google Groups 
"ClojureScript" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/clojurescript.

Reply via email to