Last active
August 29, 2015 14:07
-
-
Save rm-hull/2058361259a6bd764be8 to your computer and use it in GitHub Desktop.
A common optical illusion that is a static image, but appears to move as you look at different parts of the image - first popularised by Akiyoshi Kitaoka, Ritsumeikan University (http://www.ritsumei.ac.jp/~akitaoka/index-e.html). This gist based on a processing-js script at http://www.openprocessing.org/sketch/131928.
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
(ns enchilada.rotating-spiral | |
(:require | |
[jayq.core :refer [show]] | |
[enchilada :refer [ctx canvas]] | |
[big-bang.core :refer [big-bang]] | |
[monet.canvas :refer [fill-style fill ellipse rotate translate save restore fill-rect]])) | |
(def initial-state { | |
:angle 0 | |
:radius 600 | |
:speed 1 | |
:t 0}) | |
(defn update-state [event {:keys [t angle speed radius] :as world-state}] | |
(if (< radius 2) | |
world-state | |
(assoc world-state | |
:radius (/ radius (+ 1 (* 0.001 speed))) | |
:angle (+ angle (* speed (/ Math/PI 102))) | |
:t (inc t)))) | |
(defn render [{:keys [t angle radius]}] | |
(-> | |
ctx | |
(save) | |
(translate 400 300) | |
(rotate angle) | |
(fill-style (case (mod t 8) | |
0 :#FFFFFF | |
1 :#D2D200 | |
2 :#D2D200 | |
3 :#D2D200 | |
4 :#000000 | |
5 :#3232FF | |
6 :#3232FF | |
7 :#3232FF)) | |
(ellipse {:x radius :y 0 :rw (/ radius 10) :rh (/ radius 6)}) | |
(fill) | |
(restore))) | |
(show canvas) | |
(-> ctx | |
(fill-style :lightgrey) | |
(fill-rect {:x 0 :y 0 :w 800 :h 600})) | |
(big-bang | |
: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