Skip to content

Instantly share code, notes, and snippets.

@wagjo
Created January 31, 2014 12:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wagjo/8731671 to your computer and use it in GitHub Desktop.
Save wagjo/8731671 to your computer and use it in GitHub Desktop.
Playing with quil
(ns foo.bar
(:use [quil.core])
(:require [clojure.string :as s]))
(defn setup []
(frame-rate 1)
(background 255))
(def *scale* 2)
(defn draw-color [c o]
(let [x (bit-shift-right c 8)
y (bit-and c 16rff)
xt (* *scale* x)
yt (* *scale* y)]
(point (+ (* *scale* o) xt) yt)))
(defn r1 []
(rand-int 16rFFFF))
(def c [\0 \1 \2 \3 \4 \5 \6 \7 \8 \9 \A \B \C \D \E \F])
(defn r2 []
(Long/parseLong (s/join (repeatedly 4 #(rand-nth c))) 16))
(defn r3 []
(Long/parseLong (s/join (take 4 (shuffle c))) 16))
(defn draw []
(background 255)
(stroke 0)
(stroke-weight 2)
(fill 0)
(doseq [c (take (* 256 256) (repeatedly r2))]
(draw-color c 0))
(doseq [c (take (* 256 256) (repeatedly r3))]
(draw-color c 256)))
(defsketch foobar
:title "teh random colorz"
:setup setup
:draw draw
:size [1024 512])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment