Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
ClojureScript re-implementation of a runner up, originally by Piotr Stosur: "Animated fractal shapes (mainly rotating spirals) similar to CEVs after taking psychedelic/dissociative drugs. :P Based on copying previous frame into 4 smaller fragments (once per frame, no other kind of iterations) so it's much faster than per-pixel fractal g…
; rewritten in Clojurescript from javascript (originally by Piotr Stosur:
(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 (+ 600 (* (Math/sin t) 100))
r (Math/floor (* (Math/sin (* t 3)) 255))
g (Math/floor (* (Math/sin (* t 5)) 255))
b (Math/floor (* (Math/sin (* t 7)) 255))]
(fill-style "rgba(0,0,0,0.005)")
(fill-rect { :x 0 :y 0 :w w :h w })
(fill-rect { :x w :y w :w w :h w })
(fill-style (str "rgba(" r "," g "," b ",0.1)"))
(fill-rect { :x w :y 0 :w w :h w })
(fill-rect { :x 0 :y w :w w :h w })
(draw-image img { :x 0 :y w :w w :h w })
(draw-image img { :x w :y w :w w :h w })
(draw-image img { :x w :y 0 :w w :h w })
(draw-image img { :x 0 :y 0 :w w :h w })
(translate v v)
(rotate (* 0.01 (Math/abs (Math/sin t))))
(translate (- v) (- v)))))
(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
You can’t perform that action at this time.