-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Chapter 0 Example 7 Two-Dimensional Noise
- Loading branch information
Showing
3 changed files
with
52 additions
and
4 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
(ns noc.chapter-0-7 | ||
(:require | ||
[quil.core :as q])) | ||
|
||
(def size [640 240]) | ||
|
||
(defn init-state [_] | ||
{}) | ||
|
||
(defn setup! [{:keys [width height]}] | ||
(q/noise-seed (rand-int (-> js/Number (.-MAX_SAFE_INTEGER)))) | ||
(q/background 255) | ||
(let [img (q/create-image width height) | ||
xoffs (take width (iterate #(+ % 0.01) 0.0))] | ||
(doseq [[x xoff] (map-indexed vector xoffs)] | ||
(let [yoffs (take height (iterate #(+ % 0.01) 0.0))] | ||
(doseq [[y yoff] (map-indexed vector yoffs)] | ||
(let [bright (Math/floor (q/map-range (q/noise xoff yoff) 0 1 0 255))] | ||
(q/set-pixel img x y bright))))) | ||
(q/update-pixels img) | ||
(q/image img 0 0))) | ||
|
||
(defn tick [state] | ||
state) | ||
|
||
(defn draw! [_]) |
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