Skip to content

Instantly share code, notes, and snippets.

@quephird
Created November 18, 2013 18:04
Show Gist options
  • Save quephird/7532417 to your computer and use it in GitHub Desktop.
Save quephird/7532417 to your computer and use it in GitHub Desktop.
A first attempt at making a glitch-like rendering in quil, inspired by various ones by @netgrind on Twitter
(ns my-first-glitch
(:use quil.core))
(def screen-w 800)
(def screen-h 800)
(def t (atom 0))
(defn- setup []
(background 0)
(smooth)
)
(defn- cell [cell-w x y t]
(let [r (+ (* 128 (Math/sin (+ (* x y) @t))) 128)
g (+ (* 128 (Math/cos (+ (/ x (inc y)) @t))) 128)
b (rem (+ (* x y) @t) 256)]
(fill r g b)
(rect 0 0 cell-w cell-w)
)
)
(defn draw []
(let [cell-w 4
rows (/ screen-h cell-w)
columns (/ screen-w cell-w)]
(translate 0 0)
(doseq [row (range rows)]
(push-matrix)
(doseq [column (range columns)]
(cell cell-w column row t)
(translate cell-w 0)
)
(pop-matrix)
(translate 0 cell-w)
)
)
(swap! t inc)
)
(sketch
:title "glitch-thing-1"
:setup setup
:draw draw
:size [screen-w screen-h]
:renderer :java2d
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment