-
-
Save samaaron/2891011 to your computer and use it in GitHub Desktop.
Quil: sun-flare-thingy
This file contains 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 sun-flare-thingy | |
(:import [processing.core PApplet PConstants]) | |
(:use quil.core)) | |
(def screen-w 1920) | |
(def screen-h 1080) | |
(defn- compute-stroke-color [x1 c1 x2 c2 x] | |
(map #(/ (+ %1 %2) (- x2 x1)) (map #(* (- x2 x) %) c1) (map #(* (- x x1) %) c2))) | |
(defn- draw-gradient-lines [x1 c1 x2 c2] | |
(doseq [x (range (int (- x2 x1)))] | |
(apply stroke (compute-stroke-color x1 c1 x2 c2 (+ x1 x))) | |
(line (+ x1 x) 0 (+ x1 x) screen-h))) | |
(defn- generate-background [xs-and-cs] | |
(let [adjoining-xs-and-cs | |
(map vector xs-and-cs (rest xs-and-cs))] | |
(doseq [[[x1 c1] [x2 c2]] adjoining-xs-and-cs] | |
(draw-gradient-lines x1 c1 x2 c2)))) | |
; I could not figure out how to use only quil calls here, | |
; so I had to jump out to the Java/Processing API | |
(defn- generate-starbursts [] | |
(no-stroke) | |
(doseq [i (range 150)] | |
(let [x (random screen-w) | |
y (+ (random (* screen-h 0.75)) (* screen-h 0.12)) | |
d (random 100) | |
gc (create-graphics 200 200 PApplet/P3D)] | |
(doto gc | |
(.beginDraw) | |
(.noStroke) | |
(.fill 255 255 0) | |
(.ellipse 100 100 (* d 1.25) (* d 1.25)) | |
(.filter PConstants/BLUR 15) | |
(.fill 255 255 255) | |
(.ellipse 100 100 (* d 0.5) (* d 0.5)) | |
(.filter PConstants/BLUR 4) | |
(.endDraw)) | |
(image gc (- x 100) (- y 100))))) | |
(defn setup [] | |
(smooth) | |
(no-loop)) | |
(defn draw [] | |
(let [bg-xs-and-cs [[0 [0 0 0]] | |
[(Math/floor (* screen-w 0.33)) [64 0 0]] | |
[(Math/floor (* screen-w 0.5)) [200 0 0]] | |
[(Math/floor (* screen-w 0.67)) [255 127 0]] | |
[(Math/floor (* screen-w 0.8)) [255 255 0]] | |
[screen-w [250 247 212]]]] | |
(generate-background bg-xs-and-cs) | |
(generate-starbursts) | |
(save "sun-flare-thingy.png"))) | |
(defsketch main | |
:title "sun-flare-thingy" | |
:setup setup | |
:draw draw | |
:size [screen-w screen-h]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment