Skip to content

Instantly share code, notes, and snippets.

@johnjelinek
Forked from rm-hull/psychedelic-animation.cljs
Last active August 30, 2023 20:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnjelinek/74bc8cca8c46032e6656 to your computer and use it in GitHub Desktop.
Save johnjelinek/74bc8cca8c46032e6656 to your computer and use it in GitHub Desktop.
; rewritten in Clojurescript from javascript (originally by Piotr Stosur: http://js1k.com/2013-spring/demo/1431)
(ns psychedelic-animation.demo
(:use [enchilada :only [canvas svg ctx]]
[jayq.core :only [show hide]]
[monet.core :only [animation-frame]]
[monet.canvas :only [fill-style fill-rect draw-image rotate translate]]))
(show canvas)
(hide svg)
(defn draw-frame! [img v t]
(let [w (+ 400 (* (Math/sin t) 1))
r (Math/floor (* (Math/sin (* t 3)) 255))
g (Math/floor (* (Math/sin (* t 5)) 255))
b (Math/floor (* (Math/sin (* t 7)) 255))]
(->
ctx
(fill-style (str "rgba(" r "," g "," b ",0.1)"))
(fill-rect { :x 0 :y 0 :w w :h w })
(draw-image img { :x 0 :y 0 :w w :h w })
(rotate (* 0.01 (Math/abs (Math/sin t)))))))
(defn animate [img v]
(letfn [(loop [t]
(fn []
(animation-frame (loop (+ t 0.01))
(draw-frame! img v t))))]
((loop 0))))
(animate (.get canvas 0) 450)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment