Skip to content

Instantly share code, notes, and snippets.

@shengsword
Created May 3, 2019 02:54
Show Gist options
  • Save shengsword/7479674d3b7f5174c7f7fe71c5fd7ecc to your computer and use it in GitHub Desktop.
Save shengsword/7479674d3b7f5174c7f7fe71c5fd7ecc to your computer and use it in GitHub Desktop.
draw a noise rectangle in quil
(defn noise-rect [r n]
(let [area (g/area r)
bl (bottom-left r)
br (v2 (right r) (bottom r))
tr (top-right r)
tl (v2 (left r) (top r))
add-x #(m/+ %2 (v2 % 0))
add-y #(m/+ %2 (v2 0 %))
vs (map #(apply divide-segment %)
[[bl br n]
[br tr n]
[tr tl n]
[tl bl n]])
vertices (apply concat
(map (fn [line add]
(map #(-> %
(m/+ (q/random 1000))
(q/noise)
(q/map-range 0 1
(- (* area 0.001))
(* area 0.0001))
(add %2)) (range) line))
vs [add-y add-x add-y add-x]))]
(q/begin-shape)
(apply q/curve-vertex (last vertices))
(doseq [v vertices]
(apply q/curve-vertex v))
(apply q/curve-vertex (first vertices))
(apply q/curve-vertex (second vertices))
(q/end-shape)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment