generated from Phlox-GL/phlox-workflow.cljs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
compact.cirru
257 lines (256 loc) · 9.61 KB
/
compact.cirru
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
{} (:package |app)
:configs $ {} (:init-fn |app.main/main!) (:reload-fn |app.main/reload!) (:version nil)
:modules $ [] |memof/ |lilac/ |respo.calcit/ |respo-ui.calcit/ |phlox/
:entries $ {}
:files $ {}
|app.complex $ {}
:defs $ {}
|add $ quote
defn add (p1 p2)
let-sugar
[] a b
, p1
([] x y) p2
[] (+ a x) (+ b y)
|minus $ quote
defn minus
[] a b
[] x y
[] (- a x) (- b y)
|negate $ quote
defn negate
[] x y
[] (- 0 x) (- 0 y)
|times $ quote
defn times (p1 p2)
let-sugar
[] a b
, p1
([] x y) p2
[]
- (* a x) (* b y)
+ (* a y) (* b x)
:ns $ quote (ns app.complex)
|app.config $ {}
:defs $ {}
|cdn? $ quote
def cdn? $ cond
exists? js/window
, false
(exists? js/process) (= "\"true" js/process.env.cdn)
:else false
|dev? $ quote
def dev? $ = "\"dev" (get-env "\"mode" "\"release")
|site $ quote
def site $ {} (:dev-ui "\"http://localhost:8100/main-fonts.css") (:release-ui "\"http://cdn.tiye.me/favored-fonts/main-fonts.css") (:cdn-url "\"http://cdn.tiye.me/waving-rail/") (:title "\"Waving Rail") (:icon "\"http://cdn.tiye.me/logo/quamolit.png") (:storage-key "\"waving-rail")
:ns $ quote (ns app.config)
|app.container $ {}
:defs $ {}
|cal-position $ quote
defn cal-position (base-point r v0 v phi idx)
complex/add base-point $ complex/times ([] r 0)
[]
js/Math.cos $ + phi (* v0 v idx)
js/Math.sin $ + phi (* v0 v idx)
|comp-container $ quote
defcomp comp-container (store)
let
states $ :states store
cursor $ []
state $ or (:data states)
{} (:v0 0.01) (:r1 150)
:p1 $ [] 300 300
:v1 0.2
:r2 200
:p2 $ [] 300 300
:v2 0.2
:phi2 0
:steps 100
:alpha 1
container ({})
container
{} $ :position ([] -300 -300)
graphics $ {}
:ops $ concat
[] $ g :line-style
{} (:width 1)
:color $ hslx 200 80 80
:alpha $ :alpha state
-> (gen-trails state)
mapcat $ fn (pair)
[]
g :move-to $ first pair
g :line-to $ last pair
comp-drag-point (>> states :p1)
{}
:position $ :p1 state
:radius 4
:on-change $ fn (p d!)
d! cursor $ assoc state :p1 p
comp-drag-point (>> states :r1)
{}
:position $ complex/add (:p1 state)
[] (:r1 state) 0
:radius 4
:on-change $ fn (p d!)
d! cursor $ assoc state :r1
- (first p)
first $ :p1 state
comp-drag-point (>> states :p2)
{}
:position $ :p2 state
:radius 4
:on-change $ fn (p d!)
d! cursor $ assoc state :p2 p
comp-drag-point (>> states :r2)
{}
:position $ complex/add (:p2 state)
[] (:r2 state) 0
:radius 4
:on-change $ fn (p d!)
d! cursor $ assoc state :r2
- (first p)
first $ :p2 state
comp-slider (>> states :steps)
{}
:value $ :steps state
:round? true
:unit 1
:min 2
:position $ [] 140 -280
:title "\"Steps"
:on-change $ fn (v d!)
d! cursor $ assoc state :steps v
comp-slider (>> states :v0)
{}
:value $ or (:v0 state) 0.1
:title "\"v0"
:unit 0.0001
:min 0.0001
:max 2
:position $ [] -280 -280
:on-change $ fn (v d!)
d! cursor $ assoc state :v0 v
comp-slider (>> states :v1)
{}
:value $ :v1 state
:title "\"v1"
:unit 0.1
:min 1
:position $ [] -140 -280
:round? true
:on-change $ fn (v d!)
d! cursor $ assoc state :v1 v
comp-slider (>> states :v2)
{}
:value $ :v2 state
:title "\"v2"
:unit 0.1
:min 1
:round? true
:position $ [] 0 -280
:on-change $ fn (v d!)
d! cursor $ assoc state :v2 v
comp-slider (>> states :alpha)
{}
:value $ :alpha state
:title "\"alpha"
:unit 0.004
:min 0.001
:max 1
:round? false
:position $ [] 280 -280
:on-change $ fn (v d!)
d! cursor $ assoc state :alpha v
comp-slider (>> states :phi2)
{}
:value $ :phi2 state
:title "\"phi"
:unit 0.005
:min 0.001
:max 360
:round? false
:position $ [] 420 -280
:on-change $ fn (v d!)
d! cursor $ assoc state :phi2 v
|gen-trails $ quote
defn gen-trails (state)
->
range $ :steps state
map $ fn (idx)
[]
cal-position (:p1 state) (:r1 state) (:v0 state) (:v1 state) 0 idx
cal-position (:p2 state) (:r2 state) (:v0 state) (:v2 state) (:phi2 state) idx
:ns $ quote
ns app.container $ :require
[] phlox.core :refer $ [] defcomp >> hslx rect circle text container graphics create-list g
[] app.complex :as complex
[] phlox.comp.slider :refer $ [] comp-slider
[] phlox.comp.drag-point :refer $ [] comp-drag-point
|app.main $ {}
:defs $ {}
|*store $ quote (defatom *store schema/store)
|dispatch! $ quote
defn dispatch! (op op-data)
if (list? op)
recur :states $ [] op op-data
do
when
and dev? $ not= op :states
println "\"dispatch!" op op-data
let
op-id $ shortid/generate
op-time $ js/Date.now
reset! *store $ updater @*store op op-data op-id op-time
|global-fonts $ quote
def global-fonts $ js/Promise.all
js-array
.load $ new FontFaceObserver "\"Josefin Sans"
.load $ new FontFaceObserver "\"Hind"
|main! $ quote
defn main! ()
if dev? $ load-console-formatter!
-> global-fonts $ .then
fn (e) (render-app!)
add-watch *store :change $ fn (s p) (render-app!)
println "\"App Started"
|reload! $ quote
defn reload! () $ if (nil? build-errors)
do (println "\"Code updated.") (clear-phlox-caches!) (remove-watch *store :change)
add-watch *store :change $ fn (store prev) (render-app!)
render-app!
hud! "\"ok~" "\"Ok"
hud! "\"error" build-errors
|render-app! $ quote
defn render-app! () $ render! (comp-container @*store) dispatch! ({})
:ns $ quote
ns app.main $ :require ([] "\"pixi.js" :as PIXI) ([] "\"shortid" :as shortid)
[] phlox.core :refer $ [] render! clear-phlox-caches!
[] app.container :refer $ [] comp-container
[] app.schema :as schema
[] app.config :refer $ [] dev?
[] app.updater :refer $ [] updater
[] "\"fontfaceobserver-es" :default FontFaceObserver
"\"./calcit.build-errors" :default build-errors
"\"bottom-tip" :default hud!
|app.schema $ {}
:defs $ {}
|store $ quote
def store $ {} (:tab :drafts) (:x 0)
:states $ {}
:ns $ quote (ns app.schema)
|app.updater $ {}
:defs $ {}
|updater $ quote
defn updater (store op op-data op-id op-time)
case-default op
do (println "\"unknown op" op op-data) store
:add-x $ update store :x
fn (x)
if (> x 10) 0 $ + x 1
:tab $ assoc store :tab op-data
:states $ update-states store op-data
:hydrate-storage op-data
:ns $ quote
ns app.updater $ :require
phlox.cursor :refer $ update-states