/
core.cljc
4853 lines (4444 loc) · 177 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
cljsjs.p5
[quil.sketch :as ap :include-macros true]
[quil.util :as u :include-macros true])))
(def ^{:dynamic true}
*graphics* nil)
(def ^{:private true} no-fill-prop "no-fill-quil")
(declare pixels)
(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)
#?@(:cljs (angle-modes (:radians :degrees)))
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)
#?@(:clj (color-modes (:rgb :hsb))
:cljs (color-modes (:rgb :hsb :hsl)))
image-formats (:rgb :argb :alpha)
ellipse-modes (:center :radius :corner :corners)
hint-options (:enable-async-saveframe :disable-async-saveframe
: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)
#?@(:clj (text-modes (:model :shape)))
#?@(:cljs (text-styles (:normal :italic :bold)))
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}))
(def ^{:private true}
KEY-MAP {" " :space})
;; ------------------ end PConstants section ---------------------
#?(: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]
(if-let [elem (.getElementById js/document id)]
(.-processing-obj elem)
nil)))
(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- internal-state
"Returns atom representing internal sketch state. Can be used by
functions to save implementation-specific state. This state is
supposed to be visible to users."
[]
#?(:clj (-> (ap/current-applet) meta :internal-state)
:cljs (. (ap/current-applet) -quil-internal-state)))
(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 function). 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)))))
#?(:cljs
(defn
^{:requires-bindings true
:category "Shader"
:subcategory nil
:added "3.0.0"}
set-uniform
"Set a uniform variables inside a shader to modify the effect
while the program is running."
[shader uniform-name data]
(.setUniform shader uniform-name data)))
(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 for Clojure."
[n]
#?(:clj
(if (u/int-like? n)
(PApplet/abs (int n))
(PApplet/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) color))
(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 `r=255,
g=126, b=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]
#?(:clj (.ambient (current-graphics) (float gray))
:cljs (.ambientMaterial (current-graphics) (float gray))))
([r g b]
#?(:clj (.ambient (current-graphics) (float r) (float g) (float b))
:cljs (.ambientMaterial (current-graphics) (float r) (float g) (float b)))))
(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 of 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))))
#?(:cljs
(defn
^{:requires-bindings true
:processing-name "angleMode()"
:category "Math"
:subcategory "Trigonometry"
:added "2.8.0"}
angle-mode
"Sets the current mode of p5 to given `mode`.
Options are:
* `:radians` **(default)**
* `:degrees`"
([mode]
(let [mode (u/resolve-constant-key mode angle-modes)]
(.angleMode (current-graphics) mode)))))
(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()`.
Note that cljs has only 2d version and arguments differ see
https://p5js.org/reference/#/p5/applyMatrix"
#?(:clj
([n00 n01 n02 n10 n11 n12]
(.applyMatrix (current-graphics)
(float n00) (float n01) (float n02)
(float n10) (float n11) (float n12))))
#?(:clj
([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))))
#?(:cljs
([a b c d e f]
(.applyMatrix (current-graphics)
(float a) (float b) (float c)
(float d) (float e) (float f)))))
(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)))
([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) 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)))
#?(:clj
(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."
[]
(seq (PFont/list))))
(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`."
([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-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 "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 used 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 to 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 (.toString val 2)))
([val num-digits]
#?(:clj (PApplet/binary (int val) (int num-digits))
:cljs (let [full (binary val)]
(subs full (- (count full) num-digits) (count full))))))
(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: it is recommended to use the [[blend-mode]] function 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)
* `: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.
In clj the following blend modes are also supported:
`:subtract` - subtractive blending with black clip:
C = max(B - A*factor, 0)
In cljs the following blend modes are also supported:
`:replace` - the pixels entirely replace the others and don't utilize
alpha (transparency) values."
([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) mode))))
#?(:clj
(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)]
(PApplet/blendColor (u/clj-unchecked-int c1) (u/clj-unchecked-int c2) (int mode)))))
(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)
* `: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.
* `:replace` - the pixels entirely replace the others and don't utilize
alpha (transparency) values.
* `:overlay` - 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.
* `:burn` - darker areas are applied, increasing contrast, ignores
lights.
Note: in clj `:hard-light`, `:soft-light`, `:overlay`, `:dodge`, `:burn`
modes are not supported. In cljs `:subtract` mode is not supported.
factor is the alpha value of the pixel being drawn"
([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) (u/clj-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) (u/clj-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 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)))
(defn
^{:requires-bindings true
:processing-name "clear()"
:category "Color"
:subcategory "Setting"
:added "2.4.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
:processing-name "clip()"
:category "Rendering"
:subcategory nil
:added "2.4.0"}
clip
"Limits the rendering to the boundaries of a rectangle defined by
the parameters. The boundaries are drawn based on the state of
the [[image-mode]] function, either `:corner`, `:corners`, or `:center`.
To disable use [[no-clip]]."
[x y w h]
(.clip (current-graphics) (float x) (float y) (float w) (float h))))
(defn
^{:requires-bindings true
:processing-name "color()"
:category "Color"
:subcategory "Creating & Reading"
:added "1.0"}
color
"Creates an integer representation of a color. The parameters are
interpreted as RGB or HSB values depending on the current
[[color-mode]]. The default mode is RGB values from 0 to 255 and
therefore, the function call `(color 255 204 0)` will return a bright
yellow. Args are cast to floats.
* r - red or hue value
* g - green or saturation value
* b - blue or brightness value
* a - alpha value"
([gray] (.color (current-graphics) (float gray)))
([gray alpha] (.color (current-graphics) (float gray) (float alpha)))
([r g b] (.color (current-graphics) (float r) (float g) (float b)))
([r g b a] (.color (current-graphics) (float r) (float g) (float b) (float a))))
(defn
^{:requires-bindings true
:processing-name "colorMode()"
:category "Color"
:subcategory "Creating & Reading"
:added "1.0"}
color-mode
"Changes the way Processing interprets color data. Available modes
are `:rgb` and `:hsb` (and `:hsl` in clojurescript).
By default, the parameters for [[fill]], [[stroke]],
[[background]], and [[color]] are defined by values between 0 and 255 using
the `:rgb` color model. The [[color-mode]] function is used to change the
numerical range used for specifying colors and to switch color
systems. For example, calling
`(color-mode :rgb 1.0)` will specify that values are specified between
0 and 1. The limits for defining colors are altered by setting the
parameters range1, range2, range3, and range 4."
([mode]
(let [mode (u/resolve-constant-key mode color-modes)]
(.colorMode (current-graphics) mode #?(:cljs 255))))
([mode max]
(let [mode (u/resolve-constant-key mode color-modes)]
(.colorMode (current-graphics) mode (float max))))
([mode max-x max-y max-z]
(let [mode (u/resolve-constant-key mode color-modes)]
(.colorMode (current-graphics) mode (float max-x) (float max-y) (float max-z))))
([mode max-x max-y max-z max-a]
(let [mode (u/resolve-constant-key mode color-modes)]
(.colorMode (current-graphics) mode (float max-x) (float max-y) (float max-z) (float max-a)))))
#?(:cljs
(defn
^{:requires-bindings true
:processing-name "cone()"
:category "Shape"