-
Notifications
You must be signed in to change notification settings - Fork 163
/
core.cljc
4941 lines (4483 loc) · 176 KB
/
core.cljc
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
(ns ^{:doc "Wrappers and extensions around the core Processing.org API."}
quil.core
#?(:clj
(:import [processing.core PApplet PImage PGraphics PFont PConstants PShape]
[processing.opengl PShader]
[java.awt.event KeyEvent]))
#?(:clj
(:require quil.sketch
[clojure.set]
[quil.helpers.docs :as docs]
[quil.util :as u]
[quil.applet :as ap])
:cljs
(:require clojure.string
org.processingjs.Processing
[quil.sketch :as ap :include-macros true]
[quil.util :as u :include-macros true])))
(def ^{:dynamic true
:private true}
*graphics* nil)
(def ^{:private true} no-fill-prop "no-fill-quil")
(defn
^{:requires-bindings true
:category "Environment"
:subcategory nil
:added "2.0"
:tag PGraphics}
current-graphics
"Graphics currently used for drawing. By default it is sketch graphics,
but if called inside with-graphics macro - graphics passed to the macro
is returned. This method should be used if you need to call some methods
that are not implemented by quil. Example:
(.beginDraw (current-graphics))."
[]
(or *graphics*
#?(:clj (.-g (ap/current-applet))
:cljs (ap/current-applet))))
;; -------------------- PConstants section -----------------------
(u/generate-quil-constants #?(:clj :clj :cljs :cljs)
arc-modes (:open :chord :pie)
shape-modes (:points :lines :triangles :triangle-fan :triangle-strip :quads :quad-strip)
blend-modes (:blend :add :subtract :darkest :lightest :difference :exclusion :multiply
:screen :overlay :replace :hard-light :soft-light :dodge :burn)
color-modes (:rgb :hsb)
image-formats (:rgb :argb :alpha)
ellipse-modes (:center :radius :corner :corners)
hint-options (:enable-depth-test :disable-depth-test
:enable-depth-sort :disable-depth-sort
:enable-depth-mask :disable-depth-mask
:enable-opengl-errors :disable-opengl-errors
:enable-optimized-stroke :disable-optimized-stroke
:enable-stroke-perspective :disable-stroke-perspective
:enable-stroke-pure :disable-stroke-pure
:enable-texture-mipmaps :disable-texture-mipmaps)
image-modes (:corner :corners :center)
rect-modes (:corner :corners :center :radius)
p-shape-modes (:corner :corners :center)
stroke-cap-modes (:square :round :project :model)
stroke-join-modes (:miter :bevel :round)
horizontal-alignment-modes (:left :center :right)
vertical-alignment-modes (:top :bottom :center :baseline)
text-modes (:model :shape)
texture-modes (:image :normal)
texture-wrap-modes (:clamp :repeat)
filter-modes (:threshold :gray :invert :posterize :blur :opaque :erode :dilate)
cursor-modes (:arrow :cross :hand :move :text :wait))
;;; Useful trig constants
#?(:clj (def PI (float Math/PI))
:cljs (def PI (.-PI js/Math)))
(def HALF-PI (/ PI (float 2.0)))
(def THIRD-PI (/ PI (float 3.0)))
(def QUARTER-PI (/ PI (float 4.0)))
(def TWO-PI (* PI (float 2.0)))
(def DEG-TO-RAD (/ PI (float 180.0)))
(def RAD-TO-DEG (/ (float 180.0) PI))
#?(:clj
(def ^{:private true}
KEY-CODES {KeyEvent/VK_UP :up
KeyEvent/VK_DOWN :down
KeyEvent/VK_LEFT :left
KeyEvent/VK_RIGHT :right
KeyEvent/VK_ALT :alt
KeyEvent/VK_CONTROL :control
KeyEvent/VK_SHIFT :shift
KeyEvent/VK_WINDOWS :command
KeyEvent/VK_META :command
KeyEvent/VK_F1 :f1
KeyEvent/VK_F2 :f2
KeyEvent/VK_F3 :f3
KeyEvent/VK_F4 :f4
KeyEvent/VK_F5 :f5
KeyEvent/VK_F6 :f6
KeyEvent/VK_F7 :f7
KeyEvent/VK_F8 :f8
KeyEvent/VK_F9 :f9
KeyEvent/VK_F10 :f10
KeyEvent/VK_F11 :f11
KeyEvent/VK_F12 :f12
KeyEvent/VK_F13 :f13
KeyEvent/VK_F14 :f14
KeyEvent/VK_F15 :f15
KeyEvent/VK_F16 :f16
KeyEvent/VK_F17 :f17
KeyEvent/VK_F18 :f18
KeyEvent/VK_F19 :f19
KeyEvent/VK_F20 :f20
KeyEvent/VK_F21 :f21
KeyEvent/VK_F22 :f22
KeyEvent/VK_F23 :f23
KeyEvent/VK_F24 :f24})
:cljs
(def ^{:private true}
KEY-CODES {38 :up
40 :down
37 :left
39 :right
18 :alt
17 :control
16 :shift
157 :command
112 :f1
113 :f2
114 :f3
115 :f4
116 :f5
117 :f6
118 :f7
119 :f8
120 :f9
121 :f10
122 :f11
123 :f12}))
;; ------------------ end PConstants section ---------------------
#?(:cljs
(defn
^{:require-bindings true
:category "Output"
:subcategory "Text area"
:added "1.0"}
prc-println
"Writes to the text area of the Processing environment's console.
This is often helpful for looking at the data a program is producing.
Each call to this function creates a new line of output.
Individual elements can be separated with quotes (\"\") and joined with the string concatenation operator (+).
Also writes the content of an array to the text area of the Processing environment.
This is often helpful for looking at the data a program is producing.
A new line is put between each element of the array. This function can only print 1D arrays,
but can test to see if the content are null or not null for 2+ dimensional arrays."
[msg]
(.println (ap/current-applet) msg)))
#?(:cljs
(defn
^{:require-bindings true
:category "Output"
:subcategory "Text area"
:added "1.0"}
prc-print
"Writes to the console area of the Processing environment.
This is often helpful for looking at the data a program is producing.
The companion function println() works like print(), but creates a new line of text for each call to the function.
Individual elements can be separated with quotes (\"\") and joined with the addition operator (+). "
[msg]
(.print (ap/current-applet) msg)))
#?(:cljs
(defn
^{:requires-bindings true
:processing-name "getSketchById()"
:category nil
:subcategory nil
:added "1.0"}
get-sketch-by-id
"Returns sketch object by id of canvas element of sketch."
[id]
(.getInstanceById js/Processing id)))
(defmacro with-sketch [applet & body]
(when-not (u/clj-compilation?)
`(quil.sketch/with-sketch ~applet ~@body)))
(defn
^{:requires-bindings true
:category "State"
:subcategory nil
:added "1.0"}
state-atom
"Retrieve sketch-specific state-atom. All changes to the
atom will be reflected in the state.
(set-state! :foo 1)
(state :foo) ;=> 1
(swap! (state-atom) update-in [:foo] inc)
(state :foo) ;=> 2"
#?(:clj ([] (-> (ap/current-applet) meta :state))
:cljs ([] (. (ap/current-applet) -quil))))
(defn
^{:requires-bindings true
:category "State"
:subcategory nil
:added "1.0"}
state
"Retrieve sketch-specific state by key. Must initially call
set-state! to store state. If no parameter passed whole
state map is returned.
(set-state! :foo 1)
(state :foo) ;=> 1
(state) ;=> {:foo 1}"
([] @(state-atom))
([key] (let [state (state)]
(when-not (contains? state key)
(throw #?(:clj (Exception. (str "Unable to find state with key: " key))
:cljs (js/Error (str "Unable to find state with key: " key)))))
(get state key))))
(defn
^{:requires-bindings true
:category "State"
:subcategory nil
:added "1.0"}
set-state!
"Set sketch-specific state. May only be called once (ideally in the
setup fn). Subsequent calls have no effect.
Example:
(set-state! :foo 1 :bar (atom true) :baz (/ (width) 2))"
[& state-vals]
(let [state* (state-atom)]
(when-not @state*
(let [state-map (apply hash-map state-vals)]
(reset! state* state-map)))))
#?(:clj
(defn
^{:requires-bindings false
:processing-name "abs()"
:category "Math"
:subcategory "Calculation"
:added "1.0"}
abs-int
"Calculates the absolute value (magnitude) of a number. The absolute
value of a number is always positive. Takes and returns an int."
[n]
(PApplet/abs (int n))))
#?(:clj
(defn
^{:requires-bindings false
:processing-name "abs()"
:category "Math"
:subcategory "Calculation"
:added "1.0"}
abs-float
"Calculates the absolute value (magnitude) of a number. The absolute
value of a number is always positive. Takes and returns a float."
[n]
(PApplet/abs (float n))))
(defn
^{:requires-bindings false
:processing-name "abs()"
:category "Math"
:subcategory "Calculation"
:added "1.0"}
abs
"Calculates the absolute value (magnitude) of a number. The
absolute value of a number is always positive. Dynamically casts to
an int or float appropriately"
[n]
#?(:clj
(if (u/int-like? n)
(abs-int n)
(abs-float n))
:cljs
(.abs (ap/current-applet) n)))
(defn
^{:requires-bindings false
:processing-name "acos()"
:category "Math"
:subcategory "Trigonometry"
:added "1.0"}
acos
"The inverse of cos, returns the arc cosine of a value. This
function expects the values in the range of -1 to 1 and values are
returned in the range 0 to Math/PI (3.1415927)."
[n]
#?(:clj (PApplet/acos (float n))
:cljs (.acos (ap/current-applet) n)))
(defn
^{:requires-bindings true
:processing-name "alpha()"
:category "Color"
:subcategory "Creating & Reading"
:added "1.0"}
alpha
"Extracts the alpha value from a color."
[color]
(.alpha (current-graphics) (unchecked-int color)))
(defn
^{:requires-bindings true
:processing-name "ambient()"
:category "Lights, Camera"
:subcategory "Material Properties"
:added "1.0"}
ambient-float
"Sets the ambient reflectance for shapes drawn to the screen. This
is combined with the ambient light component of environment. The
color components set through the parameters define the
reflectance. For example in the default color mode, setting x=255,
y=126, z=0, would cause all the red light to reflect and half of the
green light to reflect. Used in combination with emissive, specular,
and shininess in setting the material properties of shapes."
([gray] (.ambient (current-graphics) (float gray)))
([x y z] (.ambient (current-graphics) (float x) (float y) (float z))))
(defn
^{:requires-bindings true
:processing-name "ambient()"
:category "Lights, Camera"
:subcategory "Material Properties"
:added "1.0"}
ambient-int
"Sets the ambient reflectance for shapes drawn to the screen. This
is combined with the ambient light component of environment. The rgb
color components set define the reflectance. Used in combination
with emissive, specular, and shininess in setting the material
properties of shapes."
[rgb]
(.ambient (current-graphics) (int rgb)))
(defn
^{:requires-bindings true
:processing-name "ambient()"
:category "Lights, Camera"
:subcategory "Material Properties"
:added "1.0"}
ambient
"Sets the ambient reflectance for shapes drawn to the screen. This
is combined with the ambient light component of environment. The
color components set through the parameters define the
reflectance. For example in the default color mode, setting x=255,
y=126, z=0, would cause all the red light to reflect and half of the
green light to reflect. Used in combination with emissive, specular,
and shininess in setting the material properties of shapes."
([rgb]
#?(:clj (if (u/int-like? rgb) (ambient-int rgb) (ambient-float rgb))
:cljs (ambient-float rgb)))
([x y z] (ambient-float x y z)))
(defn
^{:requires-bindings true
:processing-name "ambientLight()"
:category "Lights, Camera"
:subcategory "Lights"
:added "1.0"}
ambient-light
"Adds an ambient light. Ambient light doesn't come from a specific direction,
the rays have light have bounced around so much that objects are
evenly lit from all sides. Ambient lights are almost always used in
combination with other types of lights. Lights need to be included
in the draw to remain persistent in a looping program. Placing them
in the setup of a looping program will cause them to only have an
effect the first time through the loop. The effect of the
parameters is determined by the current color mode."
([red green blue]
(.ambientLight (current-graphics) (float red) (float green) (float blue)))
([red green blue x y z]
(.ambientLight (current-graphics) (float red) (float green) (float blue)
(float x) (float y) (float z))))
(defn
^{:requires-bindings true
:processing-name "applyMatrix()"
:category "Transform"
:subcategory nil
:added "1.0"}
apply-matrix
"Multiplies the current matrix by the one specified through the
parameters. This is very slow because it will try to calculate the
inverse of the transform, so avoid it whenever possible. The
equivalent function in OpenGL is glMultMatrix()."
#?(:clj
([n00 n01 n02 n10 n11 n12]
(.applyMatrix (current-graphics)
(float n00) (float n01) (float n02)
(float n10) (float n11) (float n12))))
([n00 n01 n02 n03
n10 n11 n12 n13
n20 n21 n22 n23
n30 n31 n32 n33]
(.applyMatrix (current-graphics)
(float n00) (float n01) (float n02) (float n03)
(float n10) (float n11) (float n12) (float n13)
(float n20) (float n21) (float n22) (float n23)
(float n30) (float n31) (float n32) (float n33))))
(defn
^{:requires-bindings true
:processing-name "arc()"
:category "Shape"
:subcategory "2D Primitives"
:added "1.0"}
arc
"Draws an arc in the display window. Arcs are drawn along the outer
edge of an ellipse defined by the x, y, width and height
parameters. The origin or the arc's ellipse may be changed with the
ellipse-mode function. The start and stop parameters specify the
angles at which to draw the arc. The mode is either :open, :chord or :pie."
([x y width height start stop]
(.arc (current-graphics) (float x) (float y) (float width) (float height)
(float start) (float stop)))
#?(:clj
([x y width height start stop mode]
(let [arc-mode (u/resolve-constant-key mode arc-modes)]
(.arc (current-graphics) (float x) (float y) (float width) (float height)
(float start) (float stop) (int arc-mode))))))
(defn
^{:requires-bindings false
:processing-name "asin()"
:category "Math"
:subcategory "Trigonometry"
:added "1.0"}
asin
"The inverse of sin, returns the arc sine of a value. This function
expects the values in the range of -1 to 1 and values are returned
in the range -PI/2 to PI/2."
[n]
#?(:clj (PApplet/asin (float n))
:cljs (.asin (ap/current-applet) n)))
(defn
^{:requires-bindings false
:processing-name "atan()"
:category "Math"
:subcategory "Trigonometry"
:added "1.0"}
atan
"The inverse of tan, returns the arc tangent of a value. This
function expects the values in the range of -Infinity to
Infinity (exclusive) and values are returned in the range -PI/2 to
PI/2 ."
[n]
#?(:clj (PApplet/atan (float n))
:cljs (.atan (ap/current-applet) n)))
(defn
^{:requires-bindings false
:processing-name "atan2()"
:category "Math"
:subcategory "Trigonometry"
:added "1.0"}
atan2
"Calculates the angle (in radians) from a specified point to the
coordinate origin as measured from the positive x-axis. Values are
returned as a float in the range from PI to -PI. The atan2 function
is most often used for orienting geometry to the position of the
cursor. Note: The y-coordinate of the point is the first parameter
and the x-coordinate is the second due to the structure of
calculating the tangent."
[y x]
#?(:clj (PApplet/atan2 (float y) (float x))
:cljs (.atan2 (ap/current-applet) y x)))
(defn
^{:requires-bindings false
:processing-name "PFont.list()"
:category "Typography"
:subcategory "Loading & Displaying"
:added "1.0"}
available-fonts
"A sequence of strings representing the fonts on this system
available for use.
Because of limitations in Java, not all fonts can be used and some
might work with one operating system and not others. When sharing a
sketch with other people or posting it on the web, you may need to
include a .ttf or .otf version of your font in the data directory of
the sketch because other people might not have the font installed on
their computer. Only fonts that can legally be distributed should be
included with a sketch."
[]
#?(:clj (seq (PFont/list))
:cljs (seq (.list js/PFont))))
(defn
^{:requires-bindings true
:processing-name "background()"
:category "Color"
:subcategory "Setting"
:added "1.0"}
background-float
"Sets the color used for the background of the Processing
window. The default background is light gray. In the draw function,
the background color is used to clear the display window at the
beginning of each frame.
It is not possible to use transparency (alpha) in background colors
with the main drawing surface, however they will work properly with
create-graphics. Converts args to floats."
([gray] (.background (current-graphics) (float gray)))
([gray alpha] (.background (current-graphics) (float gray) (float alpha)))
([r g b] (.background (current-graphics) (float r) (float g) (float b)))
([r g b a] (.background (current-graphics) (float r) (float g) (float b) (float a))))
(defn
^{:requires-bindings true
:processing-name "background()"
:category "Color"
:subcategory "Setting"
:added "1.0"}
background-int
"Sets the color used for the background of the Processing
window. The default background is light gray. In the draw function,
the background color is used to clear the display window at the
beginning of each frame.
It is not possible to use transparency (alpha) in background colors
with the main drawing surface, however they will work properly with
create-graphics. Converts rgb to an int and alpha to a float."
([rgb] (.background (current-graphics) (unchecked-int rgb)))
([rgb alpha] (.background (current-graphics) (unchecked-int rgb) (float alpha))))
(defn
^{:requires-bindings true
:processing-name "background()"
:category "Color"
:subcategory "Setting"
:added "1.0"}
background
"Sets the color used for the background of the Processing
window. The default background is light gray. In the draw function,
the background color is used to clear the display window at the
beginning of each frame.
It is not possible to use transparency (alpha) in background colors
with the main drawing surface, however they will work properly with
create-graphics. Converts args to floats."
#?(:clj ([rgb] (if (u/int-like? rgb) (background-int rgb) (background-float rgb)))
:cljs ([rgb] (.background (current-graphics) rgb)))
#?(:clj ([rgb alpha] (if (u/int-like? rgb) (background-int rgb alpha) (background-float rgb alpha)))
:cljs ([rgb alpha] (.background (current-graphics) rgb alpha)))
([r g b] (background-float r g b))
([r g b a] (background-float r g b a)))
(defn
^{:requires-bindings true
:processing-name "background()"
:category "Color"
:subcategory "Setting"
:added "1.0"}
background-image
"Specify an image to be used as the background for a sketch. Its
width and height must be the same size as the sketch window. Images
used as background will ignore the current tint setting."
[^PImage img]
(.background (current-graphics) img))
(defn
^{:requires-bindings true
:processing-name "beginCamera()"
:category "Lights, Camera"
:subcategory "Camera"
:added "1.0"}
begin-camera
"Sets the matrix mode to the camera matrix so calls such as
translate, rotate, apply-matrix and reset-matrix affect the
camera. begin-camera should always be used with a following
end-camera and pairs of begin-camera and end-camera cannot be
nested.
For most situations the camera function will be sufficient."
[]
(.beginCamera (current-graphics)))
(defn
^{:requires-bindings true
:processing-name "beginContour()"
:category "Shape"
:subcategory "Vertex"
:added "2.0"}
begin-contour
"Use the begin-contour and end-contour function to create negative
shapes within shapes. These functions can only be within a
begin-shape/end-shape pair and they only work with the :p2d and :p3d
renderers."
[]
(.beginContour (current-graphics)))
#?(:clj
(defn
^{:requires-bindings true
:processing-name "beginRaw()"
:category "Output"
:subcategory "Files"
:added "1.0"}
begin-raw
"Enables the creation of vectors from 3D data. Requires
corresponding end-raw command. These commands will grab the shape
data just before it is rendered to the screen. At this stage, your
entire scene is nothing but a long list of individual lines and
triangles. This means that a shape created with sphere method will
be made up of hundreds of triangles, rather than a single object. Or
that a multi-segment line shape (such as a curve) will be rendered
as individual segments."
([renderer filename]
(.beginRaw (ap/current-applet) (ap/resolve-renderer renderer) (u/absolute-path filename)))))
(defn
^{:requires-bindings true
:processing-name "beginShape()"
:category "Shape"
:subcategory "Vertex"
:added "1.0"}
begin-shape
"Enables the creation of complex forms. begin-shape begins recording
vertices for a shape and end-shape stops recording. Use the mode
keyword to specify which shape create from the provided
vertices. With no mode specified, the shape can be any irregular
polygon.
The available mode keywords are :points, :lines, :triangles,
:triangle-fan, :triangle-strip,
:quads, :quad-strip.
After calling the begin-shape function, a series of vertex commands
must follow. To stop drawing the shape, call end-shape. The vertex
function with two parameters specifies a position in 2D and the
vertex function with three parameters specifies a position in
3D. Each shape will be outlined with the current stroke color and
filled with the fill color.
Transformations such as translate, rotate, and scale do not work
within begin-shape. It is also not possible to use other shapes,
such as ellipse or rect within begin-shape."
([] (.beginShape (current-graphics)))
([mode]
(let [mode (u/resolve-constant-key mode shape-modes)]
(.beginShape (current-graphics) (int mode)))))
(defn
^{:requires-bindings true
:processing-name "bezier()"
:category "Shape"
:subcategory "Curves"
:added "1.0"}
bezier
"Draws a Bezier curve on the screen. These curves are defined by a
series of anchor and control points. The first two parameters
specify the first anchor point and the last two parameters specify
the other anchor point. The middle parameters specify the control
points which define the shape of the curve."
([x1 y1 cx1 cy1 cx2 cy2 x2 y2]
(.bezier (current-graphics)
(float x1) (float y1)
(float cx1) (float cy1)
(float cx2) (float cy2)
(float x2) (float y2)))
([x1 y1 z1 cx1 cy1 cz1 cx2 cy2 cz2 x2 y2 z2]
(.bezier (current-graphics)
(float x1) (float y1) (float z1)
(float cx1) (float cy1) (float cz1)
(float cx2) (float cy2) (float cz2)
(float x2) (float y2) (float z2))))
(defn
^{:requires-bindings true
:processing-name "bezierDetail()"
:category "Shape"
:subcategory "Curves"
:added "1.0"}
bezier-detail
"Sets the resolution at which Beziers display. The default value is
20. This function is only useful when using the :p3d or :opengl
renderer as the default (:java2d) renderer does not use this
information."
[detail]
(.bezierDetail (current-graphics) (int detail)))
(defn
^{:requires-bindings true
:processing-name "bezierPoint()"
:category "Shape"
:subcategory "Curves"
:added "1.0"}
bezier-point
"Evaluates the Bezier at point t for points a, b, c, d. The
parameter t varies between 0 and 1, a and d are points on the curve,
and b and c are the control points. This can be done once with the x
coordinates and a second time with the y coordinates to get the
location of a bezier curve at t."
[a b c d t]
(.bezierPoint (current-graphics) (float a) (float b) (float c)
(float d) (float t)))
(defn
^{:requires-bindings true
:processing-name "bezierTangent()"
:category "Shape"
:subcategory "Curves"
:added "1.0"}
bezier-tangent
"Calculates the tangent of a point on a Bezier curve.
(See http://en.wikipedia.org/wiki/Tangent)"
[a b c d t]
(.bezierTangent (current-graphics) (float a) (float b) (float c)
(float d) (float t)))
(defn
^{:requires-bindings true
:processing-name "bezierVertex()"
:category "Shape"
:subcategory "Vertex"
:added "1.0"}
bezier-vertex
"Specifies vertex coordinates for Bezier curves. Each call to
bezier-vertex defines the position of two control points and one
anchor point of a Bezier curve, adding a new segment to a line or
shape. The first time bezier-vertex is used within a begin-shape
call, it must be prefaced with a call to vertex to set the first
anchor point. This function must be used between begin-shape and
end-shape and only when there is no parameter specified to
begin-shape."
([cx1 cy1 cx2 cy2 x y]
(.bezierVertex (current-graphics)
(float cx1) (float cy1)
(float cx2) (float cy2)
(float x) (float y)))
([cx1 cy1 cz1 cx2 cy2 cz2 x y z]
(.bezierVertex (current-graphics)
(float cx1) (float cy1) (float cz1)
(float cx2) (float cy2) (float cz2)
(float x) (float y) (float z))))
(defn
^{:require-binding false
:processing-name "binary()"
:category "Data"
:subcategory "Conversion"
:added "1.0"}
binary
"Returns a string representing the binary value of an int, char or
byte. When converting an int to a string, it is possible to specify
the number of digits used."
([val]
#?(:clj (PApplet/binary (int val))
:cljs (.binary (ap/current-applet) val)))
([val num-digits]
#?(:clj (PApplet/binary (int val) (int num-digits))
:cljs (.binary (ap/current-applet) val num-digits))))
(defn
^{:requires-bindings true
:processing-name "blend()"
:category "Image"
:subcategory "Pixels"
:added "1.0"}
blend
"Blends a region of pixels from one image into another with full alpha
channel support. If src is not specified it defaults to current-graphics.
If dest is not specified it defaults to current-graphics.
Note: blend-mode function is recommended to use instead of this one.
Available blend modes are:
:blend - linear interpolation of colours: C = A*factor + B
:add - additive blending with white clip:
C = min(A*factor + B, 255)
:subtract - subtractive blending with black clip:
C = max(B - A*factor, 0)
:darkest - only the darkest colour succeeds:
C = min(A*factor, B)
:lightest - only the lightest colour succeeds:
C = max(A*factor, B)
:difference - subtract colors from underlying image.
:exclusion - similar to :difference, but less extreme.
:multiply - Multiply the colors, result will always be darker.
:screen - Opposite multiply, uses inverse values of the colors.
:overlay - A mix of :multiply and :screen. Multiplies dark values
and screens light values.
:hard-light - :screen when greater than 50% gray, :multiply when
lower.
:soft-light - Mix of :darkest and :lightest. Works like :overlay,
but not as harsh.
:dodge - Lightens light tones and increases contrast, ignores
darks.
Called \"Color Dodge\" in Illustrator and Photoshop.
:burn - Darker areas are applied, increasing contrast, ignores
lights. Called \"Color Burn\" in Illustrator and
Photoshop."
([x y width height dx dy dwidth dheight mode]
(blend (current-graphics) (current-graphics) x y width height dx dy dwidth dheight mode))
([^PImage src-img x y width height dx dy dwidth dheight mode]
(blend src-img (current-graphics) x y width height dx dy dwidth dheight mode))
([^PImage src-img ^PImage dest-img x y width height dx dy dwidth dheight mode]
(let [mode (u/resolve-constant-key mode blend-modes)]
(.blend dest-img src-img (int x) (int y) (int width) (int height)
(int dx) (int dy) (int dwidth) (int dheight) (int mode)))))
(defn
^{:requires-bindings false
:processing-name "blendColor()"
:processing-link nil
:category "Color"
:subcategory "Creating & Reading"
:added "1.0"}
blend-color
"Blends two color values together based on the blending mode given specified
with the mode keyword.
Available blend modes are:
:blend - linear interpolation of colours: C = A*factor + B
:add - additive blending with white clip:
C = min(A*factor + B, 255)
:subtract - subtractive blending with black clip:
C = max(B - A*factor, 0)
:darkest - only the darkest colour succeeds:
C = min(A*factor, B)
:lightest - only the lightest colour succeeds:
C = max(A*factor, B)
:difference - subtract colors from underlying image.
:exclusion - similar to :difference, but less extreme.
:multiply - Multiply the colors, result will always be darker.
:screen - Opposite multiply, uses inverse values of the colors.
:overlay - A mix of :multiply and :screen. Multiplies dark values
and screens light values.
:hard-light - :screen when greater than 50% gray, :multiply when
lower.
:soft-light - Mix of :darkest and :lightest. Works like :overlay,
but not as harsh.
:dodge - Lightens light tones and increases contrast, ignores
darks.
Called \"Color Dodge\" in Illustrator and Photoshop.
:burn - Darker areas are applied, increasing contrast, ignores
lights. Called \"Color Burn\" in Illustrator and
Photoshop."
[c1 c2 mode]
(let [mode (u/resolve-constant-key mode blend-modes)]
#?(:clj (PApplet/blendColor (unchecked-int c1) (unchecked-int c2) (int mode))
:cljs (.blendColor (current-graphics) c1 c2 mode))))
#?(:clj
(defn
^{:requires-bindings true
:processing-name "blendMode()"
:category "Image"
:subcategory "Rendering"
:added "2.0"}
blend-mode
"Blends the pixels in the display window according to the defined mode.
There is a choice of the following modes to blend the source pixels (A)
with the ones of pixels already in the display window (B):
:blend - linear interpolation of colours: C = A*factor + B
:add - additive blending with white clip:
C = min(A*factor + B, 255)
:subtract - subtractive blending with black clip:
C = max(B - A*factor, 0)
:darkest - only the darkest colour succeeds:
C = min(A*factor, B)
:lightest - only the lightest colour succeeds:
C = max(A*factor, B)
:exclusion - similar to :difference, but less extreme.
:multiply - Multiply the colors, result will always be darker.
:screen - Opposite multiply, uses inverse values of the colors.
:replace - the pixels entirely replace the others and don't utilize
alpha (transparency) values
Note: :hard-light, :soft-light, :dodge, :overlay, :dodge, :burn, :difference
modes are not supported by this function.
factor is alpha value of pixel being drawed"
([mode]
(let [mode (u/resolve-constant-key mode blend-modes)]
(.blendMode (current-graphics) mode)))))
(defn
^{:requires-bindings true
:processing-name "blue()"
:category "Color"
:subcategory "Creating & Reading"
:added "1.0"}
blue
"Extracts the blue value from a color, scaled to match current color-mode.
Returns a float."
[color]
(.blue (current-graphics) (unchecked-int color)))
(defn
^{:requires-bindings true
:processing-name "box()"
:category "Shape"
:subcategory "3D Primitives"
:added "1.0"}
box
"Creates an extruded rectangle."
([size] (.box (current-graphics) (float size)))
([width height depth] (.box (current-graphics) (float width) (float height) (float depth))))
(defn
^{:requires-bindings true
:processing-name "brightness()"
:category "Color"
:subcategory "Creating & Reading"
:added "1.0"}
brightness
"Extracts the brightness value from a color. Returns a float."
[color]
(.brightness (current-graphics) (unchecked-int color)))
(defn
^{:requires-bindings true
:processing-name "camera()"
:category "Lights, Camera"
:subcategory "Camera"
:added "1.0"}
camera
"Sets the position of the camera through setting the eye position,
the center of the scene, and which axis is facing upward. Moving the
eye position and the direction it is pointing (the center of the
scene) allows the images to be seen from different angles. The
version without any parameters sets the camera to the default
position, pointing to the center of the display window with the Y
axis as up. The default values are:
eyeX: (/ (width) 2.0)
eyeY: (/ (height) 2.0)
eyeZ: (/ (/ (height) 2.0) (tan (/ (* Math/PI 60.0) 360.0)))
centerX: (/ (width) 2.0)
centerY: (/ (height) 2.0)
centerZ: 0
upX: 0
upY: 1
upZ: 0
Similar imilar to gluLookAt() in OpenGL, but it first clears the
current camera settings."
([] (.camera (current-graphics)))
([eyeX eyeY eyeZ centerX centerY centerZ upX upY upZ]
(.camera (current-graphics) (float eyeX) (float eyeY) (float eyeZ)
(float centerX) (float centerY) (float centerZ)
(float upX) (float upY) (float upZ))))
(defn
^{:requires-bindings false
:processing-name "ceil()"
:category "Math"
:subcategory "Calculation"
:added "1.0"}
ceil
"Calculates the closest int value that is greater than or equal to
the value of the parameter. For example, (ceil 9.03) returns the
value 10."
[n]
#?(:clj (PApplet/ceil (float n))
:cljs (.ceil (ap/current-applet) n)))
#?(:clj
(defn
^{:requires-bindings true
:processing-name "clear()"
:category "Color"
:subcategory "Setting"
:added "2.3.0"}
clear
"Clears the pixels within a buffer. This function only works on
graphics objects created with the (create-graphics) function meaning
that you should call it only inside (with-graphics) macro. Unlike
the main graphics context (the display window), pixels in additional
graphics areas created with (create-graphics) can be entirely or
partially transparent. This function clears everything in a graphics
object to make all of the pixels 100% transparent."
[]
(.clear (current-graphics))))
#?(:clj
(defn
^{:requires-bindings true