Playing around with noise and color

This commit is contained in:
arne 2019-07-12 08:06:42 +02:00
commit 829beedcc8
4 changed files with 162 additions and 1 deletions

View file

@ -20,7 +20,7 @@
w (- (* size 0.5) padding)]
(q/with-translation [(* size 0.5) y]
(q/with-rotation [(* q/PI n 0.25)]
(q/stroke (+ 200 (* n 50)) 40 (* (q/map-range n 0 1 0.5 1) 230))
(q/stroke (+ 200 (* n 50)) 40 (* (q/map-range n -0.5 0.5 0.5 1) 230))
(q/line (- w) 0 w 0)))))
(defn draw-state [state]

48
src/aphorisms/eleven.clj Normal file
View file

@ -0,0 +1,48 @@
(ns aphorisms.eleven
(:require [thi.ng.geom.vector :as v]
[thi.ng.geom.circle :as c]
[thi.ng.geom.core :as g]
[thi.ng.math.core :as m]
[quil.core :as q]
[quil.middleware :as qm]))
(defn setup []
(q/frame-rate 1)
(q/color-mode :hsb)
{:shapes [(->
(c/circle 60)
(g/as-polygon 120))]})
(defn update-state [state]
state)
(defn mix-hsb [[h1 s1 b1] [h2 s2 b2] t]
(mapv + (map (partial * (- 1 t)) [h1 s1 b1])
(map (partial * t) [h2 s2 b2])))
(def color1 [180 (* 255 0.5) (* 255 0.6)])
(def color2 [210 (* 255 0.5) (* 255 0.6)])
(defn draw-state [state]
(q/background 0 0 (* 255 0.92))
(q/no-fill)
(q/no-stroke)
(q/with-translation [(* 0.5 (q/width)) (* 0.5 (q/height))]
(q/begin-shape)
(doseq [shape (:shapes state)
pt (:points shape)]
(apply q/fill (mix-hsb color1 color2 (q/map-range (first pt) -25 25 0 1)))
(apply q/vertex pt))
(q/end-shape :close)))
(q/defsketch eleven
:title "Eleven"
:size [500 500]
:settings #(q/pixel-density (q/display-density))
:setup setup
:update update-state
:renderer :p2d
:draw draw-state
:features [:keep-on-top :no-bind-output]
:middleware [qm/pause-on-error qm/fun-mode])

35
src/aphorisms/nine.clj Normal file
View file

@ -0,0 +1,35 @@
(ns aphorisms.nine
(:require [quil.core :as q]
[quil.middleware :as qm]))
(defn setup []
(q/frame-rate 60)
(q/color-mode :hsb)
{})
(defn update-state [state]
state)
(defn draw-state [state]
(let [half-width (* 0.5 (q/width))
half-height (* 0.5 (q/height))
top (+ 10 (- half-height))
right (- half-width 10)
bottom (- half-height 10)
left (+ 10 (- half-width))]
(q/background 240)
(q/with-translation [half-width half-height]
(dotimes [i 24]
(q/rotate (* i (/ q/PI 360)))
(q/stroke (+ 190 (* 2 i)) 120 250)
(q/line (+ (* i 10) -100) (+ (* i 10) -100) 100 100)))))
(q/defsketch nine
:title ""
:size [500 500]
:settings #(q/pixel-density (q/display-density))
:setup setup
:update update-state
:draw draw-state
:features [:keep-on-top :no-bind-output]
:middleware [qm/pause-on-error qm/fun-mode])

78
src/aphorisms/ten.clj Normal file
View file

@ -0,0 +1,78 @@
(ns aphorisms.ten
(:require [thi.ng.geom.vector :as v]
[thi.ng.math.core :as m]
[thi.ng.math.noise :as n]
[thi.ng.geom.core :as g]
[thi.ng.geom.circle :as c]
[quil.core :as q]
[quil.middleware :as qm]))
(def circle (c/circle 60))
(def noise-step 0.01)
(def movement (v/vec2 1 0))
(def resolution 75)
(defn setup []
(q/frame-rate 24)
(q/color-mode :rgb)
(q/background 240)
{:noise-pos 0
:circle-pos (v/vec2 (* (q/width) -0.5) 0)})
(defn update-state [state]
(update state :noise-pos (partial + noise-step)))
(def noise-scale 0.3)
(defn disturb-circle
[circle t]
(let [disturbed (map (fn [[x y :as pt]]
(let [n (q/noise (+ t (* noise-scale x))
(* noise-scale y))]
(m/* pt (q/map-range n 0 1 1 1.1))))
(:points (g/as-polygon circle resolution)))]
(take (+ resolution 3) (cycle disturbed))
#_(concat disturbed [(first disturbed) (second disturbed) (nth disturbed 2)])))
(def max-t 20)
(defn generate-circles [circle n max-offset]
(->> (repeat n circle)
(map-indexed
(fn [idx circle]
(->>
(disturb-circle circle (* idx 0.4))
;; add offset
(map (partial m/+ (v/vec2 (* (/ max-offset n) idx) 0)))
;; change size
(map #(m/* % (q/sin (q/map-range idx (dec n) 0 q/HALF-PI q/QUARTER-PI)))))))))
(defn draw-state [state]
(let [max-offset 100
circles (generate-circles circle 20 max-offset)]
;; clear previous drawing
(q/fill 240)
(q/no-stroke)
(q/rect 0 0 (q/width) (q/height))
;; draw new circle
(q/translate (* (q/width) 0.5)
(* (q/height) 0.5))
(q/translate (* max-offset -0.5) 0)
(q/no-fill)
(q/stroke 120)
(doseq [circle circles]
(q/begin-shape)
(doseq [[x y] circle]
(q/curve-vertex x y))
(q/end-shape))))
(q/defsketch ten
:title ""
:size [500 500]
:settings #(q/pixel-density (q/display-density))
:setup setup
:update update-state
:draw draw-state
:renderer :p2d
:features [:keep-on-top :no-bind-output]
:middleware [qm/pause-on-error qm/fun-mode])