Created
May 16, 2012 14:08
-
-
Save quephird/2710615 to your computer and use it in GitHub Desktop.
sine-wave
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 sine-wave | |
(:use quil.core)) | |
(def screen-w 1920) | |
(def screen-h 1080) | |
(def current-color (atom [])) | |
(defn- init-current-color [] | |
(doseq [i (range 3)] | |
(swap! current-color assoc i (random 255)))) | |
(defn- change-current-color [] | |
(doseq [i (range 3)] | |
(let [change-direction (random 3) | |
current-color-value (@current-color i)] | |
(cond | |
(< change-direction 1) (swap! current-color assoc i (- current-color-value 5)) | |
(> change-direction 2) (swap! current-color assoc i (+ current-color-value 5)) | |
:else nil)))) | |
(defn setup [] | |
(init-current-color) | |
(smooth) | |
(background 0) | |
(no-loop)) | |
(defn draw [] | |
(doseq [y (range -100 (+ screen-h 100))] | |
(apply stroke @current-color) | |
(doseq [x (range screen-w)] | |
(point x (+ y (* 100 (Math/sin (/ x 60)))))) | |
(change-current-color)) | |
(save "sine-wave.png")) | |
(defsketch main | |
:title "Sine wave" | |
: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