Created
October 4, 2013 02:35
-
-
Save quephird/6820154 to your computer and use it in GitHub Desktop.
a somewhat lame attempt at creating a flame like color pattern as well as generate noise for the grid pattern.
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 descent | |
(:use quil.core)) | |
(def screen-w 1920) | |
(def screen-h 1080) | |
(defn setup [] | |
(background 0) | |
(smooth) | |
(no-loop) | |
) | |
(defn generate-deviation [r c square-w rows] | |
(let [critical-r (/ rows 3) | |
max-deviation (/ (* (- r critical-r) square-w) rows) | |
dx (rand-int max-deviation) | |
dy (rand-int max-deviation)] | |
(if (> r critical-r) | |
[dx dy] | |
[0 0]) | |
) | |
) | |
(defn compute-xy [r c square-w rows] | |
(map + [(* c square-w) (* r square-w)] (generate-deviation r c square-w rows)) | |
) | |
;80 | |
(defn compute-rgb [current-row total-rows] | |
[(+ (/ (* current-row 200) total-rows) (rand-int 25)) | |
(+ (/ (* current-row 20) total-rows) (rand-int 5)) | |
0] | |
) | |
(defn draw [] | |
(let [columns 100 | |
square-w (/ screen-w (dec columns)) | |
rows (inc (/ screen-h square-w)) | |
half-square-w (/ square-w 2) | |
xs-and-ys-and-rgbs (into {} | |
(for [r (range (inc rows)) c (range (inc columns))] | |
[[r c] [(compute-xy r c square-w rows) (compute-rgb r rows)]]))] | |
(stroke 0 0 0) | |
; Move slightly off screen to insure that view is completely covered | |
(translate (- square-w) (- square-w)) | |
(doseq [[[row column] [[x1 y1] [r g b]]] xs-and-ys-and-rgbs :when (and (< row rows) (< column columns))] | |
(let [[x2 y2] (first (xs-and-ys-and-rgbs [row (inc column)])) | |
[x3 y3] (first (xs-and-ys-and-rgbs [(inc row) (inc column)])) | |
[x4 y4] (first (xs-and-ys-and-rgbs [(inc row) column]))] | |
(fill r g b) | |
(begin-shape :quads) | |
(vertex x1 y1) | |
(vertex x2 y2) | |
(vertex x3 y3) | |
(vertex x4 y4) | |
(end-shape) | |
) | |
) | |
(save "descent.png") | |
) | |
) | |
(sketch | |
:title "descent" | |
:setup setup | |
:draw draw | |
:size [screen-w screen-h] | |
:renderer :p2d | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment