Created
October 24, 2012 17:17
-
-
Save quephird/3947423 to your computer and use it in GitHub Desktop.
starfield
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 starfield | |
(:use quil.core)) | |
(def screen-w 1920) | |
(def screen-h 1080) | |
(defn setup [] | |
(smooth) | |
(no-fill) | |
(stroke-cap :square) | |
(stroke-join :miter) | |
(no-loop) | |
) | |
(defn- draw-star [scale star-color] | |
(rotate (random (radians 72))) | |
(let [w (* scale 7) | |
r1 (* scale 20) | |
r2 (+ r1 (* scale 20))] | |
(stroke-weight w) | |
(apply stroke star-color) | |
(begin-shape) | |
(doseq [i (range 5)] | |
(vertex (* r1 (cos (radians (- (* i 72) 36)))) (* r1 (sin (radians (- (* i 72) 36))))) | |
(vertex (* r2 (cos (radians (* i 72)))) (* r2 (sin (radians (* i 72))))) | |
) | |
(end-shape :close) | |
) | |
) | |
(defn- draw-stars [star-count star-color max-scale] | |
(doseq [_ (range star-count)] | |
(push-matrix) | |
(translate (random screen-w) (random screen-h)) | |
(draw-star (random max-scale) star-color) | |
(pop-matrix) | |
) | |
) | |
(defn draw [] | |
(apply background [140 55 18]) | |
(draw-stars 50 [120 30 5] 4) | |
(display-filter :blur 6) | |
(draw-stars 100 [190 90 0] 2) | |
(draw-stars 50 [255 140 0] 4) | |
(save "starfield.png") | |
) | |
(defsketch main | |
:title "starfield" | |
: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