-
Notifications
You must be signed in to change notification settings - Fork 1
/
compact.cirru
2695 lines (2694 loc) · 129 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
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
{} (:package |quatrefoil)
:configs $ {} (:init-fn |quatrefoil.app.main/main!) (:reload-fn |quatrefoil.app.main/reload!) (:version |0.1.1)
:modules $ [] |touch-control/ |pointed-prompt/ |quaternion/
:entries $ {}
:files $ {}
|quatrefoil.alias $ %{} :FileEntry
:defs $ {}
|ambient-light $ %{} :CodeEntry (:doc |)
:code $ quote
defn ambient-light (props & children) (create-element :ambient-light props children)
|arrange-children $ %{} :CodeEntry (:doc |)
:code $ quote
defn arrange-children (children)
let
cursor $ first children
result $ if
and
= 1 $ count children
not $ or (comp? cursor) (shape? cursor)
, cursor
-> children
map-indexed $ fn (idx p) ([] idx p)
pairs-map
; .log js/console "|Handle children:" children result
, result
|box $ %{} :CodeEntry (:doc |)
:code $ quote
defn box (props & children) (create-element :box props children)
|buffer-object $ %{} :CodeEntry (:doc |)
:code $ quote
defn buffer-object (props & children) (create-element :buffer-object props children)
|create-element $ %{} :CodeEntry (:doc |)
:code $ quote
defn create-element (el-name props children)
%{} Shape (:name el-name)
:params $ -> props (dissoc :material) (dissoc :event) (dissoc :position) (dissoc :scale) (dissoc :rotation) (dissoc :attributes) (dissoc :on) (dissoc :event)
:position $ :position props
:scale $ :scale props
:material $ :material props
:rotation $ :rotation props
:attributes $ :attributes props
:event $ or (:on props) (:event props)
:children $ arrange-children children
|directional-light $ %{} :CodeEntry (:doc |)
:code $ quote
defn directional-light (props & children) (create-element :directional-light props children)
|flat-values $ %{} :CodeEntry (:doc |)
:code $ quote
defmacro flat-values (& points)
&let
chunk $ &list:concat & points
quasiquote $ [] ~@chunk
|group $ %{} :CodeEntry (:doc |)
:code $ quote
defn group (props & children) (create-element :group props children)
|line $ %{} :CodeEntry (:doc |)
:code $ quote
defn line (props & children) (create-element :line props children)
|line-segments $ %{} :CodeEntry (:doc |)
:code $ quote
defn line-segments (props & children) (create-element :line-segments props children)
|mesh-line $ %{} :CodeEntry (:doc |)
:code $ quote
defn mesh-line (props & children) (create-element :mesh-line props children)
|parametric $ %{} :CodeEntry (:doc |)
:code $ quote
defn parametric (props & children) (create-element :parametric props children)
|plane-reflector $ %{} :CodeEntry (:doc |)
:code $ quote
defn plane-reflector (props & children) (create-element :plane-reflector props children)
|point-light $ %{} :CodeEntry (:doc |)
:code $ quote
defn point-light (props & children) (create-element :point-light props children)
|polyhedron $ %{} :CodeEntry (:doc |)
:code $ quote
defn polyhedron (props & children) (create-element :polyhedron props children)
|rect-area-light $ %{} :CodeEntry (:doc |)
:code $ quote
defn rect-area-light (props & children) (create-element :rect-area-light props children)
|scene $ %{} :CodeEntry (:doc |)
:code $ quote
defn scene (props & children) (create-element :scene props children)
|shader-mesh $ %{} :CodeEntry (:doc |)
:code $ quote
defn shader-mesh (props & children) (create-element :shader-mesh props children)
|shape $ %{} :CodeEntry (:doc |)
:code $ quote
defn shape (props & children) (create-element :shape props children)
|some-object $ %{} :CodeEntry (:doc |)
:code $ quote
defn some-object (props)
create-element :some-object props $ []
|sphere $ %{} :CodeEntry (:doc |)
:code $ quote
defn sphere (props & children) (create-element :sphere props children)
|spline $ %{} :CodeEntry (:doc |)
:code $ quote
defn spline (props & children) (create-element :spline props children)
|spot-light $ %{} :CodeEntry (:doc |)
:code $ quote
defn spot-light (props & children) (create-element :spot-light props children)
|text $ %{} :CodeEntry (:doc |)
:code $ quote
defn text (props & children) (create-element :text props children)
|torus $ %{} :CodeEntry (:doc |)
:code $ quote
defn torus (props & children) (create-element :torus props children)
|tube $ %{} :CodeEntry (:doc |)
:code $ quote
defn tube (props & children) (create-element :tube props children)
:ns $ %{} :CodeEntry (:doc |)
:code $ quote
ns quatrefoil.alias $ :require
quatrefoil.schema :refer $ Shape Component comp? shape?
|quatrefoil.app.comp.container $ %{} :FileEntry
:defs $ {}
|comp-back $ %{} :CodeEntry (:doc |)
:code $ quote
defcomp comp-back (on-back)
box
{} (:width 16) (:height 4) (:depth 6)
:position $ [] 60 30 0
:material $ {} (:kind :mesh-lambert) (:color 0x808080) (:opacity 0.6)
:on $ {}
:click $ fn (e d!) (on-back d!)
text $ {} (:text |Back) (:size 4) (:depth 2)
:position $ [] 0 0 10
:material $ {} (:kind :mesh-lambert) (:color 0xffcccc)
|comp-container $ %{} :CodeEntry (:doc |)
:code $ quote
defcomp comp-container (store)
let
states $ :states store
cursor $ :cursor states
state $ either (:data states)
{} $ :tab :portal
tab $ :tab state
scene ({})
group
{}
:scale $ [] 0.01 0.01 0.01
:position $ [] 0 1.2 -0.8
case-default tab
comp-portal $ fn (next d!)
d! cursor $ assoc state :tab next
:portal $ comp-portal
fn (next d!)
d! cursor $ assoc state :tab next
:todolist $ comp-todolist (:tasks store)
:demo $ comp-demo
:lines $ comp-lines
:shapes $ comp-shapes
:triflorum $ comp-triflorum
:mirror $ comp-mirror (>> states :mirror)
:fly $ comp-fly-city (>> states :fly)
:quat-tree $ comp-quat-tree
:quilling $ comp-quilling
:control $ comp-control-demo (>> states :control)
:shader $ comp-shader
:gltf $ comp-gltf
:sphere-grid $ comp-sphere-grid
if (not= tab :portal)
comp-back $ fn (d!)
d! cursor $ assoc state :tab :portal
ambient-light $ {} (:color 0x666666) (:intensity 1)
; point-light $ {} (:color 0xffffff) (:intensity 1.4) (:distance 200)
:position $ [] 20 40 50
; point-light $ {} (:color 0xffffff) (:intensity 2) (:distance 200)
:position $ [] 0 60 0
|comp-demo $ %{} :CodeEntry (:doc |)
:code $ quote
defcomp comp-demo () $ group ({})
box $ {} (:width 16) (:height 4) (:depth 6)
:position $ [] -40 0 0
:material $ {} (:kind :mesh-lambert) (:color 0x808080) (:opacity 0.6)
:event $ {}
:click $ fn (e d!) (d! :demo nil)
sphere $ {} (:radius 8)
:position $ [] 10 0 0
:material $ {} (:kind :mesh-lambert) (:opacity 0.6) (:color 0x9050c0)
:event $ {}
:click $ fn (e d!) (d! :canvas nil)
:gamepad $ fn (info elapsed d!) (js/console.log "\"first pad event" info)
sphere $ {} (:radius 8)
:position $ [] 30 0 0
:material $ {} (:kind :mesh-lambert) (:opacity 0.6)
:color $ hclx 160 80 70
:event $ {}
:click $ fn (e d!) (d! :canvas nil)
:gamepad $ fn (info elapsed d!) (js/console.log "\"second pad event" info)
group ({})
text $ {} (:text |Quatrefoil) (:size 4) (:depth 2)
:position $ [] -30 0 20
:material $ {} (:kind :mesh-lambert) (:color 0xffcccc)
sphere $ {} (:radius 4) (:emissive 0xffffff) (:metalness 0.8) (:color 0x00ff00) (:emissiveIntensity 1) (:roughness 0)
:position $ [] -10 20 0
:material $ {} (:kind :mesh-basic) (:color 0xffff55) (:opacity 0.8) (:transparent true)
:event $ {}
:click $ fn (e d!) (d! :canvas nil)
; point-light $ {} (:color 0xffff55) (:intensity 2) (:distance 200)
:position $ [] -10 20 0
point-light $ {} (:color 0xffffff) (:intensity 2) (:distance 200)
:position $ [] 10 20 10
|comp-gltf $ %{} :CodeEntry (:doc |)
:code $ quote
defn comp-gltf () $ group ({})
some-object $ {} (:key :sakura)
:object-loaded? $ some? (get @*loaded-objects :sakura)
:position $ [] 0 -100 -100
:scale $ [] 200 200 200
point-light $ {} (:color 0x555555) (:intensity 2.4) (:distance 800)
:position $ [] 10 100 100
ambient-light $ {} (:color 0xaaaaaa) (:intensity 1)
|comp-sphere-grid $ %{} :CodeEntry (:doc |)
:code $ quote
defn comp-sphere-grid () $ group ({})
group ({}) & $ -> (range-3d 8)
map $ fn (pair)
let
x $ nth pair 0
y $ nth pair 1
z $ nth pair 2
r 20
sphere $ {} (:radius 3)
:position $ [] (* r x) (* r y) (* r z)
:material $ {} (:kind :mesh-lambert) (:opacity 0.6)
:color $ hclx 160 80 70
:event $ {}
:click $ fn (e d!) (d! :canvas nil)
:gamepad $ fn (info elapsed d!) (js/console.log "\"second pad event" info)
point-light $ {} (:color 0xffffff) (:intensity 2) (:distance 200)
:position $ [] 10 20 10
|range-2d $ %{} :CodeEntry (:doc |)
:code $ quote
defn range-2d (n)
-> (range-bothway n)
mapcat $ fn (i)
-> (range-bothway n)
map $ fn (j) ([] i j)
|range-3d $ %{} :CodeEntry (:doc |)
:code $ quote
defn range-3d (n)
-> (range-bothway n)
mapcat $ fn (i)
-> (range-bothway n)
mapcat $ fn (j)
-> (range-bothway n)
map $ fn (k) ([] i j k)
:ns $ %{} :CodeEntry (:doc |)
:code $ quote
ns quatrefoil.app.comp.container $ :require
quatrefoil.alias :refer $ group box sphere point-light ambient-light scene text some-object
quatrefoil.core :refer $ defcomp >> hclx
quatrefoil.app.comp.todolist :refer $ comp-todolist
quatrefoil.app.comp.portal :refer $ comp-portal
quatrefoil.app.comp.lines :refer $ comp-lines comp-fly-city
quatrefoil.app.comp.shapes :refer $ comp-shapes comp-quilling
quatrefoil.app.comp.triflorum :refer $ comp-triflorum
quatrefoil.app.comp.mirror :refer $ comp-mirror
quatrefoil.app.comp.quat-tree :refer $ comp-quat-tree
quatrefoil.app.comp.control :refer $ comp-control-demo
quatrefoil.app.comp.shader :refer $ comp-shader
quatrefoil.globals :refer $ *loaded-objects
|quatrefoil.app.comp.control $ %{} :FileEntry
:defs $ {}
|comp-control-demo $ %{} :CodeEntry (:doc |)
:code $ quote
defcomp comp-control-demo (states)
let
cursor $ :cursor states
state $ or (:data states)
{}
:p0 $ v3 0 0 0
:v0 0
:v1 $ [] 1 1
:on? false
group ({})
comp-pin-point
{} (:speed 8) (:label "\"C") (:color 0xddaaff) (:radius 1) (:opacity 1)
:position $ :p0 state
fn (next d!)
d! cursor $ assoc state :p0 next
comp-value
{} (:speed 0.2) (:show-text? true) (:label "\"A")
:value $ :v0 state
:position $ v3 10 0 0
:bound $ [] -2 20
:color $ hslx 10 90 80
fn (v d!)
d! cursor $ assoc state :v0 v
comp-value-2d
{} (:label "\"B")
:value $ :v1 state
:position $ v3 0 10 0
:speed 0.2
:color 0xccaaff
:show-text? true
:fract-length 3
fn (v d!)
d! cursor $ assoc state :v1 v
comp-switch
{} (:label "\"Status") (:color 0xaa88ff)
:value $ :on? state
:position $ v3 20 0 0
fn (v d!)
d! cursor $ assoc state :on? v
point-light $ {} (:color 0xffffff) (:intensity 1) (:distance 200)
:position $ v3 20 40 50
:ns $ %{} :CodeEntry (:doc |)
:code $ quote
ns quatrefoil.app.comp.control $ :require
quatrefoil.alias :refer $ group box sphere text line tube point-light
quatrefoil.core :refer $ defcomp hslx
quaternion.core :refer $ q* &q* v-scale q+
quaternion.vector :refer $ v3
quatrefoil.comp.control :refer $ comp-pin-point comp-value comp-value-2d comp-switch
|quatrefoil.app.comp.lines $ %{} :FileEntry
:defs $ {}
|cloud-fn $ %{} :CodeEntry (:doc |)
:code $ quote
defn cloud-fn (ratio factor)
let
f0 $ nth factor 0
f1 $ nth factor 1
f2 $ nth factor 2
deg $ * ratio 20 &PI
r $ * 160 (js/Math.sin deg)
deg2 $ / (* 5 f0 deg) 13
deg3 $ * 0.02 f1 deg
[]
* r $ js/Math.cos deg2
* 0.6 f2 r $ js/Math.sin deg3
* r $ js/Math.sin deg2
|comp-fly-city $ %{} :CodeEntry (:doc |)
:code $ quote
defcomp comp-fly-city (states)
let
cursor $ :cursor states
state $ or (:data states)
{}
:buildings $ make-building-data 80
:factor $ [] 1 1 1
group ({}) & horizontal-lines & forward-lines &
-> (:buildings state)
map $ fn (vec)
let[] (x y w d h) vec $ box
{} (:width w) (:height h) (:depth d)
:position $ [] x (* h 0.5) (+ y)
:material $ {} (:kind :mesh-lambert) (:color 0x808080) (:opacity 0.6)
:event $ {}
:click $ fn (e d!) (d! :demo nil)
sphere $ {} (:radius 4) (:emissive 0xffffff) (:metalness 0.8) (:color 0x00ff00) (:emissiveIntensity 1) (:roughness 0)
:position $ [] 30 30 40
:material $ {} (:kind :mesh-basic) (:color 0xffff55) (:opacity 0.8) (:transparent true)
:event $ {}
:click $ fn (e d!)
d! cursor $ assoc state :buildings (make-building-data 80)
point-light $ {} (:color 0xffff55) (:intensity 2) (:distance 600)
:position $ [] 30 20 40
tube $ {} (:points-fn cloud-fn) (:radius 0.6) (:tubular-segments 1600) (:radial-segments 4)
:factor $ :factor state
:position $ [] 0 200 0
:material $ {} (:kind :mesh-standard) (:color 0xcccc77) (:opacity 1) (:transparent true)
sphere $ {} (:radius 4) (:emissive 0xffffff) (:metalness 0.8) (:color 0x00ff00) (:emissiveIntensity 1) (:roughness 0)
:position $ [] 0 240 0
:material $ {} (:kind :mesh-basic) (:color 0xffff55) (:opacity 0.2) (:transparent true)
:event $ {}
:click $ fn (e d!)
d! cursor $ assoc state :factor
[] (rand-shift 1 0.92) (rand-shift 1 0.92) (rand-shift 1 0.92)
ambient-light $ {} (:color 0x444422)
|comp-lines $ %{} :CodeEntry (:doc |)
:code $ quote
defcomp comp-lines () $ group ({})
text $ {} (:text |Lines) (:size 4) (:depth 1)
:position $ [] 0 0 4
:material $ {} (:kind :mesh-lambert) (:color 0xffcccc) (:opacity 0.9) (:transparent true)
line $ {}
:points $ [] ([] 0 0 0) ([] 3 3 4) ([] 1 4 6) ([] -2 8 0) ([] 2 5 1)
:position $ [] 0 -10 0
:material $ {} (:kind :line-dashed) (:color 0xaaaaff) (:opacity 0.9) (:transparent true) (:linewidth 4) (:gapSize 0.5) (:dashSize 0.5)
mesh-line $ {}
:points $ [] ([] 0 0 0) ([] 3 3 4) ([] 1 4 6) ([] -2 8 0) ([] 2 5 1)
:position $ [] 5 -10 0
:material $ {} (:kind :mesh-line) (:color 0xaaaaff) (:transparent true) (:opacity 0.4) (:depthTest true) (:lineWidth 0.01)
line-segments $ {}
:segments $ []
[] ([] 0 0 0) ([] 3 3 4)
[] ([] 1 4 6) ([] -2 8 0)
:position $ [] 10 -10 0
:material $ {} (:kind :line-dashed) (:color 0xaaaaff) (:opacity 0.9) (:transparent true) (:linewidth 4) (:gapSize 0.5) (:dashSize 0.5)
line-segments $ {}
:points $ [] ([] 0 0 0) ([] 3 3 4) ([] 1 4 6) ([] -2 8 0)
:position $ [] 15 -10 0
:material $ {} (:kind :line-dashed) (:color 0xaaaaff) (:opacity 0.9) (:transparent true) (:linewidth 4) (:gapSize 0.5) (:dashSize 0.5)
spline $ {}
:points $ [] ([] 10 10 0) ([] 8 0 0) ([] 18 0 0) ([] 19 6 4) ([] 15 6 4) ([] 13 8 0) ([] 12 5 1)
:position $ [] 0 0 0
:material $ {} (:kind :line-dashed) (:color 0xaaaaff) (:opacity 0.9) (:transparent true) (:linewidth 4) (:gapSize 1) (:dashSize 1)
tube $ {} (:points-fn tube-fn) (:radius 0.8) (:tubular-segments 400) (:radial-segments 20)
:position $ [] -10 0 0
:material $ {} (:kind :mesh-standard) (:color 0xcccc77) (:opacity 1) (:transparent true)
point-light $ {} (:color 0xffffff) (:intensity 1.4) (:distance 200)
:position $ [] 20 40 50
|forward-lines $ %{} :CodeEntry (:doc |)
:code $ quote
def forward-lines $ -> (range 20)
map $ fn (idx)
let
pos $ * 10 (- idx 10)
line $ {}
:points $ [] ([] pos 0 -200) ([] pos 0 200)
:position $ [] 0 0 0
:material $ {} (:kind :line-dashed) (:color 0xccccff) (:opacity 0.3) (:transparent true) (:linewidth 2) (:gapSize 0.5) (:dashSize 0.5)
|horizontal-lines $ %{} :CodeEntry (:doc |)
:code $ quote
def horizontal-lines $ -> (range 20)
map $ fn (idx)
let
pos $ * 10 (- idx 10)
line $ {}
:points $ [] ([] -200 0 pos) ([] 200 0 pos)
:position $ [] 0 0 0
:material $ {} (:kind :line-dashed) (:color 0xccccff) (:opacity 0.3) (:transparent true) (:linewidth 2) (:gapSize 0.5) (:dashSize 0.5)
|make-building-data $ %{} :CodeEntry (:doc |)
:code $ quote
defn make-building-data (n)
-> (range n)
map $ fn (i)
[] (rand-shift 0 160) (rand-shift 0 160) (rand-shift 12 8) (rand-shift 8 6) (rand-shift 60 50)
|tube-fn $ %{} :CodeEntry (:doc |)
:code $ quote
defn tube-fn (t factor)
[]
*
+ 2 $ * t 20
sin $ * 40 t
* 30 t
*
+ 2 $ * t 20
cos $ * 40 t
:ns $ %{} :CodeEntry (:doc |)
:code $ quote
ns quatrefoil.app.comp.lines $ :require
quatrefoil.alias :refer $ group box sphere text line line-segments mesh-line spline tube point-light ambient-light
quatrefoil.core :refer $ defcomp
"\"@calcit/std" :refer $ rand-shift
"\"three" :as THREE
|quatrefoil.app.comp.mirror $ %{} :FileEntry
:defs $ {}
|comp-mirror $ %{} :CodeEntry (:doc |)
:code $ quote
defcomp comp-mirror (states)
let
cursor $ :cursor states
state $ either (:data states)
{} $ :v 0
group ({})
group ({}) & $ -> (range 2)
map $ fn (i)
plane-reflector $ {} (:width 40) (:height 40) (:color 0xffaaaa)
:rotation $ [] (rand-around 0 1) (rand-around 0 1) (rand-around 0 1)
:position $ [] (rand-around 0 100) (rand-around 0 100) (rand-around 0 -20)
group ({}) & $ -> (range 60)
map $ fn (x)
shape $ {} (:path heart-path)
:scale $ v-scale ([] 1 1 1)
pow (rand 0.26) 1.4
:rotation $ [] (rand-around 0 1) (rand-around 0 1) (rand-around 0 1)
:position $ [] (rand-around 0 50) (rand-around 0 50) (rand-around 20 80)
:material $ {} (:kind :mesh-lambert) (:opacity 0.5) (:transparent true) (:color 0xff2225)
box $ {} (:width 4) (:height 4) (:depth 4)
:position $ [] 0 0 0
:material $ {} (:kind :mesh-lambert) (:color 0xcccc33) (:opacity 0.6)
:event $ {}
:click $ fn (e d!)
d! cursor $ assoc state :v (rand 1)
point-light $ {} (:color 0xff8888) (:intensity 2) (:distance 200)
:position $ [] 10 0 0
ambient-light $ {} (:color 0x666666) (:intencity 1)
|heart-path $ %{} :CodeEntry (:doc |)
:code $ quote
def heart-path $ [] (:: :move-to 25 25) (:: :bezier-curve-to 25 25 20 50 0 50) (:: :bezier-curve-to -30 50 -30 15 -30 15) (:: :bezier-curve-to -30 -5 -10 -27 25 -45) (:: :bezier-curve-to 60 -22 80 -5 80 15) (:: :bezier-curve-to 80 15 80 50 50 50) (:: :bezier-curve-to 35 50 25 25 25 25)
:ns $ %{} :CodeEntry (:doc |)
:code $ quote
ns quatrefoil.app.comp.mirror $ :require
quatrefoil.alias :refer $ group box sphere shape text line spline tube plane-reflector point-light ambient-light
quatrefoil.core :refer $ defcomp
quatrefoil.math :refer $ rand-around
quaternion.vector :refer $ v-scale
"\"@calcit/std" :refer $ rand
|quatrefoil.app.comp.portal $ %{} :FileEntry
:defs $ {}
|comp-portal $ %{} :CodeEntry (:doc |)
:code $ quote
defcomp comp-portal (on-change)
group ({})
comp-tab :todolist |Todolist ([] -40 30 0) on-change
comp-tab :demo |Demo ([] 0 30 0) on-change
comp-tab :lines |Lines ([] 0 20 0) on-change
comp-tab :shapes |Shapes ([] -40 20 0) on-change
comp-tab :control "\"Control Demo" ([] -40 10 0) on-change
comp-tab :triflorum |Triflorum ([] 0 10 0) on-change
comp-tab :mirror "\"Mirror.. <3" ([] -40 -0 0) on-change
comp-tab :fly "\"Fly" ([] 0 0 0) on-change
comp-tab :quat-tree "\"Quat... Tree" ([] -40 -10 0) on-change
comp-tab :quilling "\"Quilling" ([] -0 -10 0) on-change
comp-tab :shader "\"Shader" ([] -40 -20 0) on-change
comp-tab :gltf "\"GLTF" ([] 0 -20 0) on-change
comp-tab :sphere-grid "\"Sphere Grid" ([] -40 -30 0) on-change
point-light $ {} (:color 0xffffff) (:intensity 1.4) (:distance 200)
:position $ [] 20 40 50
|comp-tab $ %{} :CodeEntry (:doc |)
:code $ quote
defcomp comp-tab (k title position on-change)
box
{} (:width 16) (:height 4) (:depth 6) (:position position)
:material $ {} (:kind :mesh-lambert)
:color $ hslx 60 43 65
:opacity 0.6
:transparent true
:on $ {}
:click $ fn (e d!) (on-change k d!)
text $ {} (:text title) (:size 4) (:depth 1)
:position $ [] 0 0 4
:material $ {} (:kind :mesh-lambert) (:opacity 0.9) (:transparent true)
:color $ hsluvx 0 30 96
:ns $ %{} :CodeEntry (:doc |)
:code $ quote
ns quatrefoil.app.comp.portal $ :require
quatrefoil.alias :refer $ group box sphere text ambient-light point-light
quatrefoil.core :refer $ defcomp hslx hsluvx
|quatrefoil.app.comp.quat-tree $ %{} :FileEntry
:defs $ {}
|comp-quat-tree $ %{} :CodeEntry (:doc |)
:code $ quote
defcomp comp-quat-tree () $ let
p0 $ quaternion 0 0 0 0
l0 $ quaternion 0 0 30 0
lines $ generate-lines p0 l0 5 :root
group ({})
ambient-light $ {} (:color 0x444422)
point-light $ {} (:color 0xffffff) (:intensity 1.4) (:distance 200)
:position $ [] 20 40 50
group ({}) & $ -> lines
mapcat $ fn (line)
let
from $ :from line
to $ :to line
v $ &q- to from
size $ q-length v
w $ nth to 1
hang $ {} (:from to)
:to $ quaternion w (nth to 2)
+ (nth to 3)
nth (:line line) 3
nth to 4
[]
tube $ {} (:points-fn straight-fn) (:factor line)
:radius $ * 0.04 size
:tubular-segments 4
:radial-segments 4
:position $ v3 -10 0 0
:material $ assoc tube-material :color
pick-color $ :name line
; tube $ {} (:points-fn straight-fn) (:factor hang) (:radius 0.1) (:tubular-segments 4) (:radial-segments 4)
:position $ v3 -10 0 0
:material leaf-material
|generate-lines $ %{} :CodeEntry (:doc |)
:code $ quote
defn generate-lines (base l0 level name)
let
line-to $ &q+ base l0
concat
[] $ {} (:from base) (:to line-to) (:name name) (:line l0)
if (> level 0)
-> transformers $ mapcat
fn (info)
let
trans $ :vector info
name $ :name info
generate-lines line-to (&q* l0 trans) (dec level) name
[]
|leaf-material $ %{} :CodeEntry (:doc |)
:code $ quote
def leaf-material $ {} (:kind :mesh-standard) (:color 0x66cc55) (:opacity 0.5) (:transparent true)
|pick-color $ %{} :CodeEntry (:doc |)
:code $ quote
defn pick-color (name)
case-default name 0xffffff (:a 0xbbaaff) (:b 0x88bbff) (:c 0x77ccaa)
|straight-fn $ %{} :CodeEntry (:doc |)
:code $ quote
defn straight-fn (t factor)
let-sugar
[] w1 x1 y1 z1
&tuple:params $ &map:get factor :from
([] w2 x2 y2 z2)
&tuple:params $ &map:get factor :to
[]
&+ (&* x1 t)
&* x2 $ &- 1 t
&+ (&* y1 t)
&* y2 $ &- 1 t
&+ (&* z1 t)
&* z2 $ &- 1 t
|transformers $ %{} :CodeEntry (:doc |)
:code $ quote
def transformers $ []
{} (:name :a)
:vector $ quaternion 0.7 0.3 0.3 0.1
{} (:name :b)
:vector $ quaternion 0.7 0.2 -0.3 -0.43
{} (:name :c)
:vector $ quaternion 0.4 -0.44 0.12 0.33
|tube-material $ %{} :CodeEntry (:doc |)
:code $ quote
def tube-material $ {} (:kind :mesh-standard) (:color 0xcccc77) (:opacity 1) (:transparent true)
:ns $ %{} :CodeEntry (:doc |)
:code $ quote
ns quatrefoil.app.comp.quat-tree $ :require
quatrefoil.alias :refer $ group box sphere text line tube ambient-light point-light
quatrefoil.core :refer $ defcomp
quaternion.core :refer $ q* &q* q+ &q+ &q- q-length quaternion
quaternion.vector :refer $ v-scale %v3 v3
quatrefoil.app.materials :refer $ cover-line
|quatrefoil.app.comp.shader $ %{} :FileEntry
:defs $ {}
|comp-shader $ %{} :CodeEntry (:doc |)
:code $ quote
defcomp comp-shader () $ group ({})
shader-mesh $ {}
:attributes $ []
{} (:id :position) (:size 3) (:type :f32)
:buffer $ concat &
[] ([] -10 -20 0) ([] 50 0 0) ([] 13 30 0)
{} (:id :color) (:size 4) (:type :u8)
:buffer $ concat &
[] ([] 1 0 0 1) ([] 0 1 0 1) ([] 0 0 1 1 )
:material $ {} (:kind :raw-shader)
:uniforms $ {}
:vertexShader $ inline-shader "\"demo.vert"
:fragmentShader $ inline-shader "\"demo.frag"
:wireframe false
:transparent false
point-light $ {} (:color 0xffffff) (:intensity 1.4) (:distance 200)
:position $ [] 20 40 50
|inline-shader $ %{} :CodeEntry (:doc |)
:code $ quote
defmacro inline-shader (name)
read-file $ str "\"shaders/" name
:ns $ %{} :CodeEntry (:doc |)
:code $ quote
ns quatrefoil.app.comp.shader $ :require
quatrefoil.alias :refer $ group box sphere text line tube ambient-light point-light shader-mesh
quatrefoil.core :refer $ defcomp
quaternion.core :refer $ q* &q* v-scale q+ &q+ &q- q-length
quatrefoil.app.materials :refer $ cover-line
|quatrefoil.app.comp.shapes $ %{} :FileEntry
:defs $ {}
|box-material $ %{} :CodeEntry (:doc |)
:code $ quote
def box-material $ {} (:kind :mesh-lambert) (:color 0x808080) (:opacity 0.6)
|bubble-material $ %{} :CodeEntry (:doc |)
:code $ quote
def bubble-material $ {} (:kind :mesh-basic) (:color 0xffffff) (:opacity 1) (:transparent true)
|comp-bubble $ %{} :CodeEntry (:doc |)
:code $ quote
defn comp-bubble (position)
group ({})
sphere $ {} (:radius 1) (:emissive 0xffffff) (:metalness 0.8) (:color 0xffffff) (:emissiveIntensity 1) (:roughness 0) (:position position) (:material bubble-material)
point-light $ {} (:color 0xffffff) (:intensity 2) (:distance 400) (:position position)
|comp-quilling $ %{} :CodeEntry (:doc |)
:code $ quote
defcomp comp-quilling () $ group ({})
; comp-bubble $ [] 0 -80 0
; comp-bubble $ [] 0 80 0
; comp-bubble $ [] 60 40 0
; comp-bubble $ [] -80 40 0
; comp-bubble $ [] 0 40 80
; comp-bubble $ [] 0 40 -60
; ambient-light $ {} (:color 0x8888dd) (:intensity 0.8)
spot-light $ {} (:color 0xffffff) (:intensity 1)
:position $ [] 0 100 0
:distance 400
spot-light $ {} (:color 0xffffff) (:intensity 1)
:position $ [] 100 0 0
:distance 400
spot-light $ {} (:color 0xffffff) (:intensity 1)
:position $ [] 0 0 100
:distance 400
, &
-> 12 (range)
map $ fn (idx)
parametric $ {} (:func paper-fn) (:data idx) (:slices 80) (:stacks 80)
:position $ [] 0 -40 0
:material paper-material
|comp-shapes $ %{} :CodeEntry (:doc |)
:code $ quote
defcomp comp-shapes () $ group ({})
box $ {} (:width 1) (:height 10) (:depth 10)
:position $ [] 0 0 0
:material $ {} (:kind :mesh-lambert) (:opacity 0.8) (:transparent true) (:color 0xffddaa)
torus $ {} (:r1 10) (:r2 2) (:s1 20) (:s2 40)
:arc $ * 2 &PI
:position $ [] 0 0 0
:material $ {} (:kind :mesh-standard) (:opacity 0.9) (:transparent true) (:roughness 0.5) (:metalness 0.9) (:color 0x9050c0)
shape $ {}
:path $ [] (:: :move-to 0 0) (:: :line-to 7 2) (:: :line-to 16 10) (:: :line-to 20 20) (:: :line-to 8 17) (:: :line-to 4 12) (:: :line-to 0 0)
:position $ [] 20 0 0
:material $ {} (:kind :mesh-lambert) (:opacity 0.9) (:transparent true) (:color 0x249825)
rect-area-light $ {} (:intensity 18) (:width 8) (:color 0xffca00) (:height 30)
:look-at $ [] -2 0 3
:position $ [] 13 0 -4
polyhedron $ {}
:vertices $ [][] (8 4 -2) (4 9 -3) (-5 -2 -4) (4 2 8)
:indices $ [][] (0 1 2) (0 1 3) (0 2 3) (1 2 3)
:radius 10
:detail 0
:position $ [] 20 10 10
:material $ {} (:kind :mesh-lambert) (:opacity 0.9) (:transparent true) (:color 0x9498c5)
parametric $ {} (:func wave-fn) (:slices 40) (:stacks 40)
:position $ [] 20 -10 10
:material $ {} (:kind :mesh-lambert) (:opacity 0.6) (:transparent true) (:color 0xfefea5)
buffer-object $ {}
:vertices $ flat-values (0 0 0) (10 0 0) (5 0 8) (5 8 0)
:indices $ flat-values (0 1 2) (0 2 3) (1 2 3)
:position $ [] 30 -10 10
:material $ {} (:kind :mesh-lambert) (:opacity 0.8) (:transparent true) (:color 0xfe2ec5)
point-light $ {} (:color 0xffffff) (:intensity 1.4) (:distance 200)
:position $ [] 20 40 50
|paper-fn $ %{} :CodeEntry (:doc |)
:code $ quote
defn paper-fn (u v idx)
let
scale 10
t $ * u &PI 1.8
t2 $ * 6.7 t
t3 $ * 4.2 t
r $ + 2
* 0.6 (pow v 3) (pow idx 1.9)
* 0.8 scale $ pow v 3
* 6 $ * (sin t2)
sin $ * 0.5 idx
x $ * r (cos t)
y $ * r (sin t)
h $ +
* v scale (+ 1 u) 4 $ pow 0.9 (/ idx 4)
* 4 $ sin t3
[] x h y
|paper-material $ %{} :CodeEntry (:doc |)
:code $ quote
def paper-material $ {} (:kind :mesh-standard) (:roughness 0.99) (; :emissive 0x6611ee) (:metalness 0.02) (:transparent false) (:color 0x6666ff)
|wave-fn $ %{} :CodeEntry (:doc |)
:code $ quote
defn wave-fn (u v data)
[] (* 8 u)
+
* 1 $ sin
+ (* 5 &PI v) (* 8 &PI u)
* 1 $ cos
+ (* 10 &PI v) (* 3 &PI u)
* 8 v
:ns $ %{} :CodeEntry (:doc |)
:code $ quote
ns quatrefoil.app.comp.shapes $ :require
quatrefoil.alias :refer $ group box sphere point-light scene text torus shape rect-area-light polyhedron plane-reflector parametric buffer-object flat-values ambient-light directional-light spot-light
quatrefoil.core :refer $ defcomp
"\"three" :as THREE
|quatrefoil.app.comp.todolist $ %{} :FileEntry
:defs $ {}
|comp-task $ %{} :CodeEntry (:doc |)
:code $ quote
defcomp comp-task (task idx)
group
{} $ :position
[] 0 (* idx -8) 0
sphere $ {} (:radius 2)
:position $ [] -30 0 0
:material $ {} (:kind :mesh-lambert) (:opacity 0.8) (:transparent true)
:color $ if (:done? task) 0x905055 0x9050ff
:event $ {}
:click $ fn (event dispatch!)
dispatch! :toggle-task $ :id task
box
{} (:width 40) (:height 4) (:depth 1)
:material $ {} (:kind :mesh-lambert) (:color 0xcccccc) (:opacity 0.6) (:transparent true)
:event $ {}
:click $ fn (event dispatch!)
[] (:id task)
prompt-at!
[] (.-pageX event) (.-pageY event)
{} $ :initial (:text task)
fn (text)
dispatch! :edit-task $ [] (:id task) text
text $ {}
:text $ :text task
:size 3
:depth 1
:position $ [] -10 0 0
:material $ {} (:kind :mesh-lambert) (:color 0xffcccc) (:opacity 0.8) (:transparent true)
sphere $ {} (:radius 2)
:position $ [] 30 0 0
:material $ {} (:kind :mesh-lambert) (:opacity 0.8) (:color 0xff5050) (:transparent true)
:event $ {}
:click $ fn (event dispatch!)
dispatch! :delete-task $ :id task
|comp-todolist $ %{} :CodeEntry (:doc |)
:code $ quote
defcomp comp-todolist (tasks)
group ({})
group
{} $ :position ([] 0 30 0)
box $ {} (:width 40) (:height 6) (:depth 1)
:material $ {} (:kind :mesh-lambert) (:color 0xffaaaa) (:opacity 0.9) (:transparent true)
:event $ {}
:click $ fn (e d!) (js/console.log "\"e" e)
prompt-at!
[] (.-pageX e) (.-pageY e)
{} $ :initial "\""
fn (text) (d! :add-task text)
group
{} $ :position ([] 0 20 0)
-> (vals tasks)
map-indexed $ fn (idx task)
[] (:id task) (comp-task task idx)
pairs-map
point-light $ {} (:color 0xffffff) (:intensity 1.4) (:distance 200)
:position $ [] 0 20 50
:ns $ %{} :CodeEntry (:doc |)
:code $ quote
ns quatrefoil.app.comp.todolist $ :require
quatrefoil.alias :refer $ group box sphere point-light scene text
quatrefoil.core :refer $ defcomp
pointed-prompt.core :refer $ prompt-at!
|quatrefoil.app.comp.triflorum $ %{} :FileEntry
:defs $ {}
|comp-triflorum $ %{} :CodeEntry (:doc |)
:code $ quote
defcomp comp-triflorum () $ group ({}) &
-> (range 100)
map $ fn (i)
tube $ {} (:points-fn petal-fn) (:factor i) (:radius 0.06) (:tubularSegments 20) (:radialSegments 8)
:position $ [] 0 0 0
:material $ {} (:kind :mesh-standard) (:color 0x882222) (:opacity 1) (:transparent true)
, &
-> (range 100)
map $ fn (i)
tube $ {} (:points-fn yarn-fn) (:factor i) (:radius 0.3) (:tubularSegments 20) (:radialSegments 8)
:position $ [] 0 0 0
:material $ {} (:kind :mesh-standard) (:color 0xffaaaa) (:opacity 0.27) (:transparent true)
, &
-> (range 12)
map $ fn (i)
let
theta $ * i &PI (sqrt 2) 0.15
polyhedron $ {}
:vertices $ let
r1 1
r2 1
r3 3
th1 $ + theta 1.5
th2 $ - theta 1.5
th3 $ - theta &PI
[][]
* r1 $ cos th1
, 0 $ * r1 (sin th1)
(* r1 (cos th2))
, 0 $ * r1 (sin th2)
(* r3 (cos theta))
, 0.5 $ * r3 (sin theta)
(* r2 (cos th3))
, -2 $ * r2 (sin th3)
:indices $ [][] (0 1 2) (0 1 3) (0 2 3) (1 2 3)
:radius 6
:detail 0
:position $ let
r 8
[]
* r $ cos theta
, -0.3 $ * r (sin theta)
:material $ {} (:kind :mesh-lambert) (:opacity 0.9) (:transparent true) (:color 0x45cc33)
tube $ {} (:points-fn main-branch-fn) (:radius 0.7) (:tubularSegments 20) (:radialSegments 8)
:position $ [] 0 0 0
:material $ {} (:kind :mesh-standard) (:color 0x336622) (:opacity 1) (:transparent true)
point-light $ {} (:color 0xffffff) (:intensity 1.4) (:distance 200)
:position $ [] 0 20 50
|main-branch-fn $ %{} :CodeEntry (:doc |)
:code $ quote
defn main-branch-fn (ratio factor)
[] 0 (* -20 ratio) 0
|petal-fn $ %{} :CodeEntry (:doc |)
:code $ quote
defn petal-fn (ratio i)
let
theta0 $ * i
* &PI $ sqrt 2
theta $ *
+ i $ * ratio 0.4
* &PI $ sqrt 2
v+
let
radius $ +
* (- 1 ratio) 8
* 1.0 $ sqrt (+ 6 i)
v-scale
v3
* radius $ cos theta
*
- 20 $ * i 0.1
, ratio
* radius $ sin theta
, ratio
v-scale
let
radius $ * 0.8
sqrt $ + 6 i
v3
* radius $ cos theta0
*
- 20 $ * i 0.1
, ratio
* radius $ sin theta0
- 1 ratio
|yarn-fn $ %{} :CodeEntry (:doc |)
:code $ quote
defn yarn-fn (ratio i)
let
theta $ *
+ i $ * ratio 4
* &PI $ sqrt 2
[]
* 1.0
sqrt $ + 2 i
cos theta
*
- 18 $ * i 0.1
, ratio
* 1.0
sqrt $ + 2 i
sin theta
:ns $ %{} :CodeEntry (:doc |)
:code $ quote
ns quatrefoil.app.comp.triflorum $ :require
quatrefoil.alias :refer $ group box sphere text line tube polyhedron point-light
quatrefoil.core :refer $ defcomp
quaternion.vector :refer $ v+ v-scale %v3 v3
|quatrefoil.app.main $ %{} :FileEntry
:defs $ {}
|*store $ %{} :CodeEntry (:doc |)
:code $ quote
defatom *store $ {}
:tasks $ {}
100 $ {} (:id 100) (:text "|Initial task") (:done? false)
:states $ {}
:cursor $ []
|dispatch! $ %{} :CodeEntry (:doc |)
:code $ quote
defn dispatch! (op op-data)
if (list? op)
recur :states $ [] op op-data
let
store $ updater @*store op op-data
; js/console.log |Dispatch: op op-data store
reset! *store store
|main! $ %{} :CodeEntry (:doc |)
:code $ quote
defn main! () (load-console-formatter!) (inject-tree-methods) (start-loading-sakura!)
set-perspective-camera! $ {} (:fov 50) (:near 0.1) (:far 10)
:position $ v3 0 1.6 1
:aspect $ / js/window.innerWidth js/window.innerHeight
let
canvas-el $ js/document.querySelector |canvas
init-renderer! canvas-el $ {} (:background 0x110022) (:shadow-map? true)
; :composer-passes $ []
new UnrealBloomPass (new THREE/Vector2 js/window.innerWidth js/window.innerHeight) 1.5 0.4 0.85
render-app!
add-watch *store :changes $ fn (store prev) (render-app!)
set! js/window.onkeydown handle-key-event
render-control!
handle-control-events
init-controls!
println "|App started!"
|reload! $ %{} :CodeEntry (:doc |)
:code $ quote
defn reload! () $ if (some? build-errors) (hud! "\"error" build-errors)
do (hud! "\"ok~" nil) (clear-cache!) (clear-control-loop!) (handle-control-events) (remove-watch *store :changes)
add-watch *store :changes $ fn (store prev) (render-app!)
render-app!
set! js/window.onkeydown handle-key-event
println "|Code updated."
|render-app! $ %{} :CodeEntry (:doc |)
:code $ quote
defn render-app! () (; println "|Render app:")
render-canvas! (comp-container @*store) dispatch!
|start-loading-sakura! $ %{} :CodeEntry (:doc |)
:code $ quote
defn start-loading-sakura! () $ let
loader $ new GLTFLoader
dracoLoader $ new DRACOLoader