processing 0.5.32 → 0.5.34
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ChangeLog.md +49 -1
- data/VERSION +1 -1
- data/lib/processing/all.rb +3 -1
- data/lib/processing/context.rb +232 -16
- data/lib/processing/events.rb +22 -0
- data/lib/processing/font.rb +5 -0
- data/lib/processing/graphics.rb +11 -2
- data/lib/processing/graphics_context.rb +968 -74
- data/lib/processing/image.rb +92 -1
- data/lib/processing/shader.rb +29 -16
- data/lib/processing/shape.rb +268 -12
- data/lib/processing/vector.rb +126 -0
- data/lib/processing/window.rb +98 -58
- data/processing.gemspec +4 -4
- data/test/helper.rb +5 -2
- data/test/p5.rb +1 -1
- data/test/test_font.rb +1 -1
- data/test/test_graphics_context.rb +442 -8
- data/test/test_utility.rb +0 -19
- metadata +12 -11
@@ -25,6 +25,14 @@ module Processing
|
|
25
25
|
#
|
26
26
|
TAU = PI * 2
|
27
27
|
|
28
|
+
# Processing mode for renderMode().
|
29
|
+
#
|
30
|
+
PROCESSING = :processing
|
31
|
+
|
32
|
+
# p5.js mode for renderMode().
|
33
|
+
#
|
34
|
+
P5JS = :p5js
|
35
|
+
|
28
36
|
# RGBA format for createImage().
|
29
37
|
#
|
30
38
|
RGBA = :rgba
|
@@ -115,96 +123,127 @@ module Processing
|
|
115
123
|
REPLACE = :replace
|
116
124
|
|
117
125
|
# Key code or Mode for textAlign().
|
126
|
+
#
|
118
127
|
LEFT = :left
|
119
128
|
|
120
129
|
# Key code or Mode for textAlign().
|
130
|
+
#
|
121
131
|
RIGHT = :right
|
122
132
|
|
123
133
|
# Mode for textAlign().
|
134
|
+
#
|
124
135
|
TOP = :top
|
125
136
|
|
126
137
|
# Mode for textAlign().
|
138
|
+
#
|
127
139
|
BOTTOM = :bottom
|
128
140
|
|
129
141
|
# Mode for textAlign().
|
142
|
+
#
|
130
143
|
BASELINE = :baseline
|
131
144
|
|
132
145
|
# Mode for textureMode().
|
146
|
+
#
|
133
147
|
IMAGE = :image
|
134
148
|
|
135
149
|
# Mode for textureMode().
|
150
|
+
#
|
136
151
|
NORMAL = :normal
|
137
152
|
|
138
153
|
# Mode for textureWrap().
|
154
|
+
#
|
139
155
|
CLAMP = :clamp
|
140
156
|
|
141
157
|
# Mode for textureWrap().
|
158
|
+
#
|
142
159
|
REPEAT = :repeat
|
143
160
|
|
144
161
|
# Filter type for filter()
|
162
|
+
#
|
145
163
|
THRESHOLD = :threshold
|
146
164
|
|
147
165
|
# Filter type for filter()
|
166
|
+
#
|
148
167
|
GRAY = :gray
|
149
168
|
|
150
169
|
# Filter type for filter()
|
170
|
+
#
|
151
171
|
INVERT = :invert
|
152
172
|
|
153
173
|
# Filter type for filter()
|
174
|
+
#
|
154
175
|
BLUR = :blur
|
155
176
|
|
156
177
|
# Shape mode for createShape()
|
178
|
+
#
|
157
179
|
LINE = :line
|
158
180
|
|
159
181
|
# Shape mode for createShape()
|
182
|
+
#
|
160
183
|
RECT = :rect
|
161
184
|
|
162
185
|
# Shape mode for createShape()
|
186
|
+
#
|
163
187
|
ELLIPSE = :ellipse
|
164
188
|
|
165
189
|
# Shape mode for createShape()
|
190
|
+
#
|
166
191
|
ARC = :arc
|
167
192
|
|
168
193
|
# Shape mode for createShape()
|
194
|
+
#
|
169
195
|
TRIANGLE = :triangle
|
170
196
|
|
171
197
|
# Shape mode for createShape()
|
198
|
+
#
|
172
199
|
QUAD = :quad
|
173
200
|
|
174
201
|
# Shape mode for createShape()
|
202
|
+
#
|
175
203
|
GROUP = :group
|
176
204
|
|
177
205
|
# Shape mode for beginShape()
|
206
|
+
#
|
178
207
|
POINTS = :points
|
179
208
|
|
180
209
|
# Shape mode for beginShape()
|
210
|
+
#
|
181
211
|
LINES = :lines
|
182
212
|
|
183
213
|
# Shape mode for beginShape()
|
214
|
+
#
|
184
215
|
TRIANGLES = :triangles
|
185
216
|
|
186
217
|
# Shape mode for beginShape()
|
218
|
+
#
|
187
219
|
TRIANGLE_FAN = :triangle_fan
|
188
220
|
|
189
221
|
# Shape mode for beginShape()
|
222
|
+
#
|
190
223
|
TRIANGLE_STRIP = :triangle_strip
|
191
224
|
|
192
225
|
# Shape mode for beginShape()
|
226
|
+
#
|
193
227
|
QUADS = :quads
|
194
228
|
|
195
229
|
# Shape mode for beginShape()
|
230
|
+
#
|
196
231
|
QUAD_STRIP = :quad_strip
|
197
232
|
|
198
233
|
# Shape mode for beginShape()
|
234
|
+
#
|
199
235
|
TESS = :tess
|
200
236
|
|
201
237
|
# OPEN flag for endShape()
|
238
|
+
#
|
202
239
|
OPEN = :open
|
203
240
|
|
204
241
|
# CLOSE flag for endShape()
|
242
|
+
#
|
205
243
|
CLOSE = :close
|
206
244
|
|
207
245
|
# Key codes.
|
246
|
+
#
|
208
247
|
ENTER = :enter
|
209
248
|
SPACE = :space
|
210
249
|
TAB = :tab
|
@@ -267,28 +306,42 @@ module Processing
|
|
267
306
|
|
268
307
|
# @private
|
269
308
|
def init__(image, painter)
|
270
|
-
@drawing__
|
271
|
-
@
|
272
|
-
@
|
273
|
-
@
|
274
|
-
@
|
275
|
-
@
|
276
|
-
@
|
277
|
-
@
|
278
|
-
@
|
279
|
-
@
|
280
|
-
@
|
281
|
-
@
|
282
|
-
@
|
283
|
-
@
|
284
|
-
@
|
285
|
-
@
|
286
|
-
@
|
287
|
-
@
|
288
|
-
@
|
309
|
+
@drawing__ = false
|
310
|
+
@renderMode__ = nil
|
311
|
+
@p5jsMode__ = false
|
312
|
+
@colorMode__ = nil
|
313
|
+
@hsbColor__ = false
|
314
|
+
@colorMaxes__ = [1.0] * 4
|
315
|
+
@angleMode__ = nil
|
316
|
+
@toRad__ = 1.0
|
317
|
+
@toDeg__ = 1.0
|
318
|
+
@fromRad__ = 1.0
|
319
|
+
@fromDeg__ = 1.0
|
320
|
+
@rectMode__ = nil
|
321
|
+
@ellipseMode__ = nil
|
322
|
+
@imageMode__ = nil
|
323
|
+
@shapeMode__ = nil
|
324
|
+
@blendMode__ = nil
|
325
|
+
@curveDetail__ = nil
|
326
|
+
@curveTightness__ = nil
|
327
|
+
@bezierDetail__ = nil
|
328
|
+
@textAlignH__ = nil
|
329
|
+
@textAlignV__ = nil
|
330
|
+
@textFont__ = nil
|
331
|
+
@tint__ = nil
|
332
|
+
@filter__ = nil
|
333
|
+
@pixels__ = nil
|
334
|
+
@random__ = nil
|
335
|
+
@nextGaussian__ = nil
|
336
|
+
@noiseSeed__ = nil
|
337
|
+
@noiseOctaves__ = nil
|
338
|
+
@noiseFallOff__ = nil
|
339
|
+
@matrixStack__ = []
|
340
|
+
@styleStack__ = []
|
289
341
|
|
290
342
|
updateCanvas__ image, painter
|
291
343
|
|
344
|
+
renderMode PROCESSING
|
292
345
|
colorMode RGB, 255
|
293
346
|
angleMode RADIANS
|
294
347
|
rectMode CORNER
|
@@ -303,10 +356,16 @@ module Processing
|
|
303
356
|
textureMode IMAGE
|
304
357
|
textureWrap CLAMP
|
305
358
|
|
306
|
-
fill
|
307
|
-
stroke
|
308
|
-
strokeWeight
|
359
|
+
fill 255
|
360
|
+
stroke 0
|
361
|
+
strokeWeight 1
|
309
362
|
noTint
|
363
|
+
curveDetail 20
|
364
|
+
curveTightness 0
|
365
|
+
bezierDetail 20
|
366
|
+
randomSeed Random.new_seed
|
367
|
+
noiseSeed Random.new_seed
|
368
|
+
noiseDetail 4, 0.5
|
310
369
|
end
|
311
370
|
|
312
371
|
# @private
|
@@ -322,6 +381,26 @@ module Processing
|
|
322
381
|
@matrixStack__.clear
|
323
382
|
@styleStack__.clear
|
324
383
|
@drawing__ = true
|
384
|
+
setupMatrix__
|
385
|
+
end
|
386
|
+
|
387
|
+
# @private
|
388
|
+
def setupMatrix__()
|
389
|
+
w, h = width.to_f, height.to_f
|
390
|
+
x, y = w / 2.0, h / 2.0
|
391
|
+
|
392
|
+
fov, z = nil
|
393
|
+
if @p5jsMode__
|
394
|
+
z = 800
|
395
|
+
fov = degrees Math.atan(y / z) * 2.0
|
396
|
+
else
|
397
|
+
fov = 60
|
398
|
+
z = y / Math.tan(radians(fov) / 2.0)
|
399
|
+
end
|
400
|
+
|
401
|
+
@painter__.matrix =
|
402
|
+
Rays::Matrix.perspective(fov, w / h, z / 10.0, z * 10.0) *
|
403
|
+
Rays::Matrix.look_at(x, y, z, x, y, 0)
|
325
404
|
end
|
326
405
|
|
327
406
|
# @private
|
@@ -334,6 +413,9 @@ module Processing
|
|
334
413
|
#
|
335
414
|
# @return [Numeric] width
|
336
415
|
#
|
416
|
+
# @see https://processing.org/reference/width.html
|
417
|
+
# @see https://p5js.org/reference/#/p5/width
|
418
|
+
#
|
337
419
|
def width()
|
338
420
|
getInternal__.width
|
339
421
|
end
|
@@ -342,6 +424,9 @@ module Processing
|
|
342
424
|
#
|
343
425
|
# @return [Numeric] height
|
344
426
|
#
|
427
|
+
# @see https://processing.org/reference/height.html
|
428
|
+
# @see https://p5js.org/reference/#/p5/height
|
429
|
+
#
|
345
430
|
def height()
|
346
431
|
getInternal__.height
|
347
432
|
end
|
@@ -350,6 +435,8 @@ module Processing
|
|
350
435
|
#
|
351
436
|
# @return [Numeric] width
|
352
437
|
#
|
438
|
+
# @see https://processing.org/reference/pixelWidth.html
|
439
|
+
#
|
353
440
|
def pixelWidth()
|
354
441
|
width * pixelDensity
|
355
442
|
end
|
@@ -358,6 +445,8 @@ module Processing
|
|
358
445
|
#
|
359
446
|
# @return [Numeric] height
|
360
447
|
#
|
448
|
+
# @see https://processing.org/reference/pixelHeight.html
|
449
|
+
#
|
361
450
|
def pixelHeight()
|
362
451
|
height * pixelDensity
|
363
452
|
end
|
@@ -366,10 +455,27 @@ module Processing
|
|
366
455
|
#
|
367
456
|
# @return [Numeric] pixel density
|
368
457
|
#
|
458
|
+
# @see https://processing.org/reference/pixelDensity_.html
|
459
|
+
# @see https://p5js.org/reference/#/p5/pixelDensity
|
460
|
+
#
|
369
461
|
def pixelDensity()
|
370
462
|
@painter__.pixel_density
|
371
463
|
end
|
372
464
|
|
465
|
+
# Sets render mode.
|
466
|
+
#
|
467
|
+
# @param mode [PROCESSING, P5JS] compatible to Processing or p5.js
|
468
|
+
#
|
469
|
+
# @return [PROCESSING, P5JS] current mode
|
470
|
+
#
|
471
|
+
def renderMode(mode = nil)
|
472
|
+
if mode
|
473
|
+
@renderMode__ = mode
|
474
|
+
@p5jsMode__ = mode == P5JS
|
475
|
+
end
|
476
|
+
@renderMode__
|
477
|
+
end
|
478
|
+
|
373
479
|
# Sets color mode and max color values.
|
374
480
|
#
|
375
481
|
# @overload colorMode(mode)
|
@@ -386,6 +492,9 @@ module Processing
|
|
386
492
|
#
|
387
493
|
# @return [RGB, HSB] current mode
|
388
494
|
#
|
495
|
+
# @see https://processing.org/reference/colorMode_.html
|
496
|
+
# @see https://p5js.org/reference/#/p5/colorMode
|
497
|
+
#
|
389
498
|
def colorMode(mode = nil, *maxes)
|
390
499
|
if mode != nil
|
391
500
|
mode = mode.downcase.to_sym
|
@@ -417,6 +526,9 @@ module Processing
|
|
417
526
|
#
|
418
527
|
# @return [Integer] the rgba color value
|
419
528
|
#
|
529
|
+
# @see https://processing.org/reference/color_.html
|
530
|
+
# @see https://p5js.org/reference/#/p5/color
|
531
|
+
#
|
420
532
|
def color(*args)
|
421
533
|
toRGBA__(*args)
|
422
534
|
.map {|n| (n * 255).to_i.clamp 0, 255}
|
@@ -429,6 +541,9 @@ module Processing
|
|
429
541
|
#
|
430
542
|
# @return [Numeric] the red value
|
431
543
|
#
|
544
|
+
# @see https://processing.org/reference/red_.html
|
545
|
+
# @see https://p5js.org/reference/#/p5/red
|
546
|
+
#
|
432
547
|
def red(color)
|
433
548
|
((color >> 16) & 0xff) / 255.0 * @colorMaxes__[0]
|
434
549
|
end
|
@@ -439,6 +554,9 @@ module Processing
|
|
439
554
|
#
|
440
555
|
# @return [Numeric] the green value
|
441
556
|
#
|
557
|
+
# @see https://processing.org/reference/green_.html
|
558
|
+
# @see https://p5js.org/reference/#/p5/green
|
559
|
+
#
|
442
560
|
def green(color)
|
443
561
|
((color >> 8) & 0xff) / 255.0 * @colorMaxes__[1]
|
444
562
|
end
|
@@ -449,6 +567,9 @@ module Processing
|
|
449
567
|
#
|
450
568
|
# @return [Numeric] the blue value
|
451
569
|
#
|
570
|
+
# @see https://processing.org/reference/blue_.html
|
571
|
+
# @see https://p5js.org/reference/#/p5/blue
|
572
|
+
#
|
452
573
|
def blue(color)
|
453
574
|
(color & 0xff) / 255.0 * @colorMaxes__[2]
|
454
575
|
end
|
@@ -459,19 +580,64 @@ module Processing
|
|
459
580
|
#
|
460
581
|
# @return [Numeric] the red value
|
461
582
|
#
|
583
|
+
# @see https://processing.org/reference/alpha_.html
|
584
|
+
# @see https://p5js.org/reference/#/p5/alpha
|
585
|
+
#
|
462
586
|
def alpha(color)
|
463
587
|
((color >> 24) & 0xff) / 255.0 * @colorMaxes__[3]
|
464
588
|
end
|
465
589
|
|
590
|
+
# Returns the hue value of the color.
|
591
|
+
#
|
592
|
+
# @param color [Numeric] color value
|
593
|
+
#
|
594
|
+
# @return [Numeric] the hue value
|
595
|
+
#
|
596
|
+
# @see https://processing.org/reference/hue_.html
|
597
|
+
# @see https://p5js.org/reference/#/p5/hue
|
598
|
+
#
|
599
|
+
def hue(color)
|
600
|
+
h, = toRawColor__(color).to_hsv
|
601
|
+
h * (@hsbColor__ ? @colorMaxes__[0] : 1)
|
602
|
+
end
|
603
|
+
|
604
|
+
# Returns the saturation value of the color.
|
605
|
+
#
|
606
|
+
# @param color [Numeric] color value
|
607
|
+
#
|
608
|
+
# @return [Numeric] the saturation value
|
609
|
+
#
|
610
|
+
# @see https://processing.org/reference/saturation_.html
|
611
|
+
# @see https://p5js.org/reference/#/p5/saturation
|
612
|
+
#
|
613
|
+
def saturation(color)
|
614
|
+
_, s, = toRawColor__(color).to_hsv
|
615
|
+
s * (@hsbColor__ ? @colorMaxes__[1] : 1)
|
616
|
+
end
|
617
|
+
|
618
|
+
# Returns the brightness value of the color.
|
619
|
+
#
|
620
|
+
# @param color [Numeric] color value
|
621
|
+
#
|
622
|
+
# @return [Numeric] the brightness value
|
623
|
+
#
|
624
|
+
# @see https://processing.org/reference/brightness_.html
|
625
|
+
# @see https://p5js.org/reference/#/p5/brightness
|
626
|
+
#
|
627
|
+
def brightness(color)
|
628
|
+
_, _, b = toRawColor__(color).to_hsv
|
629
|
+
b * (@hsbColor__ ? @colorMaxes__[2] : 1)
|
630
|
+
end
|
631
|
+
|
466
632
|
# @private
|
467
633
|
private def toRGBA__(*args)
|
468
634
|
a, b = args
|
469
635
|
return parseColor__(a, b || alphaMax__) if a.kind_of?(String)
|
470
|
-
|
636
|
+
rawColor__(*args).to_a
|
471
637
|
end
|
472
638
|
|
473
639
|
# @private
|
474
|
-
def
|
640
|
+
def rawColor__(*args)
|
475
641
|
a, b, c, d = args
|
476
642
|
rgba = case args.size
|
477
643
|
when 1, 2 then [a, a, a, b || alphaMax__]
|
@@ -496,46 +662,54 @@ module Processing
|
|
496
662
|
@colorMaxes__[3]
|
497
663
|
end
|
498
664
|
|
665
|
+
# @private
|
666
|
+
private def toRawColor__(color)
|
667
|
+
Rays::Color.new(
|
668
|
+
((color >> 16) & 0xff) / 255.0,
|
669
|
+
((color >> 8) & 0xff) / 255.0,
|
670
|
+
( color & 0xff) / 255.0,
|
671
|
+
((color >> 24) & 0xff) / 255.0)
|
672
|
+
end
|
673
|
+
|
499
674
|
# Sets angle mode.
|
500
675
|
#
|
501
676
|
# @param mode [RADIANS, DEGREES] RADIANS or DEGREES
|
502
677
|
#
|
503
678
|
# @return [RADIANS, DEGREES] current mode
|
504
679
|
#
|
680
|
+
# @see https://p5js.org/reference/#/p5/angleMode
|
681
|
+
#
|
505
682
|
def angleMode(mode = nil)
|
506
683
|
if mode != nil
|
507
684
|
@angleMode__ = mode
|
508
|
-
@
|
685
|
+
@toRad__, @toDeg__, @fromRad__, @fromDeg__ =
|
509
686
|
case mode.downcase.to_sym
|
510
|
-
when RADIANS then RAD2DEG__
|
511
|
-
when DEGREES then 1.0
|
687
|
+
when RADIANS then [1.0, RAD2DEG__, 1.0, DEG2RAD__]
|
688
|
+
when DEGREES then [DEG2RAD__, 1.0, RAD2DEG__, 1.0]
|
512
689
|
else raise ArgumentError, "invalid angle mode: #{mode}"
|
513
690
|
end
|
514
691
|
end
|
515
692
|
@angleMode__
|
516
693
|
end
|
517
694
|
|
695
|
+
# @private
|
696
|
+
def toRadians__(angle)
|
697
|
+
angle * @toRad__
|
698
|
+
end
|
699
|
+
|
518
700
|
# @private
|
519
701
|
def toDegrees__(angle)
|
520
|
-
angle * @
|
702
|
+
angle * @toDeg__
|
521
703
|
end
|
522
704
|
|
523
705
|
# @private
|
524
706
|
def fromRadians__(radians)
|
525
|
-
|
526
|
-
when RADIANS then radians
|
527
|
-
when DEGREES then radians * RAD2DEG__
|
528
|
-
else raise "invalid angle mode: #{mode}"
|
529
|
-
end
|
707
|
+
radians * @fromRad__
|
530
708
|
end
|
531
709
|
|
532
710
|
# @private
|
533
711
|
def fromDegrees__(degrees)
|
534
|
-
|
535
|
-
when RADIANS then degrees * DEG2RAD__
|
536
|
-
when DEGREES then degrees
|
537
|
-
else raise "invalid angle mode: #{mode}"
|
538
|
-
end
|
712
|
+
degrees * @fromDeg__
|
539
713
|
end
|
540
714
|
|
541
715
|
# Sets rect mode. Default is CORNER.
|
@@ -549,6 +723,9 @@ module Processing
|
|
549
723
|
#
|
550
724
|
# @return [nil] nil
|
551
725
|
#
|
726
|
+
# @see https://processing.org/reference/rectMode_.html
|
727
|
+
# @see https://p5js.org/reference/#/p5/rectMode
|
728
|
+
#
|
552
729
|
def rectMode(mode)
|
553
730
|
@rectMode__ = mode
|
554
731
|
end
|
@@ -564,6 +741,9 @@ module Processing
|
|
564
741
|
#
|
565
742
|
# @return [nil] nil
|
566
743
|
#
|
744
|
+
# @see https://processing.org/reference/ellipseMode_.html
|
745
|
+
# @see https://p5js.org/reference/#/p5/ellipseMode
|
746
|
+
#
|
567
747
|
def ellipseMode(mode)
|
568
748
|
@ellipseMode__ = mode
|
569
749
|
end
|
@@ -578,6 +758,9 @@ module Processing
|
|
578
758
|
#
|
579
759
|
# @return [nil] nil
|
580
760
|
#
|
761
|
+
# @see https://processing.org/reference/imageMode_.html
|
762
|
+
# @see https://p5js.org/reference/#/p5/imageMode
|
763
|
+
#
|
581
764
|
def imageMode(mode)
|
582
765
|
@imageMode__ = mode
|
583
766
|
end
|
@@ -592,6 +775,8 @@ module Processing
|
|
592
775
|
#
|
593
776
|
# @return [nil] nil
|
594
777
|
#
|
778
|
+
# @see https://processing.org/reference/shapeMode_.html
|
779
|
+
#
|
595
780
|
def shapeMode(mode)
|
596
781
|
@shapeMode__ = mode
|
597
782
|
end
|
@@ -613,6 +798,9 @@ module Processing
|
|
613
798
|
#
|
614
799
|
# @return [nil] nil
|
615
800
|
#
|
801
|
+
# @see https://processing.org/reference/blendMode_.html
|
802
|
+
# @see https://p5js.org/reference/#/p5/blendMode
|
803
|
+
#
|
616
804
|
def blendMode(mode = nil)
|
617
805
|
if mode != nil
|
618
806
|
@blendMode__ = mode
|
@@ -639,6 +827,9 @@ module Processing
|
|
639
827
|
#
|
640
828
|
# @return [nil] nil
|
641
829
|
#
|
830
|
+
# @see https://processing.org/reference/fill_.html
|
831
|
+
# @see https://p5js.org/reference/#/p5/fill
|
832
|
+
#
|
642
833
|
def fill(*args)
|
643
834
|
@painter__.fill(*toRGBA__(*args))
|
644
835
|
nil
|
@@ -653,6 +844,9 @@ module Processing
|
|
653
844
|
#
|
654
845
|
# @return [nil] nil
|
655
846
|
#
|
847
|
+
# @see https://processing.org/reference/noFill_.html
|
848
|
+
# @see https://p5js.org/reference/#/p5/noFill
|
849
|
+
#
|
656
850
|
def noFill()
|
657
851
|
@painter__.fill nil
|
658
852
|
nil
|
@@ -676,6 +870,9 @@ module Processing
|
|
676
870
|
#
|
677
871
|
# @return [nil] nil
|
678
872
|
#
|
873
|
+
# @see https://processing.org/reference/stroke_.html
|
874
|
+
# @see https://p5js.org/reference/#/p5/stroke
|
875
|
+
#
|
679
876
|
def stroke(*args)
|
680
877
|
@painter__.stroke(*toRGBA__(*args))
|
681
878
|
nil
|
@@ -685,6 +882,9 @@ module Processing
|
|
685
882
|
#
|
686
883
|
# @return [nil] nil
|
687
884
|
#
|
885
|
+
# @see https://processing.org/reference/noStroke_.html
|
886
|
+
# @see https://p5js.org/reference/#/p5/noStroke
|
887
|
+
#
|
688
888
|
def noStroke()
|
689
889
|
@painter__.stroke nil
|
690
890
|
nil
|
@@ -696,6 +896,9 @@ module Processing
|
|
696
896
|
#
|
697
897
|
# @return [nil] nil
|
698
898
|
#
|
899
|
+
# @see https://processing.org/reference/strokeWeight_.html
|
900
|
+
# @see https://p5js.org/reference/#/p5/strokeWeight
|
901
|
+
#
|
699
902
|
def strokeWeight(weight)
|
700
903
|
@painter__.stroke_width weight
|
701
904
|
nil
|
@@ -707,6 +910,9 @@ module Processing
|
|
707
910
|
#
|
708
911
|
# @return [nil] nil
|
709
912
|
#
|
913
|
+
# @see https://processing.org/reference/strokeCap_.html
|
914
|
+
# @see https://p5js.org/reference/#/p5/strokeCap
|
915
|
+
#
|
710
916
|
def strokeCap(cap)
|
711
917
|
@painter__.stroke_cap cap
|
712
918
|
nil
|
@@ -718,11 +924,60 @@ module Processing
|
|
718
924
|
#
|
719
925
|
# @return [nil] nil
|
720
926
|
#
|
927
|
+
# @see https://processing.org/reference/strokeJoin_.html
|
928
|
+
# @see https://p5js.org/reference/#/p5/strokeJoin
|
929
|
+
#
|
721
930
|
def strokeJoin(join)
|
722
931
|
@painter__.stroke_join join
|
723
932
|
nil
|
724
933
|
end
|
725
934
|
|
935
|
+
# Sets the resolution at which curves display.
|
936
|
+
# The default value is 20 while the minimum value is 3.
|
937
|
+
#
|
938
|
+
# @param detail [Numeric] resolution of the curves
|
939
|
+
#
|
940
|
+
# @return [nil] nil
|
941
|
+
#
|
942
|
+
# @see https://processing.org/reference/curveDetail_.html
|
943
|
+
# @see https://p5js.org/reference/#/p5/curveDetail
|
944
|
+
#
|
945
|
+
def curveDetail(detail)
|
946
|
+
detail = 3 if detail < 3
|
947
|
+
@curveDetail__ = detail
|
948
|
+
nil
|
949
|
+
end
|
950
|
+
|
951
|
+
# Sets the quality of curve forms.
|
952
|
+
#
|
953
|
+
# @param tightness [Numeric] determines how the curve fits to the vertex points
|
954
|
+
#
|
955
|
+
# @return [nil] nil
|
956
|
+
#
|
957
|
+
# @see https://processing.org/reference/curveTightness_.html
|
958
|
+
# @see https://p5js.org/reference/#/p5/curveTightness
|
959
|
+
#
|
960
|
+
def curveTightness(tightness)
|
961
|
+
@curveTightness__ = tightness
|
962
|
+
nil
|
963
|
+
end
|
964
|
+
|
965
|
+
# Sets the resolution at which Bezier's curve is displayed.
|
966
|
+
# The default value is 20.
|
967
|
+
#
|
968
|
+
# @param detail [Numeric] resolution of the curves
|
969
|
+
#
|
970
|
+
# @return [nil] nil
|
971
|
+
#
|
972
|
+
# @see https://processing.org/reference/bezierDetail_.html
|
973
|
+
# @see https://p5js.org/reference/#/p5/bezierDetail
|
974
|
+
#
|
975
|
+
def bezierDetail(detail)
|
976
|
+
detail = 1 if detail < 1
|
977
|
+
@bezierDetail__ = detail
|
978
|
+
nil
|
979
|
+
end
|
980
|
+
|
726
981
|
# Sets fill color for drawing images.
|
727
982
|
#
|
728
983
|
# @overload tint(rgb)
|
@@ -741,6 +996,9 @@ module Processing
|
|
741
996
|
#
|
742
997
|
# @return [nil] nil
|
743
998
|
#
|
999
|
+
# @see https://processing.org/reference/tint_.html
|
1000
|
+
# @see https://p5js.org/reference/#/p5/tint
|
1001
|
+
#
|
744
1002
|
def tint(*args)
|
745
1003
|
@tint__ = args
|
746
1004
|
nil
|
@@ -750,6 +1008,9 @@ module Processing
|
|
750
1008
|
#
|
751
1009
|
# @return [nil] nil
|
752
1010
|
#
|
1011
|
+
# @see https://processing.org/reference/noTint_.html
|
1012
|
+
# @see https://p5js.org/reference/#/p5/noTint
|
1013
|
+
#
|
753
1014
|
def noTint()
|
754
1015
|
@tint__ = nil
|
755
1016
|
end
|
@@ -770,6 +1031,9 @@ module Processing
|
|
770
1031
|
#
|
771
1032
|
# @return [nil] nil
|
772
1033
|
#
|
1034
|
+
# @see https://processing.org/reference/clip_.html
|
1035
|
+
# @see https://p5js.org/reference/#/p5/clip
|
1036
|
+
#
|
773
1037
|
def clip(a, b, c, d)
|
774
1038
|
x, y, w, h = toXYWH__ @imageMode__, a, b, c, d
|
775
1039
|
@painter__.clip x, y, w, h
|
@@ -780,36 +1044,43 @@ module Processing
|
|
780
1044
|
#
|
781
1045
|
# @return [nil] nil
|
782
1046
|
#
|
1047
|
+
# @see https://processing.org/reference/noClip_.html
|
1048
|
+
#
|
783
1049
|
def noClip()
|
784
1050
|
@painter__.no_clip
|
785
1051
|
nil
|
786
1052
|
end
|
787
1053
|
|
788
1054
|
# Sets text font.
|
789
|
-
#
|
790
1055
|
# (Passing a font name as the first parameter is deprecated)
|
791
1056
|
#
|
1057
|
+
# @overload textFont()
|
792
1058
|
# @overload textFont(font)
|
793
|
-
# @overload textFont(name)
|
1059
|
+
# @overload textFont(name) [DEPRECATED]
|
794
1060
|
# @overload textFont(font, size)
|
795
|
-
# @overload textFont(name, size)
|
1061
|
+
# @overload textFont(name, size) [DEPRECATED]
|
796
1062
|
#
|
797
1063
|
# @param font [Font] font
|
798
1064
|
# @param name [String] font name
|
799
1065
|
# @param size [Numeric] font size (max 256)
|
800
1066
|
#
|
801
|
-
# @return [
|
1067
|
+
# @return [Font] current font
|
802
1068
|
#
|
803
|
-
|
804
|
-
|
805
|
-
|
806
|
-
|
807
|
-
|
808
|
-
|
1069
|
+
# @see https://processing.org/reference/textFont_.html
|
1070
|
+
# @see https://p5js.org/reference/#/p5/textFont
|
1071
|
+
#
|
1072
|
+
def textFont(font = nil, size = nil)
|
1073
|
+
if font != nil || size != nil
|
1074
|
+
size = FONT_SIZE_MAX__ if size && size > FONT_SIZE_MAX__
|
1075
|
+
if font.nil? || font.kind_of?(String)
|
1076
|
+
font = createFont font, size
|
1077
|
+
elsif size
|
1078
|
+
font.setSize__ size
|
1079
|
+
end
|
1080
|
+
@painter__.font = font.getInternal__
|
1081
|
+
@textFont__ = font
|
809
1082
|
end
|
810
|
-
@textFont__
|
811
|
-
@painter__.font = font.getInternal__
|
812
|
-
nil
|
1083
|
+
@textFont__
|
813
1084
|
end
|
814
1085
|
|
815
1086
|
# Sets text size.
|
@@ -818,27 +1089,91 @@ module Processing
|
|
818
1089
|
#
|
819
1090
|
# @return [nil] nil
|
820
1091
|
#
|
1092
|
+
# @see https://processing.org/reference/textSize_.html
|
1093
|
+
# @see https://p5js.org/reference/#/p5/textSize
|
1094
|
+
#
|
821
1095
|
def textSize(size)
|
822
1096
|
textFont @textFont__, size
|
1097
|
+
nil
|
823
1098
|
end
|
824
1099
|
|
1100
|
+
# Returns the width of the text.
|
1101
|
+
#
|
1102
|
+
# @param str [String] text string
|
1103
|
+
#
|
1104
|
+
# @return [Numeric] width of the text
|
1105
|
+
#
|
1106
|
+
# @see https://processing.org/reference/textWidth_.html
|
1107
|
+
# @see https://p5js.org/reference/#/p5/textWidth
|
1108
|
+
#
|
825
1109
|
def textWidth(str)
|
826
1110
|
@painter__.font.width str
|
827
1111
|
end
|
828
1112
|
|
1113
|
+
# Returns ascent of the current font at its current size.
|
1114
|
+
#
|
1115
|
+
# @return [Numeric] ascent
|
1116
|
+
#
|
1117
|
+
# @see https://processing.org/reference/textAscent_.html
|
1118
|
+
# @see https://p5js.org/reference/#/p5/textAscent
|
1119
|
+
#
|
829
1120
|
def textAscent()
|
830
1121
|
@painter__.font.ascent
|
831
1122
|
end
|
832
1123
|
|
1124
|
+
# Returns descent of the current font at its current size.
|
1125
|
+
#
|
1126
|
+
# @return [Numeric] descent
|
1127
|
+
#
|
1128
|
+
# @see https://processing.org/reference/textDescent_.html
|
1129
|
+
# @see https://p5js.org/reference/#/p5/textDescent
|
1130
|
+
#
|
833
1131
|
def textDescent()
|
834
1132
|
@painter__.font.descent
|
835
1133
|
end
|
836
1134
|
|
1135
|
+
# Sets the alignment for drawing text.
|
1136
|
+
#
|
1137
|
+
# @param horizontal [LEFT, CENTER, RIGHT] horizontal alignment
|
1138
|
+
# @param vertical [TOP, BOTTOM, CENTER, BASELINE] vertical alignment
|
1139
|
+
#
|
1140
|
+
# @return [nil] nil
|
1141
|
+
#
|
1142
|
+
# @see https://processing.org/reference/textAlign_.html
|
1143
|
+
# @see https://p5js.org/reference/#/p5/textAlign
|
1144
|
+
#
|
837
1145
|
def textAlign(horizontal, vertical = BASELINE)
|
838
1146
|
@textAlignH__ = horizontal
|
839
1147
|
@textAlignV__ = vertical
|
1148
|
+
nil
|
840
1149
|
end
|
841
1150
|
|
1151
|
+
# Sets the spacing between lines of text in units of pixels.
|
1152
|
+
#
|
1153
|
+
# @overload textLeading()
|
1154
|
+
# @overload textLeading(leading)
|
1155
|
+
#
|
1156
|
+
# @param leading [Numeric] the size in pixels for spacing between lines
|
1157
|
+
#
|
1158
|
+
# @return [Numeric] current spacing
|
1159
|
+
#
|
1160
|
+
# @see https://processing.org/reference/textLeading_.html
|
1161
|
+
# @see https://p5js.org/reference/#/p5/textLeading
|
1162
|
+
#
|
1163
|
+
def textLeading(leading = nil)
|
1164
|
+
@painter__.line_height = leading if leading
|
1165
|
+
@painter__.line_height
|
1166
|
+
end
|
1167
|
+
|
1168
|
+
# Sets texture.
|
1169
|
+
#
|
1170
|
+
# @param image [Image] texture image
|
1171
|
+
#
|
1172
|
+
# @return [nil] nil
|
1173
|
+
#
|
1174
|
+
# @see https://processing.org/reference/texture_.html
|
1175
|
+
# @see https://p5js.org/reference/#/p5/texture
|
1176
|
+
#
|
842
1177
|
def texture(image)
|
843
1178
|
@painter__.texture image&.getInternal__
|
844
1179
|
nil
|
@@ -887,6 +1222,9 @@ module Processing
|
|
887
1222
|
#
|
888
1223
|
# @return [nil] nil
|
889
1224
|
#
|
1225
|
+
# @see https://processing.org/reference/shader_.html
|
1226
|
+
# @see https://p5js.org/reference/#/p5/shader
|
1227
|
+
#
|
890
1228
|
def shader(shader)
|
891
1229
|
@painter__.shader shader&.getInternal__
|
892
1230
|
nil
|
@@ -896,6 +1234,9 @@ module Processing
|
|
896
1234
|
#
|
897
1235
|
# @return [nil] nil
|
898
1236
|
#
|
1237
|
+
# @see https://processing.org/reference/resetShader_.html
|
1238
|
+
# @see https://p5js.org/reference/#/p5/resetShader
|
1239
|
+
#
|
899
1240
|
def resetShader()
|
900
1241
|
@painter__.no_shader
|
901
1242
|
nil
|
@@ -911,8 +1252,14 @@ module Processing
|
|
911
1252
|
# @param type [THRESHOLD, GRAY, INVERT, BLUR] filter type
|
912
1253
|
# @param param [Numeric] a parameter for each filter
|
913
1254
|
#
|
1255
|
+
# @return [nil] nil
|
1256
|
+
#
|
1257
|
+
# @see https://processing.org/reference/filter_.html
|
1258
|
+
# @see https://p5js.org/reference/#/p5/filter
|
1259
|
+
#
|
914
1260
|
def filter(*args)
|
915
1261
|
@filter__ = Shader.createFilter__(*args)
|
1262
|
+
nil
|
916
1263
|
end
|
917
1264
|
|
918
1265
|
# Clears screen.
|
@@ -933,6 +1280,9 @@ module Processing
|
|
933
1280
|
#
|
934
1281
|
# @return [nil] nil
|
935
1282
|
#
|
1283
|
+
# @see https://processing.org/reference/background_.html
|
1284
|
+
# @see https://p5js.org/reference/#/p5/background
|
1285
|
+
#
|
936
1286
|
def background(*args)
|
937
1287
|
assertDrawing__
|
938
1288
|
rgba = toRGBA__(*args)
|
@@ -959,9 +1309,12 @@ module Processing
|
|
959
1309
|
#
|
960
1310
|
# @return [nil] nil
|
961
1311
|
#
|
1312
|
+
# @see https://processing.org/reference/point_.html
|
1313
|
+
# @see https://p5js.org/reference/#/p5/point
|
1314
|
+
#
|
962
1315
|
def point(x, y)
|
963
1316
|
assertDrawing__
|
964
|
-
@painter__.
|
1317
|
+
@painter__.point x, y
|
965
1318
|
nil
|
966
1319
|
end
|
967
1320
|
|
@@ -976,6 +1329,9 @@ module Processing
|
|
976
1329
|
#
|
977
1330
|
# @return [nil] nil
|
978
1331
|
#
|
1332
|
+
# @see https://processing.org/reference/line_.html
|
1333
|
+
# @see https://p5js.org/reference/#/p5/line
|
1334
|
+
#
|
979
1335
|
def line(x1, y1, x2, y2)
|
980
1336
|
assertDrawing__
|
981
1337
|
@painter__.line x1, y1, x2, y2
|
@@ -1004,6 +1360,9 @@ module Processing
|
|
1004
1360
|
#
|
1005
1361
|
# @return [nil] nil
|
1006
1362
|
#
|
1363
|
+
# @see https://processing.org/reference/rect_.html
|
1364
|
+
# @see https://p5js.org/reference/#/p5/rect
|
1365
|
+
#
|
1007
1366
|
def rect(a, b, c, d, *args)
|
1008
1367
|
assertDrawing__
|
1009
1368
|
x, y, w, h = toXYWH__ @rectMode__, a, b, c, d
|
@@ -1029,6 +1388,9 @@ module Processing
|
|
1029
1388
|
#
|
1030
1389
|
# @return [nil] nil
|
1031
1390
|
#
|
1391
|
+
# @see https://processing.org/reference/ellipse_.html
|
1392
|
+
# @see https://p5js.org/reference/#/p5/ellipse
|
1393
|
+
#
|
1032
1394
|
def ellipse(a, b, c, d)
|
1033
1395
|
assertDrawing__
|
1034
1396
|
x, y, w, h = toXYWH__ @ellipseMode__, a, b, c, d
|
@@ -1046,6 +1408,9 @@ module Processing
|
|
1046
1408
|
#
|
1047
1409
|
# @return [nil] nil
|
1048
1410
|
#
|
1411
|
+
# @see https://processing.org/reference/circle_.html
|
1412
|
+
# @see https://p5js.org/reference/#/p5/circle
|
1413
|
+
#
|
1049
1414
|
def circle(x, y, extent)
|
1050
1415
|
ellipse x, y, extent, extent
|
1051
1416
|
end
|
@@ -1065,6 +1430,9 @@ module Processing
|
|
1065
1430
|
#
|
1066
1431
|
# @return [nil] nil
|
1067
1432
|
#
|
1433
|
+
# @see https://processing.org/reference/arc_.html
|
1434
|
+
# @see https://p5js.org/reference/#/p5/arc
|
1435
|
+
#
|
1068
1436
|
def arc(a, b, c, d, start, stop)
|
1069
1437
|
assertDrawing__
|
1070
1438
|
x, y, w, h = toXYWH__ @ellipseMode__, a, b, c, d
|
@@ -1083,6 +1451,9 @@ module Processing
|
|
1083
1451
|
#
|
1084
1452
|
# @return [nil] nil
|
1085
1453
|
#
|
1454
|
+
# @see https://processing.org/reference/square_.html
|
1455
|
+
# @see https://p5js.org/reference/#/p5/square
|
1456
|
+
#
|
1086
1457
|
def square(x, y, extent)
|
1087
1458
|
rect x, y, extent, extent
|
1088
1459
|
end
|
@@ -1100,6 +1471,9 @@ module Processing
|
|
1100
1471
|
#
|
1101
1472
|
# @return [nil] nil
|
1102
1473
|
#
|
1474
|
+
# @see https://processing.org/reference/triangle_.html
|
1475
|
+
# @see https://p5js.org/reference/#/p5/triangle
|
1476
|
+
#
|
1103
1477
|
def triangle(x1, y1, x2, y2, x3, y3)
|
1104
1478
|
assertDrawing__
|
1105
1479
|
@painter__.line x1, y1, x2, y2, x3, y3, loop: true
|
@@ -1121,6 +1495,9 @@ module Processing
|
|
1121
1495
|
#
|
1122
1496
|
# @return [nil] nil
|
1123
1497
|
#
|
1498
|
+
# @see https://processing.org/reference/quad_.html
|
1499
|
+
# @see https://p5js.org/reference/#/p5/quad
|
1500
|
+
#
|
1124
1501
|
def quad(x1, y1, x2, y2, x3, y3, x4, y4)
|
1125
1502
|
assertDrawing__
|
1126
1503
|
@painter__.line x1, y1, x2, y2, x3, y3, x4, y4, loop: true
|
@@ -1142,9 +1519,14 @@ module Processing
|
|
1142
1519
|
#
|
1143
1520
|
# @return [nil] nil
|
1144
1521
|
#
|
1522
|
+
# @see https://processing.org/reference/curve_.html
|
1523
|
+
# @see https://p5js.org/reference/#/p5/curve
|
1524
|
+
#
|
1145
1525
|
def curve(cx1, cy1, x1, y1, x2, y2, cx2, cy2)
|
1146
1526
|
assertDrawing__
|
1527
|
+
@painter__.nsegment = @curveDetail__
|
1147
1528
|
@painter__.curve cx1, cy1, x1, y1, x2, y2, cx2, cy2
|
1529
|
+
@painter__.nsegment = 0
|
1148
1530
|
nil
|
1149
1531
|
end
|
1150
1532
|
|
@@ -1163,9 +1545,14 @@ module Processing
|
|
1163
1545
|
#
|
1164
1546
|
# @return [nil] nil
|
1165
1547
|
#
|
1548
|
+
# @see https://processing.org/reference/bezier_.html
|
1549
|
+
# @see https://p5js.org/reference/#/p5/bezier
|
1550
|
+
#
|
1166
1551
|
def bezier(x1, y1, cx1, cy1, cx2, cy2, x2, y2)
|
1167
1552
|
assertDrawing__
|
1553
|
+
@painter__.nsegment = @bezierDetail__
|
1168
1554
|
@painter__.bezier x1, y1, cx1, cy1, cx2, cy2, x2, y2
|
1555
|
+
@painter__.nsegment = 0
|
1169
1556
|
nil
|
1170
1557
|
end
|
1171
1558
|
|
@@ -1189,6 +1576,9 @@ module Processing
|
|
1189
1576
|
#
|
1190
1577
|
# @return [nil] nil
|
1191
1578
|
#
|
1579
|
+
# @see https://processing.org/reference/text_.html
|
1580
|
+
# @see https://p5js.org/reference/#/p5/text
|
1581
|
+
#
|
1192
1582
|
def text(str, x, y, x2 = nil, y2 = nil)
|
1193
1583
|
assertDrawing__
|
1194
1584
|
if x2
|
@@ -1227,6 +1617,9 @@ module Processing
|
|
1227
1617
|
#
|
1228
1618
|
# @return [nil] nil
|
1229
1619
|
#
|
1620
|
+
# @see https://processing.org/reference/image_.html
|
1621
|
+
# @see https://p5js.org/reference/#/p5/image
|
1622
|
+
#
|
1230
1623
|
def image(img, a, b, c = nil, d = nil)
|
1231
1624
|
assertDrawing__
|
1232
1625
|
x, y, w, h = toXYWH__ @imageMode__, a, b, c || img.width, d || img.height
|
@@ -1251,6 +1644,8 @@ module Processing
|
|
1251
1644
|
#
|
1252
1645
|
# @return [nil] nil
|
1253
1646
|
#
|
1647
|
+
# @see https://processing.org/reference/shape_.html
|
1648
|
+
#
|
1254
1649
|
def shape(shp, a = 0, b = 0, c = nil, d = nil)
|
1255
1650
|
assertDrawing__
|
1256
1651
|
return nil unless shp.isVisible
|
@@ -1437,6 +1832,9 @@ module Processing
|
|
1437
1832
|
#
|
1438
1833
|
# @return [nil] nil
|
1439
1834
|
#
|
1835
|
+
# @see https://processing.org/reference/copy_.html
|
1836
|
+
# @see https://p5js.org/reference/#/p5/copy
|
1837
|
+
#
|
1440
1838
|
def copy(img = nil, sx, sy, sw, sh, dx, dy, dw, dh)
|
1441
1839
|
blend img, sx, sy, sw, sh, dx, dy, dw, dh, BLEND
|
1442
1840
|
end
|
@@ -1459,6 +1857,9 @@ module Processing
|
|
1459
1857
|
#
|
1460
1858
|
# @return [nil] nil
|
1461
1859
|
#
|
1860
|
+
# @see https://processing.org/reference/blend_.html
|
1861
|
+
# @see https://p5js.org/reference/#/p5/blend
|
1862
|
+
#
|
1462
1863
|
def blend(img = nil, sx, sy, sw, sh, dx, dy, dw, dh, mode)
|
1463
1864
|
assertDrawing__
|
1464
1865
|
(img || self).drawImage__(
|
@@ -1470,6 +1871,9 @@ module Processing
|
|
1470
1871
|
#
|
1471
1872
|
# @return [nil] nil
|
1472
1873
|
#
|
1874
|
+
# @see https://processing.org/reference/loadPixels_.html
|
1875
|
+
# @see https://p5js.org/reference/#/p5/loadPixels
|
1876
|
+
#
|
1473
1877
|
def loadPixels()
|
1474
1878
|
@pixels__ = getInternal__.pixels
|
1475
1879
|
end
|
@@ -1478,15 +1882,30 @@ module Processing
|
|
1478
1882
|
#
|
1479
1883
|
# @return [nil] nil
|
1480
1884
|
#
|
1481
|
-
|
1482
|
-
|
1483
|
-
|
1885
|
+
# @see https://processing.org/reference/updatePixels_.html
|
1886
|
+
# @see https://p5js.org/reference/#/p5/updatePixels
|
1887
|
+
#
|
1888
|
+
def updatePixels(&block)
|
1889
|
+
return if !block && !@pixels__
|
1890
|
+
if block
|
1891
|
+
loadPixels
|
1892
|
+
block.call pixels
|
1893
|
+
end
|
1894
|
+
getInternal__.tap do |img|
|
1895
|
+
img.pixels = @pixels__
|
1896
|
+
img.paint {} # update texture and set modifiied
|
1897
|
+
end
|
1484
1898
|
@pixels__ = nil
|
1485
1899
|
end
|
1486
1900
|
|
1487
1901
|
# An array of all pixels.
|
1488
1902
|
# Call loadPixels() before accessing the array.
|
1489
1903
|
#
|
1904
|
+
# @return [Array] color array
|
1905
|
+
#
|
1906
|
+
# @see https://processing.org/reference/pixels.html
|
1907
|
+
# @see https://p5js.org/reference/#/p5/pixels
|
1908
|
+
#
|
1490
1909
|
def pixels()
|
1491
1910
|
@pixels__
|
1492
1911
|
end
|
@@ -1497,6 +1916,9 @@ module Processing
|
|
1497
1916
|
#
|
1498
1917
|
# @return [nil] nil
|
1499
1918
|
#
|
1919
|
+
# @see https://processing.org/reference/save_.html
|
1920
|
+
# @see https://p5js.org/reference/#/p5/save
|
1921
|
+
#
|
1500
1922
|
def save(filename)
|
1501
1923
|
getInternal__.save filename
|
1502
1924
|
nil
|
@@ -1509,10 +1931,13 @@ module Processing
|
|
1509
1931
|
#
|
1510
1932
|
# @param x [Numeric] left/right translation
|
1511
1933
|
# @param y [Numeric] up/down translation
|
1512
|
-
# @param
|
1934
|
+
# @param z [Numeric] forward/backward translation
|
1513
1935
|
#
|
1514
1936
|
# @return [nil] nil
|
1515
1937
|
#
|
1938
|
+
# @see https://processing.org/reference/translate_.html
|
1939
|
+
# @see https://p5js.org/reference/#/p5/translate
|
1940
|
+
#
|
1516
1941
|
def translate(x, y, z = 0)
|
1517
1942
|
assertDrawing__
|
1518
1943
|
@painter__.translate x, y, z
|
@@ -1523,13 +1948,18 @@ module Processing
|
|
1523
1948
|
#
|
1524
1949
|
# @overload scale(s)
|
1525
1950
|
# @overload scale(x, y)
|
1951
|
+
# @overload scale(x, y, z)
|
1526
1952
|
#
|
1527
1953
|
# @param s [Numeric] horizontal and vertical scale
|
1528
1954
|
# @param x [Numeric] horizontal scale
|
1529
1955
|
# @param y [Numeric] vertical scale
|
1956
|
+
# @param z [Numeric] depth scale
|
1530
1957
|
#
|
1531
1958
|
# @return [nil] nil
|
1532
1959
|
#
|
1960
|
+
# @see https://processing.org/reference/scale_.html
|
1961
|
+
# @see https://p5js.org/reference/#/p5/scale
|
1962
|
+
#
|
1533
1963
|
def scale(x, y = nil, z = 1)
|
1534
1964
|
assertDrawing__
|
1535
1965
|
@painter__.scale x, (y || x), z
|
@@ -1542,16 +1972,104 @@ module Processing
|
|
1542
1972
|
#
|
1543
1973
|
# @return [nil] nil
|
1544
1974
|
#
|
1975
|
+
# @see https://processing.org/reference/rotate_.html
|
1976
|
+
# @see https://p5js.org/reference/#/p5/rotate
|
1977
|
+
#
|
1545
1978
|
def rotate(angle)
|
1546
1979
|
assertDrawing__
|
1547
1980
|
@painter__.rotate toDegrees__ angle
|
1548
1981
|
nil
|
1549
1982
|
end
|
1550
1983
|
|
1984
|
+
# Applies rotation around the x-axis.
|
1985
|
+
#
|
1986
|
+
# @param angle [Numeric] angle for rotation
|
1987
|
+
#
|
1988
|
+
# @return [nil] nil
|
1989
|
+
#
|
1990
|
+
# @see https://processing.org/reference/rotateX_.html
|
1991
|
+
# @see https://p5js.org/reference/#/p5/rotateX
|
1992
|
+
#
|
1993
|
+
def rotateX(angle)
|
1994
|
+
assertDrawing__
|
1995
|
+
@painter__.rotate toDegrees__(angle), 1, 0, 0
|
1996
|
+
nil
|
1997
|
+
end
|
1998
|
+
|
1999
|
+
# Applies rotation around the y-axis.
|
2000
|
+
#
|
2001
|
+
# @param angle [Numeric] angle for rotation
|
2002
|
+
#
|
2003
|
+
# @return [nil] nil
|
2004
|
+
#
|
2005
|
+
# @see https://processing.org/reference/rotateY_.html
|
2006
|
+
# @see https://p5js.org/reference/#/p5/rotateY
|
2007
|
+
#
|
2008
|
+
def rotateY(angle)
|
2009
|
+
assertDrawing__
|
2010
|
+
@painter__.rotate toDegrees__(angle), 0, 1, 0
|
2011
|
+
nil
|
2012
|
+
end
|
2013
|
+
|
2014
|
+
# Applies rotation around the z-axis.
|
2015
|
+
#
|
2016
|
+
# @param angle [Numeric] angle for rotation
|
2017
|
+
#
|
2018
|
+
# @return [nil] nil
|
2019
|
+
#
|
2020
|
+
# @see https://processing.org/reference/rotateZ_.html
|
2021
|
+
# @see https://p5js.org/reference/#/p5/rotateZ
|
2022
|
+
#
|
2023
|
+
def rotateZ(angle)
|
2024
|
+
assertDrawing__
|
2025
|
+
@painter__.rotate toDegrees__(angle), 0, 0, 1
|
2026
|
+
nil
|
2027
|
+
end
|
2028
|
+
|
2029
|
+
# Applies shear around the x-axis.
|
2030
|
+
#
|
2031
|
+
# @param angle [Numeric] angle for shearing
|
2032
|
+
#
|
2033
|
+
# @return [nil] nil
|
2034
|
+
#
|
2035
|
+
# @see https://processing.org/reference/shearX_.html
|
2036
|
+
# @see https://p5js.org/reference/#/p5/shearX
|
2037
|
+
#
|
2038
|
+
def shearX(angle)
|
2039
|
+
t = Math.tan toRadians__(angle)
|
2040
|
+
@painter__.matrix *= Rays::Matrix.new(
|
2041
|
+
1, t, 0, 0,
|
2042
|
+
0, 1, 0, 0,
|
2043
|
+
0, 0, 1, 0,
|
2044
|
+
0, 0, 0, 1)
|
2045
|
+
nil
|
2046
|
+
end
|
2047
|
+
|
2048
|
+
# Applies shear around the y-axis.
|
2049
|
+
#
|
2050
|
+
# @param angle [Numeric] angle for shearing
|
2051
|
+
#
|
2052
|
+
# @return [nil] nil
|
2053
|
+
#
|
2054
|
+
# @see https://processing.org/reference/shearY_.html
|
2055
|
+
# @see https://p5js.org/reference/#/p5/shearY
|
2056
|
+
#
|
2057
|
+
def shearY(angle)
|
2058
|
+
t = Math.tan toRadians__(angle)
|
2059
|
+
@painter__.matrix *= Rays::Matrix.new(
|
2060
|
+
1, 0, 0, 0,
|
2061
|
+
t, 1, 0, 0,
|
2062
|
+
0, 0, 1, 0,
|
2063
|
+
0, 0, 0, 1)
|
2064
|
+
nil
|
2065
|
+
end
|
2066
|
+
|
1551
2067
|
# Pushes the current transformation matrix to stack.
|
1552
2068
|
#
|
1553
2069
|
# @return [Object] result of the expression at the end of the block
|
1554
2070
|
#
|
2071
|
+
# @see https://processing.org/reference/pushMatrix_.html
|
2072
|
+
#
|
1555
2073
|
def pushMatrix(&block)
|
1556
2074
|
assertDrawing__
|
1557
2075
|
@matrixStack__.push @painter__.matrix
|
@@ -1564,6 +2082,8 @@ module Processing
|
|
1564
2082
|
#
|
1565
2083
|
# @return [nil] nil
|
1566
2084
|
#
|
2085
|
+
# @see https://processing.org/reference/popMatrix_.html
|
2086
|
+
#
|
1567
2087
|
def popMatrix()
|
1568
2088
|
assertDrawing__
|
1569
2089
|
raise "matrix stack underflow" if @matrixStack__.empty?
|
@@ -1571,20 +2091,86 @@ module Processing
|
|
1571
2091
|
nil
|
1572
2092
|
end
|
1573
2093
|
|
2094
|
+
# Reset current transformation matrix with 2x3, or 4x4 matrix.
|
2095
|
+
#
|
2096
|
+
# @overload applyMatrix(array)
|
2097
|
+
# @overload applyMatrix(a, b, c, d, e, f)
|
2098
|
+
# @overload applyMatrix(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p)
|
2099
|
+
#
|
2100
|
+
# @param array [Array] 6 or 16 numbers which define the matrix
|
2101
|
+
# @param a [Numeric] number which defines the matrix
|
2102
|
+
# @param b [Numeric] number which defines the matrix
|
2103
|
+
# @param c [Numeric] number which defines the matrix
|
2104
|
+
# @param d [Numeric] number which defines the matrix
|
2105
|
+
# @param e [Numeric] number which defines the matrix
|
2106
|
+
# @param f [Numeric] number which defines the matrix
|
2107
|
+
# @param g [Numeric] number which defines the matrix
|
2108
|
+
# @param h [Numeric] number which defines the matrix
|
2109
|
+
# @param i [Numeric] number which defines the matrix
|
2110
|
+
# @param j [Numeric] number which defines the matrix
|
2111
|
+
# @param k [Numeric] number which defines the matrix
|
2112
|
+
# @param l [Numeric] number which defines the matrix
|
2113
|
+
# @param m [Numeric] number which defines the matrix
|
2114
|
+
# @param n [Numeric] number which defines the matrix
|
2115
|
+
# @param o [Numeric] number which defines the matrix
|
2116
|
+
# @param p [Numeric] number which defines the matrix
|
2117
|
+
#
|
2118
|
+
# @return [nil] nil
|
2119
|
+
#
|
2120
|
+
# @see https://processing.org/reference/applyMatrix_.html
|
2121
|
+
# @see https://p5js.org/reference/#/p5/applyMatrix
|
2122
|
+
#
|
2123
|
+
def applyMatrix(*args)
|
2124
|
+
assertDrawing__
|
2125
|
+
args = args.first if args.first.kind_of?(Array)
|
2126
|
+
if args.size == 6
|
2127
|
+
a, b, c, d, e, f = args
|
2128
|
+
args = [
|
2129
|
+
a, b, 0, 0,
|
2130
|
+
c, d, 0, 0,
|
2131
|
+
0, 0, 1, 0,
|
2132
|
+
e, f, 0, 1
|
2133
|
+
]
|
2134
|
+
end
|
2135
|
+
raise ArgumentError unless args.size == 16
|
2136
|
+
m = Rays::Matrix.new(*args)
|
2137
|
+
m.transpose! if @p5jsMode__
|
2138
|
+
@painter__.matrix *= m
|
2139
|
+
nil
|
2140
|
+
end
|
2141
|
+
|
1574
2142
|
# Reset current transformation matrix with identity matrix.
|
1575
2143
|
#
|
1576
2144
|
# @return [nil] nil
|
1577
2145
|
#
|
2146
|
+
# @see https://processing.org/reference/resetMatrix_.html
|
2147
|
+
# @see https://p5js.org/reference/#/p5/resetMatrix
|
2148
|
+
#
|
1578
2149
|
def resetMatrix()
|
1579
2150
|
assertDrawing__
|
1580
2151
|
@painter__.matrix = 1
|
1581
2152
|
nil
|
1582
2153
|
end
|
1583
2154
|
|
2155
|
+
# Prints matrix elements to console.
|
2156
|
+
#
|
2157
|
+
# @return [nil] nil
|
2158
|
+
#
|
2159
|
+
# @see https://processing.org/reference/printMatrix_.html
|
2160
|
+
#
|
2161
|
+
def printMatrix()
|
2162
|
+
m = @painter__.matrix
|
2163
|
+
m.transpose! if @p5jsMode__
|
2164
|
+
print "%f %f %f %f\n%f %f %f %f\n%f %f %f %f\n%f %f %f %f\n" % m.to_a
|
2165
|
+
nil
|
2166
|
+
end
|
2167
|
+
|
1584
2168
|
# Save current style values to the style stack.
|
1585
2169
|
#
|
1586
2170
|
# @return [Object] result of the expression at the end of the block
|
1587
2171
|
#
|
2172
|
+
# @see https://processing.org/reference/pushStyle_.html
|
2173
|
+
#
|
1588
2174
|
def pushStyle(&block)
|
1589
2175
|
assertDrawing__
|
1590
2176
|
@styleStack__.push [
|
@@ -1593,6 +2179,8 @@ module Processing
|
|
1593
2179
|
@painter__.stroke_width,
|
1594
2180
|
@painter__.stroke_cap,
|
1595
2181
|
@painter__.stroke_join,
|
2182
|
+
@painter__.miter_limit,
|
2183
|
+
@painter__.line_height!,
|
1596
2184
|
@painter__.clip,
|
1597
2185
|
@painter__.blend_mode,
|
1598
2186
|
@painter__.font,
|
@@ -1600,13 +2188,22 @@ module Processing
|
|
1600
2188
|
@painter__.texcoord_mode,
|
1601
2189
|
@painter__.texcoord_wrap,
|
1602
2190
|
@painter__.shader,
|
2191
|
+
@colorMode__,
|
1603
2192
|
@hsbColor__,
|
1604
2193
|
@colorMaxes__,
|
1605
|
-
@
|
2194
|
+
@angleMode__,
|
2195
|
+
@toRad__,
|
2196
|
+
@toDeg__,
|
2197
|
+
@fromRad__,
|
2198
|
+
@fromDeg__,
|
1606
2199
|
@rectMode__,
|
1607
2200
|
@ellipseMode__,
|
1608
2201
|
@imageMode__,
|
1609
2202
|
@shapeMode__,
|
2203
|
+
@blendMode__,
|
2204
|
+
@curveDetail__,
|
2205
|
+
@curveTightness__,
|
2206
|
+
@bezierDetail__,
|
1610
2207
|
@textAlignH__,
|
1611
2208
|
@textAlignV__,
|
1612
2209
|
@textFont__,
|
@@ -1621,6 +2218,8 @@ module Processing
|
|
1621
2218
|
#
|
1622
2219
|
# @return [nil] nil
|
1623
2220
|
#
|
2221
|
+
# @see https://processing.org/reference/popStyle_.html
|
2222
|
+
#
|
1624
2223
|
def popStyle()
|
1625
2224
|
assertDrawing__
|
1626
2225
|
raise "style stack underflow" if @styleStack__.empty?
|
@@ -1629,6 +2228,8 @@ module Processing
|
|
1629
2228
|
@painter__.stroke_width,
|
1630
2229
|
@painter__.stroke_cap,
|
1631
2230
|
@painter__.stroke_join,
|
2231
|
+
@painter__.miter_limit,
|
2232
|
+
@painter__.line_height,
|
1632
2233
|
@painter__.clip,
|
1633
2234
|
@painter__.blend_mode,
|
1634
2235
|
@painter__.font,
|
@@ -1636,13 +2237,22 @@ module Processing
|
|
1636
2237
|
@painter__.texcoord_mode,
|
1637
2238
|
@painter__.texcoord_wrap,
|
1638
2239
|
@painter__.shader,
|
2240
|
+
@colorMode__,
|
1639
2241
|
@hsbColor__,
|
1640
2242
|
@colorMaxes__,
|
1641
|
-
@
|
2243
|
+
@angleMode__,
|
2244
|
+
@toRad__,
|
2245
|
+
@toDeg__,
|
2246
|
+
@fromRad__,
|
2247
|
+
@fromDeg__,
|
1642
2248
|
@rectMode__,
|
1643
2249
|
@ellipseMode__,
|
1644
2250
|
@imageMode__,
|
1645
2251
|
@shapeMode__,
|
2252
|
+
@blendMode__,
|
2253
|
+
@curveDetail__,
|
2254
|
+
@curveTightness__,
|
2255
|
+
@bezierDetail__,
|
1646
2256
|
@textAlignH__,
|
1647
2257
|
@textAlignV__,
|
1648
2258
|
@textFont__,
|
@@ -1655,6 +2265,9 @@ module Processing
|
|
1655
2265
|
#
|
1656
2266
|
# @return [Object] result of the expression at the end of the block
|
1657
2267
|
#
|
2268
|
+
# @see https://processing.org/reference/push_.html
|
2269
|
+
# @see https://p5js.org/reference/#/p5/push
|
2270
|
+
#
|
1658
2271
|
def push(&block)
|
1659
2272
|
pushMatrix
|
1660
2273
|
pushStyle
|
@@ -1667,6 +2280,9 @@ module Processing
|
|
1667
2280
|
#
|
1668
2281
|
# @return [nil] nil
|
1669
2282
|
#
|
2283
|
+
# @see https://processing.org/reference/pop_.html
|
2284
|
+
# @see https://p5js.org/reference/#/p5/pop
|
2285
|
+
#
|
1670
2286
|
def pop()
|
1671
2287
|
popMatrix
|
1672
2288
|
popStyle
|
@@ -1678,10 +2294,10 @@ module Processing
|
|
1678
2294
|
end
|
1679
2295
|
|
1680
2296
|
# @private
|
1681
|
-
def drawImage__(painter, *args, **states)
|
2297
|
+
def drawImage__(painter, *args, image__: getInternal__, **states)
|
1682
2298
|
shader = painter.shader || @filter__&.getInternal__
|
1683
2299
|
painter.push shader: shader, **states do |_|
|
1684
|
-
painter.image
|
2300
|
+
painter.image image__, *args
|
1685
2301
|
end
|
1686
2302
|
end
|
1687
2303
|
|
@@ -1700,6 +2316,9 @@ module Processing
|
|
1700
2316
|
#
|
1701
2317
|
# @return [Numeric] absolute number
|
1702
2318
|
#
|
2319
|
+
# @see https://processing.org/reference/abs_.html
|
2320
|
+
# @see https://p5js.org/reference/#/p5/abs
|
2321
|
+
#
|
1703
2322
|
def abs(value)
|
1704
2323
|
value.abs
|
1705
2324
|
end
|
@@ -1710,6 +2329,9 @@ module Processing
|
|
1710
2329
|
#
|
1711
2330
|
# @return [Numeric] rounded up number
|
1712
2331
|
#
|
2332
|
+
# @see https://processing.org/reference/ceil_.html
|
2333
|
+
# @see https://p5js.org/reference/#/p5/ceil
|
2334
|
+
#
|
1713
2335
|
def ceil(value)
|
1714
2336
|
value.ceil
|
1715
2337
|
end
|
@@ -1720,6 +2342,9 @@ module Processing
|
|
1720
2342
|
#
|
1721
2343
|
# @return [Numeric] rounded down number
|
1722
2344
|
#
|
2345
|
+
# @see https://processing.org/reference/floor_.html
|
2346
|
+
# @see https://p5js.org/reference/#/p5/floor
|
2347
|
+
#
|
1723
2348
|
def floor(value)
|
1724
2349
|
value.floor
|
1725
2350
|
end
|
@@ -1730,6 +2355,9 @@ module Processing
|
|
1730
2355
|
#
|
1731
2356
|
# @return [Numeric] rounded number
|
1732
2357
|
#
|
2358
|
+
# @see https://processing.org/reference/round_.html
|
2359
|
+
# @see https://p5js.org/reference/#/p5/round
|
2360
|
+
#
|
1733
2361
|
def round(value)
|
1734
2362
|
value.round
|
1735
2363
|
end
|
@@ -1740,6 +2368,9 @@ module Processing
|
|
1740
2368
|
#
|
1741
2369
|
# @return [Numeric] result number
|
1742
2370
|
#
|
2371
|
+
# @see https://processing.org/reference/log_.html
|
2372
|
+
# @see https://p5js.org/reference/#/p5/log
|
2373
|
+
#
|
1743
2374
|
def log(n)
|
1744
2375
|
Math.log n
|
1745
2376
|
end
|
@@ -1750,6 +2381,9 @@ module Processing
|
|
1750
2381
|
#
|
1751
2382
|
# @return [Numeric] result number
|
1752
2383
|
#
|
2384
|
+
# @see https://processing.org/reference/exp_.html
|
2385
|
+
# @see https://p5js.org/reference/#/p5/exp
|
2386
|
+
#
|
1753
2387
|
def exp(n)
|
1754
2388
|
Math.exp n
|
1755
2389
|
end
|
@@ -1761,6 +2395,9 @@ module Processing
|
|
1761
2395
|
#
|
1762
2396
|
# @return [Numeric] value ** exponent
|
1763
2397
|
#
|
2398
|
+
# @see https://processing.org/reference/pow_.html
|
2399
|
+
# @see https://p5js.org/reference/#/p5/pow
|
2400
|
+
#
|
1764
2401
|
def pow(value, exponent)
|
1765
2402
|
value ** exponent
|
1766
2403
|
end
|
@@ -1771,6 +2408,9 @@ module Processing
|
|
1771
2408
|
#
|
1772
2409
|
# @return [Numeric] squared value
|
1773
2410
|
#
|
2411
|
+
# @see https://processing.org/reference/sq_.html
|
2412
|
+
# @see https://p5js.org/reference/#/p5/sq
|
2413
|
+
#
|
1774
2414
|
def sq(value)
|
1775
2415
|
value * value
|
1776
2416
|
end
|
@@ -1781,6 +2421,9 @@ module Processing
|
|
1781
2421
|
#
|
1782
2422
|
# @return [Numeric] squared value
|
1783
2423
|
#
|
2424
|
+
# @see https://processing.org/reference/sqrt_.html
|
2425
|
+
# @see https://p5js.org/reference/#/p5/sqrt
|
2426
|
+
#
|
1784
2427
|
def sqrt(value)
|
1785
2428
|
Math.sqrt value
|
1786
2429
|
end
|
@@ -1796,6 +2439,9 @@ module Processing
|
|
1796
2439
|
#
|
1797
2440
|
# @return [Numeric] magnitude
|
1798
2441
|
#
|
2442
|
+
# @see https://processing.org/reference/mag_.html
|
2443
|
+
# @see https://p5js.org/reference/#/p5/mag
|
2444
|
+
#
|
1799
2445
|
def mag(*args)
|
1800
2446
|
x, y, z = *args
|
1801
2447
|
case args.size
|
@@ -1819,6 +2465,9 @@ module Processing
|
|
1819
2465
|
#
|
1820
2466
|
# @return [Numeric] distance between 2 points
|
1821
2467
|
#
|
2468
|
+
# @see https://processing.org/reference/dist_.html
|
2469
|
+
# @see https://p5js.org/reference/#/p5/dist
|
2470
|
+
#
|
1822
2471
|
def dist(*args)
|
1823
2472
|
case args.size
|
1824
2473
|
when 4
|
@@ -1841,6 +2490,9 @@ module Processing
|
|
1841
2490
|
#
|
1842
2491
|
# @return [Numeric] normalized value between 0..1
|
1843
2492
|
#
|
2493
|
+
# @see https://processing.org/reference/norm_.html
|
2494
|
+
# @see https://p5js.org/reference/#/p5/norm
|
2495
|
+
#
|
1844
2496
|
def norm(value, start, stop)
|
1845
2497
|
(value.to_f - start.to_f) / (stop.to_f - start.to_f)
|
1846
2498
|
end
|
@@ -1853,6 +2505,9 @@ module Processing
|
|
1853
2505
|
#
|
1854
2506
|
# @return [Numeric] interporated number
|
1855
2507
|
#
|
2508
|
+
# @see https://processing.org/reference/lerp_.html
|
2509
|
+
# @see https://p5js.org/reference/#/p5/lerp
|
2510
|
+
#
|
1856
2511
|
def lerp(start, stop, amount)
|
1857
2512
|
start + (stop - start) * amount
|
1858
2513
|
end
|
@@ -1865,6 +2520,9 @@ module Processing
|
|
1865
2520
|
#
|
1866
2521
|
# @return [Integer] interporated color
|
1867
2522
|
#
|
2523
|
+
# @see https://processing.org/reference/lerpColor_.html
|
2524
|
+
# @see https://p5js.org/reference/#/p5/lerpColor
|
2525
|
+
#
|
1868
2526
|
def lerpColor(color1, color2, amount)
|
1869
2527
|
color(
|
1870
2528
|
lerp(red( color1), red( color2), amount),
|
@@ -1883,6 +2541,9 @@ module Processing
|
|
1883
2541
|
#
|
1884
2542
|
# @return [Numeric] mapped number
|
1885
2543
|
#
|
2544
|
+
# @see https://processing.org/reference/map_.html
|
2545
|
+
# @see https://p5js.org/reference/#/p5/map
|
2546
|
+
#
|
1886
2547
|
def map(value, start1, stop1, start2, stop2)
|
1887
2548
|
lerp start2, stop2, norm(value, start1, stop1)
|
1888
2549
|
end
|
@@ -1900,6 +2561,9 @@ module Processing
|
|
1900
2561
|
#
|
1901
2562
|
# @return [Numeric] minimum value
|
1902
2563
|
#
|
2564
|
+
# @see https://processing.org/reference/min_.html
|
2565
|
+
# @see https://p5js.org/reference/#/p5/min
|
2566
|
+
#
|
1903
2567
|
def min(*args)
|
1904
2568
|
args.flatten.min
|
1905
2569
|
end
|
@@ -1917,6 +2581,9 @@ module Processing
|
|
1917
2581
|
#
|
1918
2582
|
# @return [Numeric] maximum value
|
1919
2583
|
#
|
2584
|
+
# @see https://processing.org/reference/max_.html
|
2585
|
+
# @see https://p5js.org/reference/#/p5/max
|
2586
|
+
#
|
1920
2587
|
def max(*args)
|
1921
2588
|
args.flatten.max
|
1922
2589
|
end
|
@@ -1929,6 +2596,9 @@ module Processing
|
|
1929
2596
|
#
|
1930
2597
|
# @return [Numeric] constrained number
|
1931
2598
|
#
|
2599
|
+
# @see https://processing.org/reference/constrain_.html
|
2600
|
+
# @see https://p5js.org/reference/#/p5/constrain
|
2601
|
+
#
|
1932
2602
|
def constrain(value, min, max)
|
1933
2603
|
value < min ? min : (value > max ? max : value)
|
1934
2604
|
end
|
@@ -1939,6 +2609,9 @@ module Processing
|
|
1939
2609
|
#
|
1940
2610
|
# @return [Numeric] radian
|
1941
2611
|
#
|
2612
|
+
# @see https://processing.org/reference/radians_.html
|
2613
|
+
# @see https://p5js.org/reference/#/p5/radians
|
2614
|
+
#
|
1942
2615
|
def radians(degree)
|
1943
2616
|
degree * DEG2RAD__
|
1944
2617
|
end
|
@@ -1949,6 +2622,9 @@ module Processing
|
|
1949
2622
|
#
|
1950
2623
|
# @return [Numeric] degree
|
1951
2624
|
#
|
2625
|
+
# @see https://processing.org/reference/degrees_.html
|
2626
|
+
# @see https://p5js.org/reference/#/p5/degrees
|
2627
|
+
#
|
1952
2628
|
def degrees(radian)
|
1953
2629
|
radian * RAD2DEG__
|
1954
2630
|
end
|
@@ -1959,6 +2635,9 @@ module Processing
|
|
1959
2635
|
#
|
1960
2636
|
# @return [Numeric] the sine
|
1961
2637
|
#
|
2638
|
+
# @see https://processing.org/reference/sin_.html
|
2639
|
+
# @see https://p5js.org/reference/#/p5/sin
|
2640
|
+
#
|
1962
2641
|
def sin(angle)
|
1963
2642
|
Math.sin angle
|
1964
2643
|
end
|
@@ -1969,6 +2648,9 @@ module Processing
|
|
1969
2648
|
#
|
1970
2649
|
# @return [Numeric] the cosine
|
1971
2650
|
#
|
2651
|
+
# @see https://processing.org/reference/cos_.html
|
2652
|
+
# @see https://p5js.org/reference/#/p5/cos
|
2653
|
+
#
|
1972
2654
|
def cos(angle)
|
1973
2655
|
Math.cos angle
|
1974
2656
|
end
|
@@ -1979,6 +2661,9 @@ module Processing
|
|
1979
2661
|
#
|
1980
2662
|
# @return [Numeric] the tangent
|
1981
2663
|
#
|
2664
|
+
# @see https://processing.org/reference/tan_.html
|
2665
|
+
# @see https://p5js.org/reference/#/p5/tan
|
2666
|
+
#
|
1982
2667
|
def tan(angle)
|
1983
2668
|
Math.tan angle
|
1984
2669
|
end
|
@@ -1989,6 +2674,9 @@ module Processing
|
|
1989
2674
|
#
|
1990
2675
|
# @return [Numeric] the arc sine
|
1991
2676
|
#
|
2677
|
+
# @see https://processing.org/reference/asin_.html
|
2678
|
+
# @see https://p5js.org/reference/#/p5/asin
|
2679
|
+
#
|
1992
2680
|
def asin(value)
|
1993
2681
|
Math.asin value
|
1994
2682
|
end
|
@@ -1999,6 +2687,9 @@ module Processing
|
|
1999
2687
|
#
|
2000
2688
|
# @return [Numeric] the arc cosine
|
2001
2689
|
#
|
2690
|
+
# @see https://processing.org/reference/acos_.html
|
2691
|
+
# @see https://p5js.org/reference/#/p5/acos
|
2692
|
+
#
|
2002
2693
|
def acos(value)
|
2003
2694
|
Math.acos value
|
2004
2695
|
end
|
@@ -2009,6 +2700,9 @@ module Processing
|
|
2009
2700
|
#
|
2010
2701
|
# @return [Numeric] the arc tangent
|
2011
2702
|
#
|
2703
|
+
# @see https://processing.org/reference/atan_.html
|
2704
|
+
# @see https://p5js.org/reference/#/p5/atan
|
2705
|
+
#
|
2012
2706
|
def atan(value)
|
2013
2707
|
Math.atan value
|
2014
2708
|
end
|
@@ -2020,10 +2714,105 @@ module Processing
|
|
2020
2714
|
#
|
2021
2715
|
# @return [Numeric] the angle in radians
|
2022
2716
|
#
|
2717
|
+
# @see https://processing.org/reference/atan2_.html
|
2718
|
+
# @see https://p5js.org/reference/#/p5/atan2
|
2719
|
+
#
|
2023
2720
|
def atan2(y, x)
|
2024
2721
|
Math.atan2 y, x
|
2025
2722
|
end
|
2026
2723
|
|
2724
|
+
# Evaluates the curve at point t for points a, b, c, d.
|
2725
|
+
#
|
2726
|
+
# @param a [Numeric] coordinate of first control point
|
2727
|
+
# @param b [Numeric] coordinate of first point on the curve
|
2728
|
+
# @param c [Numeric] coordinate of second point on the curve
|
2729
|
+
# @param d [Numeric] coordinate of second control point
|
2730
|
+
# @param t [Numeric] value between 0.0 and 1.0
|
2731
|
+
#
|
2732
|
+
# @return [Numeric] interpolated value
|
2733
|
+
#
|
2734
|
+
# @see https://processing.org/reference/curvePoint_.html
|
2735
|
+
# @see https://p5js.org/reference/#/p5/curvePoint
|
2736
|
+
#
|
2737
|
+
def curvePoint(a, b, c, d, t)
|
2738
|
+
s = @curveTightness__
|
2739
|
+
t3 = t * t * t
|
2740
|
+
t2 = t * t
|
2741
|
+
f1 = ( s - 1.0) / 2.0 * t3 + ( 1.0 - s) * t2 + (s - 1.0) / 2.0 * t
|
2742
|
+
f2 = ( s + 3.0) / 2.0 * t3 + (-5.0 - s) / 2.0 * t2 + 1.0
|
2743
|
+
f3 = (-3.0 - s) / 2.0 * t3 + ( s + 2.0) * t2 + (1.0 - s) / 2.0 * t
|
2744
|
+
f4 = ( 1.0 - s) / 2.0 * t3 + ( s - 1.0) / 2.0 * t2
|
2745
|
+
a * f1 + b * f2 + c * f3 + d * f4
|
2746
|
+
end
|
2747
|
+
|
2748
|
+
# Calculates the tangent of a point on a curve.
|
2749
|
+
#
|
2750
|
+
# @param a [Numeric] coordinate of first control point
|
2751
|
+
# @param b [Numeric] coordinate of first point on the curve
|
2752
|
+
# @param c [Numeric] coordinate of second point on the curve
|
2753
|
+
# @param d [Numeric] coordinate of second control point
|
2754
|
+
# @param t [Numeric] value between 0.0 and 1.0
|
2755
|
+
#
|
2756
|
+
# @return [Numeric] tangent value
|
2757
|
+
#
|
2758
|
+
# @see https://processing.org/reference/curveTangent_.html
|
2759
|
+
# @see https://p5js.org/reference/#/p5/curveTangent
|
2760
|
+
#
|
2761
|
+
def curveTangent(a, b, c, d, t)
|
2762
|
+
s = @curveTightness__
|
2763
|
+
tt3 = t * t * 3.0
|
2764
|
+
t2 = t * 2.0
|
2765
|
+
f1 = ( s - 1.0) / 2.0 * tt3 + ( 1.0 - s) * t2 + (s - 1.0) / 2.0
|
2766
|
+
f2 = ( s + 3.0) / 2.0 * tt3 + (-5.0 - s) / 2.0 * t2
|
2767
|
+
f3 = (-3.0 - s) / 2.0 * tt3 + ( s + 2.0) * t2 + (1.0 - s) / 2.0
|
2768
|
+
f4 = ( 1.0 - s) / 2.0 * tt3 + ( s - 1.0) / 2.0 * t2
|
2769
|
+
a * f1 + b * f2 + c * f3 + d * f4
|
2770
|
+
end
|
2771
|
+
|
2772
|
+
# Evaluates the Bezier at point t for points a, b, c, d.
|
2773
|
+
#
|
2774
|
+
# @param a [Numeric] coordinate of first point on the curve
|
2775
|
+
# @param b [Numeric] coordinate of first control point
|
2776
|
+
# @param c [Numeric] coordinate of second control point
|
2777
|
+
# @param d [Numeric] coordinate of second point on the curve
|
2778
|
+
# @param t [Numeric] value between 0.0 and 1.0
|
2779
|
+
#
|
2780
|
+
# @return [Numeric] interpolated value
|
2781
|
+
#
|
2782
|
+
# @see https://processing.org/reference/bezierPoint_.html
|
2783
|
+
# @see https://p5js.org/reference/#/p5/bezierPoint
|
2784
|
+
#
|
2785
|
+
def bezierPoint(a, b, c, d, t)
|
2786
|
+
tt = 1.0 - t
|
2787
|
+
tt ** 3.0 * a +
|
2788
|
+
tt ** 2.0 * b * 3.0 * t +
|
2789
|
+
t ** 2.0 * c * 3.0 * tt +
|
2790
|
+
t ** 3.0 * d
|
2791
|
+
end
|
2792
|
+
|
2793
|
+
# Calculates the tangent of a point on a Bezier curve.
|
2794
|
+
#
|
2795
|
+
# @param a [Numeric] coordinate of first point on the curve
|
2796
|
+
# @param b [Numeric] coordinate of first control point
|
2797
|
+
# @param c [Numeric] coordinate of second control point
|
2798
|
+
# @param d [Numeric] coordinate of second point on the curve
|
2799
|
+
# @param t [Numeric] value between 0.0 and 1.0
|
2800
|
+
#
|
2801
|
+
# @return [Numeric] tangent value
|
2802
|
+
#
|
2803
|
+
# @see https://processing.org/reference/bezierTangent_.html
|
2804
|
+
# @see https://p5js.org/reference/#/p5/bezierTangent
|
2805
|
+
#
|
2806
|
+
def bezierTangent(a, b, c, d, t)
|
2807
|
+
tt = 1.0 - t
|
2808
|
+
3.0 * d * t ** 2.0 -
|
2809
|
+
3.0 * c * t ** 2.0 +
|
2810
|
+
6.0 * c * tt * t -
|
2811
|
+
6.0 * b * tt * t +
|
2812
|
+
3.0 * b * tt ** 2.0 -
|
2813
|
+
3.0 * a * tt ** 2.0
|
2814
|
+
end
|
2815
|
+
|
2027
2816
|
# Returns the perlin noise value.
|
2028
2817
|
#
|
2029
2818
|
# @overload noise(x)
|
@@ -2036,13 +2825,52 @@ module Processing
|
|
2036
2825
|
#
|
2037
2826
|
# @return [Numeric] noise value (0.0..1.0)
|
2038
2827
|
#
|
2828
|
+
# @see https://processing.org/reference/noise_.html
|
2829
|
+
# @see https://p5js.org/reference/#/p5/noise
|
2830
|
+
#
|
2039
2831
|
def noise(x, y = 0, z = 0)
|
2040
|
-
|
2832
|
+
seed, falloff = @noiseSeed__, @noiseFallOff__
|
2833
|
+
amp = 0.5
|
2834
|
+
@noiseOctaves__.times.reduce(0) do |sum|
|
2835
|
+
value = (Rays.perlin(x, y, z, seed) / 2.0 + 0.5) * amp
|
2836
|
+
x *= 2
|
2837
|
+
y *= 2
|
2838
|
+
z *= 2
|
2839
|
+
amp *= falloff
|
2840
|
+
sum + value
|
2841
|
+
end
|
2842
|
+
end
|
2843
|
+
|
2844
|
+
# Sets the seed value for noise()
|
2845
|
+
#
|
2846
|
+
# @param seed [Numeric] seed value
|
2847
|
+
#
|
2848
|
+
# @return [nil] nil
|
2849
|
+
#
|
2850
|
+
# @see https://processing.org/reference/noiseSeed_.html
|
2851
|
+
# @see https://p5js.org/reference/#/p5/noiseSeed
|
2852
|
+
#
|
2853
|
+
def noiseSeed(seed)
|
2854
|
+
@noiseSeed__ = Random.new(seed).rand 0.0..1.0
|
2855
|
+
end
|
2856
|
+
|
2857
|
+
# Adjusts the character and level of detail produced by the Perlin noise function.
|
2858
|
+
#
|
2859
|
+
# @param lod [Numeric] number of octaves to be used by the noise
|
2860
|
+
# @param falloff [Numeric] falloff factor for each octave
|
2861
|
+
#
|
2862
|
+
# @return [nil] nil
|
2863
|
+
#
|
2864
|
+
# @see https://processing.org/reference/noiseDetail_.html
|
2865
|
+
# @see https://p5js.org/reference/#/p5/noiseDetail
|
2866
|
+
#
|
2867
|
+
def noiseDetail(lod, falloff = nil)
|
2868
|
+
@noiseOctaves__ = lod if lod && lod > 0
|
2869
|
+
@noiseFallOff__ = falloff if falloff && falloff > 0
|
2041
2870
|
end
|
2042
2871
|
|
2043
2872
|
# Returns a random number in range low...high
|
2044
2873
|
#
|
2045
|
-
# @overload random()
|
2046
2874
|
# @overload random(high)
|
2047
2875
|
# @overload random(low, high)
|
2048
2876
|
# @overload random(choices)
|
@@ -2053,10 +2881,60 @@ module Processing
|
|
2053
2881
|
#
|
2054
2882
|
# @return [Float] random number
|
2055
2883
|
#
|
2884
|
+
# @see https://processing.org/reference/random_.html
|
2885
|
+
# @see https://p5js.org/reference/#/p5/random
|
2886
|
+
#
|
2056
2887
|
def random(*args)
|
2057
|
-
|
2058
|
-
|
2059
|
-
|
2888
|
+
if args.first.kind_of? Array
|
2889
|
+
a = args.first
|
2890
|
+
a.empty? ? nil : a[@random__.rand a.size]
|
2891
|
+
else
|
2892
|
+
high, low = args.reverse
|
2893
|
+
@random__.rand (low || 0).to_f...(high || 1).to_f
|
2894
|
+
end
|
2895
|
+
end
|
2896
|
+
|
2897
|
+
# Sets the seed value for random()
|
2898
|
+
#
|
2899
|
+
# @param seed [Numeric] seed value
|
2900
|
+
#
|
2901
|
+
# @return [nil] nil
|
2902
|
+
#
|
2903
|
+
# @see https://processing.org/reference/randomSeed_.html
|
2904
|
+
# @see https://p5js.org/reference/#/p5/randomSeed
|
2905
|
+
#
|
2906
|
+
def randomSeed(seed)
|
2907
|
+
@random__ = Random.new seed
|
2908
|
+
@nextGaussian__ = nil
|
2909
|
+
end
|
2910
|
+
|
2911
|
+
# Returns a random number fitting a Gaussian, or normal, distribution.
|
2912
|
+
#
|
2913
|
+
# @param mean [Numeric] mean
|
2914
|
+
# @param sd [Numeric] standard deviation
|
2915
|
+
#
|
2916
|
+
# @return [Float] random number
|
2917
|
+
#
|
2918
|
+
# @see https://processing.org/reference/randomGaussian_.html
|
2919
|
+
# @see https://p5js.org/reference/#/p5/randomGaussian
|
2920
|
+
#
|
2921
|
+
def randomGaussian(mean = 0, sd = 1)
|
2922
|
+
value =
|
2923
|
+
if @nextGaussian__
|
2924
|
+
x, @nextGaussian__ = @nextGaussian__, nil
|
2925
|
+
x
|
2926
|
+
else
|
2927
|
+
a, b, w = 0, 0, 1
|
2928
|
+
until w < 1
|
2929
|
+
a = random(2) - 1
|
2930
|
+
b = random(2) - 1
|
2931
|
+
w = a ** 2 + b ** 2
|
2932
|
+
end
|
2933
|
+
w = Math.sqrt(-2 * Math.log(w) / w)
|
2934
|
+
@randomGaussian__ = a * w
|
2935
|
+
b * w
|
2936
|
+
end
|
2937
|
+
value * sd + mean
|
2060
2938
|
end
|
2061
2939
|
|
2062
2940
|
# Creates a new vector object.
|
@@ -2071,6 +2949,8 @@ module Processing
|
|
2071
2949
|
#
|
2072
2950
|
# @return [Vector] new vector
|
2073
2951
|
#
|
2952
|
+
# @see https://p5js.org/reference/#/p5/createVector
|
2953
|
+
#
|
2074
2954
|
def createVector(*args)
|
2075
2955
|
Vector.new(*args, context: self)
|
2076
2956
|
end
|
@@ -2080,6 +2960,10 @@ module Processing
|
|
2080
2960
|
# @param name [String] font name
|
2081
2961
|
# @param size [Numeric] font size (max 256)
|
2082
2962
|
#
|
2963
|
+
# @return [Font] new font
|
2964
|
+
#
|
2965
|
+
# @see https://processing.org/reference/createFont_.html
|
2966
|
+
#
|
2083
2967
|
def createFont(name, size)
|
2084
2968
|
size = FONT_SIZE_MAX__ if size && size > FONT_SIZE_MAX__
|
2085
2969
|
Font.new Rays::Font.new(name, size || FONT_SIZE_DEFAULT__)
|
@@ -2096,6 +2980,9 @@ module Processing
|
|
2096
2980
|
#
|
2097
2981
|
# @return [Image] new image
|
2098
2982
|
#
|
2983
|
+
# @see https://processing.org/reference/createImage_.html
|
2984
|
+
# @see https://p5js.org/reference/#/p5/createImage
|
2985
|
+
#
|
2099
2986
|
def createImage(w, h, format = RGBA)
|
2100
2987
|
colorspace = {RGB => Rays::RGB, RGBA => Rays::RGBA}[format]
|
2101
2988
|
raise ArgumentError, "Unknown image format" unless colorspace
|
@@ -2115,6 +3002,10 @@ module Processing
|
|
2115
3002
|
#
|
2116
3003
|
# @param kind [LINE, RECT, ELLIPSE, ARC, TRIANGLE, QUAD, GROUP]
|
2117
3004
|
#
|
3005
|
+
# @return [Shape] new shape
|
3006
|
+
#
|
3007
|
+
# @see https://processing.org/reference/createShape_.html
|
3008
|
+
#
|
2118
3009
|
def createShape(kind = nil, *args)
|
2119
3010
|
case kind
|
2120
3011
|
when LINE then createLineShape__( *args)
|
@@ -2171,6 +3062,9 @@ module Processing
|
|
2171
3062
|
#
|
2172
3063
|
# @return [Graphics] graphics object
|
2173
3064
|
#
|
3065
|
+
# @see https://processing.org/reference/createGraphics_.html
|
3066
|
+
# @see https://p5js.org/reference/#/p5/createGraphics
|
3067
|
+
#
|
2174
3068
|
def createGraphics(width, height, pixelDensity = 1)
|
2175
3069
|
Graphics.new width, height, pixelDensity
|
2176
3070
|
end
|
@@ -2207,6 +3101,8 @@ module Processing
|
|
2207
3101
|
#
|
2208
3102
|
# @return [Shader] shader object
|
2209
3103
|
#
|
3104
|
+
# @see https://p5js.org/reference/#/p5/createShader
|
3105
|
+
#
|
2210
3106
|
def createShader(vert, frag)
|
2211
3107
|
vert = File.read if vert && File.exist?(vert)
|
2212
3108
|
frag = File.read if frag && File.exist?(frag)
|
@@ -2235,7 +3131,7 @@ module Processing
|
|
2235
3131
|
raise "unsupported font type -- '#{ext}'" unless ext =~ /^\.?(ttf|otf)$/i
|
2236
3132
|
|
2237
3133
|
filename = httpGet__ filename, ext if filename =~ %r|^https?://|
|
2238
|
-
Font.new Rays::Font.load
|
3134
|
+
Font.new Rays::Font.load filename
|
2239
3135
|
end
|
2240
3136
|
|
2241
3137
|
# Loads image.
|
@@ -2288,6 +3184,9 @@ module Processing
|
|
2288
3184
|
#
|
2289
3185
|
# @return [Shader] loaded shader object
|
2290
3186
|
#
|
3187
|
+
# @see https://processing.org/reference/loadShader_.html
|
3188
|
+
# @see https://p5js.org/reference/#/p5/loadShader
|
3189
|
+
#
|
2291
3190
|
def loadShader(fragPath, vertPath = nil)
|
2292
3191
|
createShader vertPath, fragPath
|
2293
3192
|
end
|
@@ -2299,15 +3198,10 @@ module Processing
|
|
2299
3198
|
path = path.sub_ext ext
|
2300
3199
|
|
2301
3200
|
unless path.file?
|
2302
|
-
URI.
|
2303
|
-
|
3201
|
+
Net::HTTP.get_response URI.parse(uri) do |res|
|
3202
|
+
res.value # raise an error unless successful
|
2304
3203
|
tmpdir.mkdir unless tmpdir.directory?
|
2305
|
-
path.open('
|
2306
|
-
output.set_encoding Encoding::ASCII_8BIT
|
2307
|
-
while buf = input.read(2 ** 16)
|
2308
|
-
output.write buf
|
2309
|
-
end
|
2310
|
-
end
|
3204
|
+
path.open('wb') {|file| res.read_body {|body| file.write body}}
|
2311
3205
|
end
|
2312
3206
|
end
|
2313
3207
|
path.to_s
|