-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathex08_folds.clj
executable file
·80 lines (62 loc) · 2.15 KB
/
ex08_folds.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
(ns ex08-folds
(:require [clojure2d.core :as c2d]
[fastmath.core :as m]
[fastmath.random :as r]
[fastmath.vector :as v]
[fastmath.fields :as vr]
[clojure2d.extra.overlays :as o]
[clojure.pprint :refer [pprint]])
(:import [fastmath.vector Vec2]))
(set! *warn-on-reflection* true)
(set! *unchecked-math* :warn-on-boxed)
(m/use-primitive-operators)
(def ^:const w 540)
(def ^:const h 540)
(def ^:const x1 -2.0)
(def ^:const y1 -2.0)
(def ^:const x2 2.0)
(def ^:const y2 2.0)
(def ^:const step (/ (- x2 x1) (* 1.8 w)))
(def ^:const x1- (dec x1))
(def ^:const y1- (dec y1))
(def ^:const x2+ (inc x2))
(def ^:const y2+ (inc y2))
(def ^:const w- (dec w))
(def ^:const h- (dec h))
(def ^:const fscale 0.7)
(def s60 (future (o/spots-overlay w h {:alpha 60 :intensities [60 120 180]})))
(def n60 (future (o/noise-overlay w h {:alpha 60})))
(defn make-me
[canvas window]
(let [field-config (vr/random-configuration)
field (vr/combine field-config)
;; field (vr/make-variation :shreadrad)
]
(pprint field-config)
(loop [y y1]
(loop [x x1]
(let [^Vec2 vv (v/mult (v/sin (v/mult (field (Vec2. x y)) fscale)) 2.7)
xx (m/norm (+ (.x vv) (r/grand 0.0012)) x1- x2+ 0.0 w)
yy (m/norm (+ (.y vv) (r/grand 0.0012)) y1- y2+ 0.0 h)]
(c2d/point canvas xx yy))
(when (and (c2d/window-active? window) (< x x2)) (recur (+ x step))))
(when (and (c2d/window-active? window) (< y y2)) (recur (+ y step)))))
canvas)
(defn draw-folds
[[canvas disp]]
(c2d/with-canvas-> canvas
(c2d/set-background 255 250 245)
(c2d/set-color 35 35 35 16)
(make-me disp)
(c2d/image (o/render-noise (c2d/get-image canvas) @n60))
(c2d/image (o/render-spots (c2d/get-image canvas) @s60)))
:done)
(defn example-08
[]
(let [cnvs (c2d/canvas w h)
window (c2d/show-window cnvs "folds" 15 nil)]
(defmethod c2d/key-pressed ["folds" \space] [_ _]
(c2d/save cnvs (c2d/next-filename "results/ex08/" ".jpg")))
[cnvs window]))
(draw-folds (example-08))
;; [[../results/ex08/1FABF63A_000013.jpg]]