rubysketch 0.3.15 → 0.3.16
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ChangeLog.md +6 -0
- data/VERSION +1 -1
- data/lib/rubysketch-processing.rb +1 -1
- data/lib/rubysketch.rb +2 -0
- data/lib/rubysketch/app.rb +13 -0
- data/lib/rubysketch/glsl.rb +2 -2
- data/lib/rubysketch/module.rb +3 -3
- data/lib/rubysketch/processing.rb +377 -248
- data/lib/rubysketch/window.rb +62 -46
- data/test/helper.rb +1 -1
- data/test/processing/test_utility.rb +3 -7
- data/test/processing/test_vector.rb +43 -46
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e7c911427a4145fa18e7395c65f49ed58077c6d294f93ee9d24a840f621bcfeb
|
4
|
+
data.tar.gz: e5ecc52cb87042b8e59fd64f48c358f19638a3a4f35a696072b3f49d95998eba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ce775dec5c87470a3c3aa88e37fae94ecfaab96616c381bf71cbab5c17325ec0b93ab6640be326185de6f4b5e44b6aec9438418f1e57a00a9955ac5e148d20e1
|
7
|
+
data.tar.gz: 433efaf677bb1538096b1453591e5d28608fc20793bbcdd9e648f54e286eff7d63923496375520e5c560904883eb9385ac2837f67e4aabe7988f7d1d0fa4f23a
|
data/ChangeLog.md
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.16
|
data/lib/rubysketch.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'set'
|
1
2
|
require 'digest/sha1'
|
2
3
|
require 'pathname'
|
3
4
|
require 'tmpdir'
|
@@ -5,6 +6,7 @@ require 'open-uri'
|
|
5
6
|
|
6
7
|
require 'reflex'
|
7
8
|
require 'rubysketch/module'
|
9
|
+
require 'rubysketch/app'
|
8
10
|
require 'rubysketch/window'
|
9
11
|
require 'rubysketch/processing'
|
10
12
|
require 'rubysketch/glsl'
|
data/lib/rubysketch/glsl.rb
CHANGED
@@ -4,12 +4,12 @@ module RubySketch
|
|
4
4
|
# @private
|
5
5
|
class GLSL
|
6
6
|
|
7
|
-
def initialize
|
7
|
+
def initialize(glsl)
|
8
8
|
@shader = Reflex::Shader.new glsl
|
9
9
|
end
|
10
10
|
|
11
11
|
# @private
|
12
|
-
def on_start__
|
12
|
+
def on_start__(window)
|
13
13
|
start = Time.now.to_f
|
14
14
|
|
15
15
|
window.draw = proc do |e, painter|
|
data/lib/rubysketch/module.rb
CHANGED
@@ -5,15 +5,15 @@ module RubySketch
|
|
5
5
|
|
6
6
|
module_function
|
7
7
|
|
8
|
-
def name
|
8
|
+
def name()
|
9
9
|
super.split('::')[-2]
|
10
10
|
end
|
11
11
|
|
12
|
-
def version
|
12
|
+
def version()
|
13
13
|
open(root_dir 'VERSION') {|f| f.readline.chomp}
|
14
14
|
end
|
15
15
|
|
16
|
-
def root_dir
|
16
|
+
def root_dir(path = '')
|
17
17
|
File.expand_path "../../#{path}", __dir__
|
18
18
|
end
|
19
19
|
|
@@ -34,7 +34,7 @@ module RubySketch
|
|
34
34
|
# @param v [Vector] vector object to copy
|
35
35
|
# @param a [Array] array like [x, y, z]
|
36
36
|
#
|
37
|
-
def initialize
|
37
|
+
def initialize(x = 0, y = 0, z = 0, context: nil)
|
38
38
|
@point = case x
|
39
39
|
when Rays::Point then x.dup
|
40
40
|
when Vector then x.getInternal__.dup
|
@@ -46,7 +46,7 @@ module RubySketch
|
|
46
46
|
|
47
47
|
# Initializer for dup or clone
|
48
48
|
#
|
49
|
-
def initialize_copy
|
49
|
+
def initialize_copy(o)
|
50
50
|
@point = o.getInternal__.dup
|
51
51
|
end
|
52
52
|
|
@@ -72,8 +72,8 @@ module RubySketch
|
|
72
72
|
#
|
73
73
|
# @return [nil] nil
|
74
74
|
#
|
75
|
-
def set
|
76
|
-
initialize
|
75
|
+
def set(*args)
|
76
|
+
initialize(*args)
|
77
77
|
self
|
78
78
|
end
|
79
79
|
|
@@ -81,7 +81,7 @@ module RubySketch
|
|
81
81
|
#
|
82
82
|
# @return [Numeric] x value of vector
|
83
83
|
#
|
84
|
-
def x
|
84
|
+
def x()
|
85
85
|
@point.x
|
86
86
|
end
|
87
87
|
|
@@ -89,7 +89,7 @@ module RubySketch
|
|
89
89
|
#
|
90
90
|
# @return [Numeric] y value of vector
|
91
91
|
#
|
92
|
-
def y
|
92
|
+
def y()
|
93
93
|
@point.y
|
94
94
|
end
|
95
95
|
|
@@ -97,7 +97,7 @@ module RubySketch
|
|
97
97
|
#
|
98
98
|
# @return [Numeric] z value of vector
|
99
99
|
#
|
100
|
-
def z
|
100
|
+
def z()
|
101
101
|
@point.z
|
102
102
|
end
|
103
103
|
|
@@ -105,7 +105,7 @@ module RubySketch
|
|
105
105
|
#
|
106
106
|
# @return [Numeric] x value of vector
|
107
107
|
#
|
108
|
-
def x=
|
108
|
+
def x=(x)
|
109
109
|
@point.x = x
|
110
110
|
end
|
111
111
|
|
@@ -113,7 +113,7 @@ module RubySketch
|
|
113
113
|
#
|
114
114
|
# @return [Numeric] y value of vector
|
115
115
|
#
|
116
|
-
def y=
|
116
|
+
def y=(y)
|
117
117
|
@point.y = y
|
118
118
|
end
|
119
119
|
|
@@ -121,7 +121,7 @@ module RubySketch
|
|
121
121
|
#
|
122
122
|
# @return [Numeric] z value of vector
|
123
123
|
#
|
124
|
-
def z=
|
124
|
+
def z=(z)
|
125
125
|
@point.z = z
|
126
126
|
end
|
127
127
|
|
@@ -139,8 +139,8 @@ module RubySketch
|
|
139
139
|
#
|
140
140
|
# @return [Vector] interporated vector
|
141
141
|
#
|
142
|
-
def lerp
|
143
|
-
v = toVector__
|
142
|
+
def lerp(*args, amount)
|
143
|
+
v = toVector__(*args)
|
144
144
|
self.x = x + (v.x - x) * amount
|
145
145
|
self.y = y + (v.y - y) * amount
|
146
146
|
self.z = z + (v.z - z) * amount
|
@@ -155,7 +155,7 @@ module RubySketch
|
|
155
155
|
#
|
156
156
|
# @return [Vector] interporated vector
|
157
157
|
#
|
158
|
-
def self.lerp
|
158
|
+
def self.lerp(v1, v2, amount)
|
159
159
|
v1.dup.lerp v2, amount
|
160
160
|
end
|
161
161
|
|
@@ -163,7 +163,7 @@ module RubySketch
|
|
163
163
|
#
|
164
164
|
# @return [Array] array of x, y, z
|
165
165
|
#
|
166
|
-
def array
|
166
|
+
def array()
|
167
167
|
@point.to_a 3
|
168
168
|
end
|
169
169
|
|
@@ -180,7 +180,7 @@ module RubySketch
|
|
180
180
|
#
|
181
181
|
# @return [Vector] added vector
|
182
182
|
#
|
183
|
-
def add
|
183
|
+
def add(*args)
|
184
184
|
@point += toVector__(*args).getInternal__
|
185
185
|
self
|
186
186
|
end
|
@@ -198,7 +198,7 @@ module RubySketch
|
|
198
198
|
#
|
199
199
|
# @return [Vector] subtracted vector
|
200
200
|
#
|
201
|
-
def sub
|
201
|
+
def sub(*args)
|
202
202
|
@point -= toVector__(*args).getInternal__
|
203
203
|
self
|
204
204
|
end
|
@@ -209,7 +209,7 @@ module RubySketch
|
|
209
209
|
#
|
210
210
|
# @return [Vector] multiplied vector
|
211
211
|
#
|
212
|
-
def mult
|
212
|
+
def mult(num)
|
213
213
|
@point *= num
|
214
214
|
self
|
215
215
|
end
|
@@ -220,7 +220,7 @@ module RubySketch
|
|
220
220
|
#
|
221
221
|
# @return [Vector] divided vector
|
222
222
|
#
|
223
|
-
def div
|
223
|
+
def div(num)
|
224
224
|
@point /= num
|
225
225
|
self
|
226
226
|
end
|
@@ -231,7 +231,7 @@ module RubySketch
|
|
231
231
|
#
|
232
232
|
# @return [Vector] added vector
|
233
233
|
#
|
234
|
-
def +
|
234
|
+
def +(v)
|
235
235
|
dup.add v
|
236
236
|
end
|
237
237
|
|
@@ -241,7 +241,7 @@ module RubySketch
|
|
241
241
|
#
|
242
242
|
# @return [Vector] subtracted vector
|
243
243
|
#
|
244
|
-
def -
|
244
|
+
def -(v)
|
245
245
|
dup.sub v
|
246
246
|
end
|
247
247
|
|
@@ -251,7 +251,7 @@ module RubySketch
|
|
251
251
|
#
|
252
252
|
# @return [Vector] multiplied vector
|
253
253
|
#
|
254
|
-
def *
|
254
|
+
def *(num)
|
255
255
|
dup.mult num
|
256
256
|
end
|
257
257
|
|
@@ -261,7 +261,7 @@ module RubySketch
|
|
261
261
|
#
|
262
262
|
# @return [Vector] divided vector
|
263
263
|
#
|
264
|
-
def /
|
264
|
+
def /(num)
|
265
265
|
dup.div num
|
266
266
|
end
|
267
267
|
|
@@ -276,7 +276,7 @@ module RubySketch
|
|
276
276
|
#
|
277
277
|
# @return [Vector] added vector
|
278
278
|
#
|
279
|
-
def self.add
|
279
|
+
def self.add(v1, v2, target = nil)
|
280
280
|
v = v1 + v2
|
281
281
|
target.set v if self === target
|
282
282
|
v
|
@@ -293,7 +293,7 @@ module RubySketch
|
|
293
293
|
#
|
294
294
|
# @return [Vector] subtracted vector
|
295
295
|
#
|
296
|
-
def self.sub
|
296
|
+
def self.sub(v1, v2, target = nil)
|
297
297
|
v = v1 - v2
|
298
298
|
target.set v if self === target
|
299
299
|
v
|
@@ -310,7 +310,7 @@ module RubySketch
|
|
310
310
|
#
|
311
311
|
# @return [Vector] multiplied vector
|
312
312
|
#
|
313
|
-
def self.mult
|
313
|
+
def self.mult(v1, num, target = nil)
|
314
314
|
v = v1 * num
|
315
315
|
target.set v if self === target
|
316
316
|
v
|
@@ -327,7 +327,7 @@ module RubySketch
|
|
327
327
|
#
|
328
328
|
# @return [Vector] divided vector
|
329
329
|
#
|
330
|
-
def self.div
|
330
|
+
def self.div(v1, num, target = nil)
|
331
331
|
v = v1 / num
|
332
332
|
target.set v if self === target
|
333
333
|
v
|
@@ -337,7 +337,7 @@ module RubySketch
|
|
337
337
|
#
|
338
338
|
# @return [Numeric] length
|
339
339
|
#
|
340
|
-
def mag
|
340
|
+
def mag()
|
341
341
|
@point.length
|
342
342
|
end
|
343
343
|
|
@@ -345,7 +345,7 @@ module RubySketch
|
|
345
345
|
#
|
346
346
|
# @return [Numeric] squared length
|
347
347
|
#
|
348
|
-
def magSq
|
348
|
+
def magSq()
|
349
349
|
Rays::Point::dot(@point, @point)
|
350
350
|
end
|
351
351
|
|
@@ -359,7 +359,7 @@ module RubySketch
|
|
359
359
|
#
|
360
360
|
# @return [Vector] vector with new length
|
361
361
|
#
|
362
|
-
def setMag
|
362
|
+
def setMag(target = nil, len)
|
363
363
|
(target || self).set @point.normal * len
|
364
364
|
end
|
365
365
|
|
@@ -369,7 +369,7 @@ module RubySketch
|
|
369
369
|
#
|
370
370
|
# @return [Vector] normalized vector
|
371
371
|
#
|
372
|
-
def normalize
|
372
|
+
def normalize(target = nil)
|
373
373
|
(target || self).set @point.normal
|
374
374
|
end
|
375
375
|
|
@@ -379,7 +379,7 @@ module RubySketch
|
|
379
379
|
#
|
380
380
|
# @return [Vector] new vector
|
381
381
|
#
|
382
|
-
def limit
|
382
|
+
def limit(max)
|
383
383
|
setMag max if magSq > max ** 2
|
384
384
|
self
|
385
385
|
end
|
@@ -390,7 +390,7 @@ module RubySketch
|
|
390
390
|
#
|
391
391
|
# @return [Numeric] the distance
|
392
392
|
#
|
393
|
-
def dist
|
393
|
+
def dist(v)
|
394
394
|
(self - v).mag
|
395
395
|
end
|
396
396
|
|
@@ -401,7 +401,7 @@ module RubySketch
|
|
401
401
|
#
|
402
402
|
# @return [Numeric] the distance
|
403
403
|
#
|
404
|
-
def self.dist
|
404
|
+
def self.dist(v1, v2)
|
405
405
|
v1.dist v2
|
406
406
|
end
|
407
407
|
|
@@ -418,7 +418,7 @@ module RubySketch
|
|
418
418
|
#
|
419
419
|
# @return [Numeric] result of dot product
|
420
420
|
#
|
421
|
-
def dot
|
421
|
+
def dot(*args)
|
422
422
|
Rays::Point::dot getInternal__, toVector__(*args).getInternal__
|
423
423
|
end
|
424
424
|
|
@@ -429,7 +429,7 @@ module RubySketch
|
|
429
429
|
#
|
430
430
|
# @return [Numeric] result of dot product
|
431
431
|
#
|
432
|
-
def self.dot
|
432
|
+
def self.dot(v1, v2)
|
433
433
|
v1.dot v2
|
434
434
|
end
|
435
435
|
|
@@ -446,7 +446,7 @@ module RubySketch
|
|
446
446
|
#
|
447
447
|
# @return [Numeric] result of cross product
|
448
448
|
#
|
449
|
-
def cross
|
449
|
+
def cross(a, *rest)
|
450
450
|
target = self.class === rest.last ? rest.pop : nil
|
451
451
|
v = self.class.new Rays::Point::cross getInternal__, toVector__(a, *rest).getInternal__
|
452
452
|
target.set v if self.class === target
|
@@ -460,7 +460,7 @@ module RubySketch
|
|
460
460
|
#
|
461
461
|
# @return [Numeric] result of cross product
|
462
462
|
#
|
463
|
-
def self.cross
|
463
|
+
def self.cross(v1, v2, target = nil)
|
464
464
|
v1.cross v2, target
|
465
465
|
end
|
466
466
|
|
@@ -470,7 +470,7 @@ module RubySketch
|
|
470
470
|
#
|
471
471
|
# @return [Vector] rotated this object
|
472
472
|
#
|
473
|
-
def rotate
|
473
|
+
def rotate(angle)
|
474
474
|
angle = @context ? @context.toAngle__(angle) : angle * RAD2DEG__
|
475
475
|
@point.rotate! angle
|
476
476
|
self
|
@@ -480,7 +480,7 @@ module RubySketch
|
|
480
480
|
#
|
481
481
|
# @return [Numeric] the angle in radians
|
482
482
|
#
|
483
|
-
def heading
|
483
|
+
def heading()
|
484
484
|
Math.atan2 y, x
|
485
485
|
end
|
486
486
|
|
@@ -491,7 +491,7 @@ module RubySketch
|
|
491
491
|
#
|
492
492
|
# @return [Vector] rotated vector
|
493
493
|
#
|
494
|
-
def self.fromAngle
|
494
|
+
def self.fromAngle(angle, target = nil)
|
495
495
|
v = self.new(1, 0, 0).rotate(angle)
|
496
496
|
target.set v if target
|
497
497
|
v
|
@@ -504,7 +504,7 @@ module RubySketch
|
|
504
504
|
#
|
505
505
|
# @return [Numeric] angle in radians
|
506
506
|
#
|
507
|
-
def self.angleBetween
|
507
|
+
def self.angleBetween(v1, v2)
|
508
508
|
x1, y1, z1 = v1.array
|
509
509
|
x2, y2, z2 = v2.array
|
510
510
|
return 0 if (x1 == 0 && y1 == 0 && z1 == 0) || (x2 == 0 && y2 == 0 && z2 == 0)
|
@@ -521,7 +521,7 @@ module RubySketch
|
|
521
521
|
#
|
522
522
|
# @return [Vector] a random vector
|
523
523
|
#
|
524
|
-
def self.random2D
|
524
|
+
def self.random2D(target = nil)
|
525
525
|
v = self.fromAngle rand 0.0...(Math::PI * 2)
|
526
526
|
target.set v if target
|
527
527
|
v
|
@@ -533,9 +533,9 @@ module RubySketch
|
|
533
533
|
#
|
534
534
|
# @return [Vector] a random vector
|
535
535
|
#
|
536
|
-
def self.random3D
|
536
|
+
def self.random3D(target = nil)
|
537
537
|
angle = rand 0.0...(Math::PI * 2)
|
538
|
-
z = rand
|
538
|
+
z = rand(-1.0..1.0)
|
539
539
|
z2 = z ** 2
|
540
540
|
x = Math.sqrt(1.0 - z2) * Math.cos(angle)
|
541
541
|
y = Math.sqrt(1.0 - z2) * Math.sin(angle)
|
@@ -545,22 +545,22 @@ module RubySketch
|
|
545
545
|
end
|
546
546
|
|
547
547
|
# @private
|
548
|
-
def inspect
|
548
|
+
def inspect()
|
549
549
|
"<##{self.class.name} #{x}, #{y}, #{z}>"
|
550
550
|
end
|
551
551
|
|
552
552
|
# @private
|
553
|
-
def <=>
|
553
|
+
def <=>(o)
|
554
554
|
@point <=> o.getInternal__
|
555
555
|
end
|
556
556
|
|
557
557
|
# @private
|
558
|
-
protected def getInternal__
|
558
|
+
protected def getInternal__()
|
559
559
|
@point
|
560
560
|
end
|
561
561
|
|
562
562
|
# @private
|
563
|
-
private def toVector__
|
563
|
+
private def toVector__(*args)
|
564
564
|
self.class === args.first ? args.first : self.class.new(*args)
|
565
565
|
end
|
566
566
|
|
@@ -572,7 +572,7 @@ module RubySketch
|
|
572
572
|
class Image
|
573
573
|
|
574
574
|
# @private
|
575
|
-
def initialize
|
575
|
+
def initialize(image)
|
576
576
|
@image = image
|
577
577
|
end
|
578
578
|
|
@@ -580,7 +580,7 @@ module RubySketch
|
|
580
580
|
#
|
581
581
|
# @return [Numeric] width of image
|
582
582
|
#
|
583
|
-
def width
|
583
|
+
def width()
|
584
584
|
@image.width
|
585
585
|
end
|
586
586
|
|
@@ -588,7 +588,7 @@ module RubySketch
|
|
588
588
|
#
|
589
589
|
# @return [Numeric] height of image
|
590
590
|
#
|
591
|
-
def height
|
591
|
+
def height()
|
592
592
|
@image.height
|
593
593
|
end
|
594
594
|
|
@@ -599,7 +599,7 @@ module RubySketch
|
|
599
599
|
#
|
600
600
|
# @return [nil] nil
|
601
601
|
#
|
602
|
-
def resize
|
602
|
+
def resize(width, height)
|
603
603
|
@image = Rays::Image.new(width, height).paint do |painter|
|
604
604
|
painter.image @image, 0, 0, width, height
|
605
605
|
end
|
@@ -623,7 +623,7 @@ module RubySketch
|
|
623
623
|
#
|
624
624
|
# @return [nil] nil
|
625
625
|
#
|
626
|
-
def copy
|
626
|
+
def copy(img = nil, sx, sy, sw, sh, dx, dy, dw, dh)
|
627
627
|
img ||= self
|
628
628
|
@image.paint do |painter|
|
629
629
|
painter.image img.getInternal__, sx, sy, sw, sh, dx, dy, dw, dh
|
@@ -634,12 +634,12 @@ module RubySketch
|
|
634
634
|
#
|
635
635
|
# @param filename [String] file name to save image
|
636
636
|
#
|
637
|
-
def save
|
637
|
+
def save(filename)
|
638
638
|
@image.save filename
|
639
639
|
end
|
640
640
|
|
641
641
|
# @private
|
642
|
-
def getInternal__
|
642
|
+
def getInternal__()
|
643
643
|
@image
|
644
644
|
end
|
645
645
|
|
@@ -651,7 +651,7 @@ module RubySketch
|
|
651
651
|
class Font
|
652
652
|
|
653
653
|
# @private
|
654
|
-
def initialize
|
654
|
+
def initialize(font)
|
655
655
|
@font = font
|
656
656
|
end
|
657
657
|
|
@@ -668,7 +668,7 @@ module RubySketch
|
|
668
668
|
#
|
669
669
|
# @return [TextBounds] bounding box for text
|
670
670
|
#
|
671
|
-
def textBounds
|
671
|
+
def textBounds(str, x = 0, y = 0, fontSize = nil)
|
672
672
|
f = fontSize ? Rays::Font.new(@font.name, fontSize) : @font
|
673
673
|
TextBounds.new x, y, x + f.width(str), y + f.height
|
674
674
|
end
|
@@ -697,7 +697,7 @@ module RubySketch
|
|
697
697
|
attr_reader :h
|
698
698
|
|
699
699
|
# @private
|
700
|
-
def initialize
|
700
|
+
def initialize(x, y, w, h)
|
701
701
|
@x, @y, @w, @h = x, y, w, h
|
702
702
|
end
|
703
703
|
|
@@ -717,11 +717,11 @@ module RubySketch
|
|
717
717
|
attr_reader :y
|
718
718
|
|
719
719
|
# @private
|
720
|
-
def initialize
|
720
|
+
def initialize(x, y)
|
721
721
|
@x, @y = x, y
|
722
722
|
end
|
723
723
|
|
724
|
-
def id
|
724
|
+
def id()
|
725
725
|
raise NotImplementedError
|
726
726
|
end
|
727
727
|
|
@@ -736,7 +736,7 @@ module RubySketch
|
|
736
736
|
#
|
737
737
|
# @return [Array] device name list
|
738
738
|
#
|
739
|
-
def self.list
|
739
|
+
def self.list()
|
740
740
|
Rays::Camera.device_names
|
741
741
|
end
|
742
742
|
|
@@ -751,7 +751,7 @@ module RubySketch
|
|
751
751
|
# @param requestHeight [Integer] captured image height
|
752
752
|
# @param cameraName [String] camera device name
|
753
753
|
#
|
754
|
-
def initialize
|
754
|
+
def initialize(*args)
|
755
755
|
width, height, name =
|
756
756
|
if args.empty?
|
757
757
|
[-1, -1, nil]
|
@@ -769,7 +769,7 @@ module RubySketch
|
|
769
769
|
#
|
770
770
|
# @return [nil] nil
|
771
771
|
#
|
772
|
-
def start
|
772
|
+
def start()
|
773
773
|
raise "Failed to start capture" unless @camera.start
|
774
774
|
nil
|
775
775
|
end
|
@@ -778,7 +778,7 @@ module RubySketch
|
|
778
778
|
#
|
779
779
|
# @return [nil] nil
|
780
780
|
#
|
781
|
-
def stop
|
781
|
+
def stop()
|
782
782
|
@camera.stop
|
783
783
|
nil
|
784
784
|
end
|
@@ -787,13 +787,13 @@ module RubySketch
|
|
787
787
|
#
|
788
788
|
# @return [Boolean] true means object has next frame
|
789
789
|
#
|
790
|
-
def available
|
790
|
+
def available()
|
791
791
|
@camera.active?
|
792
792
|
end
|
793
793
|
|
794
794
|
# Reads next frame image
|
795
795
|
#
|
796
|
-
def read
|
796
|
+
def read()
|
797
797
|
@camera.image
|
798
798
|
end
|
799
799
|
|
@@ -801,7 +801,7 @@ module RubySketch
|
|
801
801
|
#
|
802
802
|
# @return [Numeric] the width of captured image
|
803
803
|
#
|
804
|
-
def width
|
804
|
+
def width()
|
805
805
|
@camera.image&.width || 0
|
806
806
|
end
|
807
807
|
|
@@ -809,17 +809,17 @@ module RubySketch
|
|
809
809
|
#
|
810
810
|
# @return [Numeric] the height of captured image
|
811
811
|
#
|
812
|
-
def height
|
812
|
+
def height()
|
813
813
|
@camera.image&.height || 0
|
814
814
|
end
|
815
815
|
|
816
816
|
# @private
|
817
|
-
def getInternal__
|
817
|
+
def getInternal__()
|
818
818
|
@camera.image || dummyImage__
|
819
819
|
end
|
820
820
|
|
821
821
|
# @private
|
822
|
-
private def dummyImage__
|
822
|
+
private def dummyImage__()
|
823
823
|
@dummy ||= Rays::Image.new 1, 1
|
824
824
|
end
|
825
825
|
|
@@ -852,50 +852,99 @@ module RubySketch
|
|
852
852
|
|
853
853
|
# RGB mode for colorMode().
|
854
854
|
#
|
855
|
-
RGB = :
|
855
|
+
RGB = :rgb
|
856
856
|
|
857
857
|
# HSB mode for colorMode().
|
858
858
|
#
|
859
|
-
HSB = :
|
859
|
+
HSB = :hsb
|
860
860
|
|
861
861
|
# Radian mode for angleMode().
|
862
862
|
#
|
863
|
-
RADIANS = :
|
863
|
+
RADIANS = :radians
|
864
864
|
|
865
865
|
# Degree mode for angleMode().
|
866
866
|
#
|
867
|
-
DEGREES = :
|
867
|
+
DEGREES = :degrees
|
868
868
|
|
869
869
|
# Mode for rectMode(), ellipseMode() and imageMode().
|
870
870
|
#
|
871
|
-
CORNER = :
|
871
|
+
CORNER = :corner
|
872
872
|
|
873
873
|
# Mode for rectMode(), ellipseMode() and imageMode().
|
874
874
|
#
|
875
|
-
CORNERS = :
|
875
|
+
CORNERS = :corners
|
876
876
|
|
877
877
|
# Mode for rectMode(), ellipseMode(), imageMode() and textAlign().
|
878
878
|
#
|
879
|
-
CENTER = :
|
879
|
+
CENTER = :center
|
880
880
|
|
881
881
|
# Mode for rectMode() and ellipseMode().
|
882
882
|
#
|
883
|
-
RADIUS = :
|
883
|
+
RADIUS = :radius
|
884
|
+
|
885
|
+
# Key codes.
|
886
|
+
ENTER = :enter
|
887
|
+
SPACE = :space
|
888
|
+
TAB = :tab
|
889
|
+
DELETE = :delete
|
890
|
+
BACKSPACE = :backspace
|
891
|
+
ESC = :escape
|
892
|
+
HOME = :home
|
893
|
+
#END = :end
|
894
|
+
PAGEUP = :pageup
|
895
|
+
PAGEDOWN = :pagedown
|
896
|
+
CLEAR = :clear
|
897
|
+
SHIFT = :shift
|
898
|
+
CONTROL = :control
|
899
|
+
ALT = :alt
|
900
|
+
WIN = :win
|
901
|
+
COMMAND = :command
|
902
|
+
OPTION = :option
|
903
|
+
FUNCTION = :function
|
904
|
+
CAPSLOCK = :capslock
|
905
|
+
SECTION = :section
|
906
|
+
HELP = :help
|
907
|
+
F1 = :f1
|
908
|
+
F2 = :f2
|
909
|
+
F3 = :f3
|
910
|
+
F4 = :f4
|
911
|
+
F5 = :f5
|
912
|
+
F6 = :f6
|
913
|
+
F7 = :f7
|
914
|
+
F8 = :f8
|
915
|
+
F9 = :f9
|
916
|
+
F10 = :f10
|
917
|
+
F11 = :f11
|
918
|
+
F12 = :f12
|
919
|
+
F13 = :f13
|
920
|
+
F14 = :f14
|
921
|
+
F15 = :f15
|
922
|
+
F16 = :f16
|
923
|
+
F17 = :f17
|
924
|
+
F18 = :f18
|
925
|
+
F19 = :f19
|
926
|
+
F20 = :f20
|
927
|
+
F21 = :f21
|
928
|
+
F22 = :f22
|
929
|
+
F23 = :f23
|
930
|
+
F24 = :f24
|
931
|
+
UP = :up
|
932
|
+
DOWN = :down
|
933
|
+
|
934
|
+
# Key code or Mode for textAlign().
|
935
|
+
LEFT = :left
|
936
|
+
|
937
|
+
# Key code or Mode for textAlign().
|
938
|
+
RIGHT = :right
|
884
939
|
|
885
940
|
# Mode for textAlign().
|
886
|
-
|
941
|
+
TOP = :top
|
887
942
|
|
888
943
|
# Mode for textAlign().
|
889
|
-
|
944
|
+
BOTTOM = :bottom
|
890
945
|
|
891
946
|
# Mode for textAlign().
|
892
|
-
|
893
|
-
|
894
|
-
# Mode for textAlign().
|
895
|
-
BOTTOM = :BOTTOM
|
896
|
-
|
897
|
-
# Mode for textAlign().
|
898
|
-
BASELINE = :BASELINE
|
947
|
+
BASELINE = :baseline
|
899
948
|
|
900
949
|
# Mode for strokeCap().
|
901
950
|
#
|
@@ -913,7 +962,7 @@ module RubySketch
|
|
913
962
|
#
|
914
963
|
SQUARE = :square
|
915
964
|
|
916
|
-
def init__
|
965
|
+
def init__(image, painter)
|
917
966
|
@drawing__ = false
|
918
967
|
@hsbColor__ = false
|
919
968
|
@colorMaxes__ = [1.0] * 4
|
@@ -937,29 +986,30 @@ module RubySketch
|
|
937
986
|
|
938
987
|
fill 255
|
939
988
|
stroke 0
|
989
|
+
strokeWeight 1
|
940
990
|
end
|
941
991
|
|
942
|
-
def updateCanvas__
|
992
|
+
def updateCanvas__(image, painter)
|
943
993
|
@image__, @painter__ = image, painter
|
944
994
|
end
|
945
995
|
|
946
996
|
# @private
|
947
|
-
def beginDraw__
|
997
|
+
def beginDraw__()
|
948
998
|
@matrixStack__.clear
|
949
999
|
@styleStack__.clear
|
950
1000
|
@drawing__ = true
|
951
1001
|
end
|
952
1002
|
|
953
1003
|
# @private
|
954
|
-
def endDraw__
|
1004
|
+
def endDraw__()
|
955
1005
|
@drawing__ = false
|
956
1006
|
end
|
957
1007
|
|
958
|
-
def width
|
1008
|
+
def width()
|
959
1009
|
@image__.width
|
960
1010
|
end
|
961
1011
|
|
962
|
-
def height
|
1012
|
+
def height()
|
963
1013
|
@image__.height
|
964
1014
|
end
|
965
1015
|
|
@@ -979,8 +1029,8 @@ module RubySketch
|
|
979
1029
|
#
|
980
1030
|
# @return [nil] nil
|
981
1031
|
#
|
982
|
-
def colorMode
|
983
|
-
mode = mode.
|
1032
|
+
def colorMode(mode, *maxes)
|
1033
|
+
mode = mode.downcase.to_sym
|
984
1034
|
raise ArgumentError, "invalid color mode: #{mode}" unless [RGB, HSB].include?(mode)
|
985
1035
|
raise ArgumentError unless [0, 1, 3, 4].include?(maxes.size)
|
986
1036
|
|
@@ -993,7 +1043,7 @@ module RubySketch
|
|
993
1043
|
end
|
994
1044
|
|
995
1045
|
# @private
|
996
|
-
private def toRGBA__
|
1046
|
+
private def toRGBA__(*args)
|
997
1047
|
a, b, c, d = args
|
998
1048
|
return parseColor__(a, b || alphaMax__) if a.kind_of?(String)
|
999
1049
|
|
@@ -1008,8 +1058,8 @@ module RubySketch
|
|
1008
1058
|
end
|
1009
1059
|
|
1010
1060
|
# @private
|
1011
|
-
private def parseColor__
|
1012
|
-
result = str.match
|
1061
|
+
private def parseColor__(str, alpha)
|
1062
|
+
result = str.match(/^\s*##{'([0-9a-f]{2})' * 3}\s*$/i)
|
1013
1063
|
raise ArgumentError, "invalid color code: '#{str}'" unless result
|
1014
1064
|
|
1015
1065
|
rgb = result[1..3].map.with_index {|hex, i| hex.to_i(16) / 255.0}
|
@@ -1017,7 +1067,7 @@ module RubySketch
|
|
1017
1067
|
end
|
1018
1068
|
|
1019
1069
|
# @private
|
1020
|
-
private def alphaMax__
|
1070
|
+
private def alphaMax__()
|
1021
1071
|
@colorMaxes__[3]
|
1022
1072
|
end
|
1023
1073
|
|
@@ -1027,8 +1077,8 @@ module RubySketch
|
|
1027
1077
|
#
|
1028
1078
|
# @return [nil] nil
|
1029
1079
|
#
|
1030
|
-
def angleMode
|
1031
|
-
@angleScale__ = case mode.
|
1080
|
+
def angleMode(mode)
|
1081
|
+
@angleScale__ = case mode.downcase.to_sym
|
1032
1082
|
when RADIANS then RAD2DEG__
|
1033
1083
|
when DEGREES then 1.0
|
1034
1084
|
else raise ArgumentError, "invalid angle mode: #{mode}"
|
@@ -1037,7 +1087,7 @@ module RubySketch
|
|
1037
1087
|
end
|
1038
1088
|
|
1039
1089
|
# @private
|
1040
|
-
def toAngle__
|
1090
|
+
def toAngle__(angle)
|
1041
1091
|
angle * @angleScale__
|
1042
1092
|
end
|
1043
1093
|
|
@@ -1052,7 +1102,7 @@ module RubySketch
|
|
1052
1102
|
#
|
1053
1103
|
# @return [nil] nil
|
1054
1104
|
#
|
1055
|
-
def rectMode
|
1105
|
+
def rectMode(mode)
|
1056
1106
|
@rectMode__ = mode
|
1057
1107
|
end
|
1058
1108
|
|
@@ -1067,7 +1117,7 @@ module RubySketch
|
|
1067
1117
|
#
|
1068
1118
|
# @return [nil] nil
|
1069
1119
|
#
|
1070
|
-
def ellipseMode
|
1120
|
+
def ellipseMode(mode)
|
1071
1121
|
@ellipseMode__ = mode
|
1072
1122
|
end
|
1073
1123
|
|
@@ -1081,12 +1131,12 @@ module RubySketch
|
|
1081
1131
|
#
|
1082
1132
|
# @return [nil] nil
|
1083
1133
|
#
|
1084
|
-
def imageMode
|
1134
|
+
def imageMode(mode)
|
1085
1135
|
@imageMode__ = mode
|
1086
1136
|
end
|
1087
1137
|
|
1088
1138
|
# @private
|
1089
|
-
private def toXYWH__
|
1139
|
+
private def toXYWH__(mode, a, b, c, d)
|
1090
1140
|
case mode
|
1091
1141
|
when CORNER then [a, b, c, d]
|
1092
1142
|
when CORNERS then [a, b, c - a, d - b]
|
@@ -1114,7 +1164,7 @@ module RubySketch
|
|
1114
1164
|
#
|
1115
1165
|
# @return [nil] nil
|
1116
1166
|
#
|
1117
|
-
def fill
|
1167
|
+
def fill(*args)
|
1118
1168
|
@painter__.fill(*toRGBA__(*args))
|
1119
1169
|
nil
|
1120
1170
|
end
|
@@ -1137,7 +1187,7 @@ module RubySketch
|
|
1137
1187
|
#
|
1138
1188
|
# @return [nil] nil
|
1139
1189
|
#
|
1140
|
-
def stroke
|
1190
|
+
def stroke(*args)
|
1141
1191
|
@painter__.stroke(*toRGBA__(*args))
|
1142
1192
|
nil
|
1143
1193
|
end
|
@@ -1148,7 +1198,7 @@ module RubySketch
|
|
1148
1198
|
#
|
1149
1199
|
# @return [nil] nil
|
1150
1200
|
#
|
1151
|
-
def strokeWeight
|
1201
|
+
def strokeWeight(weight)
|
1152
1202
|
@painter__.stroke_width weight
|
1153
1203
|
nil
|
1154
1204
|
end
|
@@ -1159,7 +1209,7 @@ module RubySketch
|
|
1159
1209
|
#
|
1160
1210
|
# @return [nil] nil
|
1161
1211
|
#
|
1162
|
-
def strokeCap
|
1212
|
+
def strokeCap(cap)
|
1163
1213
|
@painter__.stroke_cap cap
|
1164
1214
|
nil
|
1165
1215
|
end
|
@@ -1170,7 +1220,7 @@ module RubySketch
|
|
1170
1220
|
#
|
1171
1221
|
# @return [nil] nil
|
1172
1222
|
#
|
1173
|
-
def strokeJoin
|
1223
|
+
def strokeJoin(join)
|
1174
1224
|
@painter__.stroke_join join
|
1175
1225
|
nil
|
1176
1226
|
end
|
@@ -1179,7 +1229,7 @@ module RubySketch
|
|
1179
1229
|
#
|
1180
1230
|
# @return [nil] nil
|
1181
1231
|
#
|
1182
|
-
def noFill
|
1232
|
+
def noFill()
|
1183
1233
|
@painter__.fill nil
|
1184
1234
|
nil
|
1185
1235
|
end
|
@@ -1188,7 +1238,7 @@ module RubySketch
|
|
1188
1238
|
#
|
1189
1239
|
# @return [nil] nil
|
1190
1240
|
#
|
1191
|
-
def noStroke
|
1241
|
+
def noStroke()
|
1192
1242
|
@painter__.stroke nil
|
1193
1243
|
nil
|
1194
1244
|
end
|
@@ -1200,7 +1250,7 @@ module RubySketch
|
|
1200
1250
|
#
|
1201
1251
|
# @return [Font] current font
|
1202
1252
|
#
|
1203
|
-
def textFont
|
1253
|
+
def textFont(name = nil, size = nil)
|
1204
1254
|
setFont__ name, size if name || size
|
1205
1255
|
Font.new @painter__.font
|
1206
1256
|
end
|
@@ -1211,30 +1261,30 @@ module RubySketch
|
|
1211
1261
|
#
|
1212
1262
|
# @return [nil] nil
|
1213
1263
|
#
|
1214
|
-
def textSize
|
1264
|
+
def textSize(size)
|
1215
1265
|
setFont__ @painter__.font.name, size
|
1216
1266
|
nil
|
1217
1267
|
end
|
1218
1268
|
|
1219
|
-
def textWidth
|
1269
|
+
def textWidth(str)
|
1220
1270
|
@painter__.font.width str
|
1221
1271
|
end
|
1222
1272
|
|
1223
|
-
def textAscent
|
1273
|
+
def textAscent()
|
1224
1274
|
@painter__.font.ascent
|
1225
1275
|
end
|
1226
1276
|
|
1227
|
-
def textDescent
|
1277
|
+
def textDescent()
|
1228
1278
|
@painter__.font.descent
|
1229
1279
|
end
|
1230
1280
|
|
1231
|
-
def textAlign
|
1281
|
+
def textAlign(horizontal, vertical = BASELINE)
|
1232
1282
|
@textAlignH__ = horizontal
|
1233
1283
|
@textAlignV__ = vertical
|
1234
1284
|
end
|
1235
1285
|
|
1236
1286
|
# @private
|
1237
|
-
def setFont__
|
1287
|
+
def setFont__(name, size)
|
1238
1288
|
size = 256 if size && size > 256
|
1239
1289
|
@painter__.font name, size
|
1240
1290
|
end
|
@@ -1257,11 +1307,11 @@ module RubySketch
|
|
1257
1307
|
#
|
1258
1308
|
# @return [nil] nil
|
1259
1309
|
#
|
1260
|
-
def background
|
1310
|
+
def background(*args)
|
1261
1311
|
assertDrawing__
|
1262
|
-
rgba = toRGBA__
|
1312
|
+
rgba = toRGBA__(*args)
|
1263
1313
|
if rgba[3] == 1
|
1264
|
-
@painter__.background
|
1314
|
+
@painter__.background(*rgba)
|
1265
1315
|
else
|
1266
1316
|
@painter__.push fill: rgba, stroke: nil do |_|
|
1267
1317
|
@painter__.rect 0, 0, width, height
|
@@ -1277,7 +1327,7 @@ module RubySketch
|
|
1277
1327
|
#
|
1278
1328
|
# @return [nil] nil
|
1279
1329
|
#
|
1280
|
-
def point
|
1330
|
+
def point(x, y)
|
1281
1331
|
assertDrawing__
|
1282
1332
|
w = @painter__.stroke_width
|
1283
1333
|
w = 1 if w == 0
|
@@ -1294,7 +1344,7 @@ module RubySketch
|
|
1294
1344
|
#
|
1295
1345
|
# @return [nil] nil
|
1296
1346
|
#
|
1297
|
-
def line
|
1347
|
+
def line(x1, y1, x2, y2)
|
1298
1348
|
assertDrawing__
|
1299
1349
|
@painter__.line x1, y1, x2, y2
|
1300
1350
|
nil
|
@@ -1318,7 +1368,7 @@ module RubySketch
|
|
1318
1368
|
#
|
1319
1369
|
# @return [nil] nil
|
1320
1370
|
#
|
1321
|
-
def rect
|
1371
|
+
def rect(a, b, c, d, *args)
|
1322
1372
|
assertDrawing__
|
1323
1373
|
x, y, w, h = toXYWH__ @rectMode__, a, b, c, d
|
1324
1374
|
case args.size
|
@@ -1339,7 +1389,7 @@ module RubySketch
|
|
1339
1389
|
#
|
1340
1390
|
# @return [nil] nil
|
1341
1391
|
#
|
1342
|
-
def ellipse
|
1392
|
+
def ellipse(a, b, c, d)
|
1343
1393
|
assertDrawing__
|
1344
1394
|
x, y, w, h = toXYWH__ @ellipseMode__, a, b, c, d
|
1345
1395
|
@painter__.ellipse x, y, w, h
|
@@ -1354,7 +1404,7 @@ module RubySketch
|
|
1354
1404
|
#
|
1355
1405
|
# @return [nil] nil
|
1356
1406
|
#
|
1357
|
-
def circle
|
1407
|
+
def circle(x, y, extent)
|
1358
1408
|
ellipse x, y, extent, extent
|
1359
1409
|
end
|
1360
1410
|
|
@@ -1369,11 +1419,11 @@ module RubySketch
|
|
1369
1419
|
#
|
1370
1420
|
# @return [nil] nil
|
1371
1421
|
#
|
1372
|
-
def arc
|
1422
|
+
def arc(a, b, c, d, start, stop)
|
1373
1423
|
assertDrawing__
|
1374
1424
|
x, y, w, h = toXYWH__ @ellipseMode__, a, b, c, d
|
1375
|
-
start = toAngle__
|
1376
|
-
stop = toAngle__
|
1425
|
+
start = toAngle__(-start)
|
1426
|
+
stop = toAngle__(-stop)
|
1377
1427
|
@painter__.ellipse x, y, w, h, from: start, to: stop
|
1378
1428
|
nil
|
1379
1429
|
end
|
@@ -1386,7 +1436,7 @@ module RubySketch
|
|
1386
1436
|
#
|
1387
1437
|
# @return [nil] nil
|
1388
1438
|
#
|
1389
|
-
def square
|
1439
|
+
def square(x, y, extent)
|
1390
1440
|
rect x, y, extent, extent
|
1391
1441
|
end
|
1392
1442
|
|
@@ -1401,7 +1451,7 @@ module RubySketch
|
|
1401
1451
|
#
|
1402
1452
|
# @return [nil] nil
|
1403
1453
|
#
|
1404
|
-
def triangle
|
1454
|
+
def triangle(x1, y1, x2, y2, x3, y3)
|
1405
1455
|
assertDrawing__
|
1406
1456
|
@painter__.line x1, y1, x2, y2, x3, y3, loop: true
|
1407
1457
|
nil
|
@@ -1420,7 +1470,7 @@ module RubySketch
|
|
1420
1470
|
#
|
1421
1471
|
# @return [nil] nil
|
1422
1472
|
#
|
1423
|
-
def quad
|
1473
|
+
def quad(x1, y1, x2, y2, x3, y3, x4, y4)
|
1424
1474
|
assertDrawing__
|
1425
1475
|
@painter__.line x1, y1, x2, y2, x3, y3, x4, y4, loop: true
|
1426
1476
|
nil
|
@@ -1439,7 +1489,7 @@ module RubySketch
|
|
1439
1489
|
#
|
1440
1490
|
# @return [nil] nil
|
1441
1491
|
#
|
1442
|
-
def curve
|
1492
|
+
def curve(cx1, cy1, x1, y1, x2, y2, cx2, cy2)
|
1443
1493
|
assertDrawing__
|
1444
1494
|
@painter__.curve cx1, cy1, x1, y1, x2, y2, cx2, cy2
|
1445
1495
|
nil
|
@@ -1458,7 +1508,7 @@ module RubySketch
|
|
1458
1508
|
#
|
1459
1509
|
# @return [nil] nil
|
1460
1510
|
#
|
1461
|
-
def bezier
|
1511
|
+
def bezier(x1, y1, cx1, cy1, cx2, cy2, x2, y2)
|
1462
1512
|
assertDrawing__
|
1463
1513
|
@painter__.bezier x1, y1, cx1, cy1, cx2, cy2, x2, y2
|
1464
1514
|
nil
|
@@ -1480,7 +1530,7 @@ module RubySketch
|
|
1480
1530
|
#
|
1481
1531
|
# @return [nil] nil
|
1482
1532
|
#
|
1483
|
-
def text
|
1533
|
+
def text(str, x, y, x2 = nil, y2 = nil)
|
1484
1534
|
assertDrawing__
|
1485
1535
|
if x2
|
1486
1536
|
raise ArgumentError, "missing y2 parameter" unless y2
|
@@ -1514,7 +1564,7 @@ module RubySketch
|
|
1514
1564
|
#
|
1515
1565
|
# @return [nil] nil
|
1516
1566
|
#
|
1517
|
-
def image
|
1567
|
+
def image(img, a, b, c = nil, d = nil)
|
1518
1568
|
assertDrawing__
|
1519
1569
|
i = img.getInternal__
|
1520
1570
|
x, y, w, h = toXYWH__ @imageMode__, a, b, c || i.width, d || i.height
|
@@ -1539,7 +1589,7 @@ module RubySketch
|
|
1539
1589
|
#
|
1540
1590
|
# @return [nil] nil
|
1541
1591
|
#
|
1542
|
-
def copy
|
1592
|
+
def copy(img = nil, sx, sy, sw, sh, dx, dy, dw, dh)
|
1543
1593
|
assertDrawing__
|
1544
1594
|
src = img&.getInternal__ || @window__.canvas
|
1545
1595
|
@painter__.image src, sx, sy, sw, sh, dx, dy, dw, dh
|
@@ -1552,7 +1602,7 @@ module RubySketch
|
|
1552
1602
|
#
|
1553
1603
|
# @return [nil] nil
|
1554
1604
|
#
|
1555
|
-
def translate
|
1605
|
+
def translate(x, y)
|
1556
1606
|
assertDrawing__
|
1557
1607
|
@painter__.translate x, y
|
1558
1608
|
nil
|
@@ -1569,7 +1619,7 @@ module RubySketch
|
|
1569
1619
|
#
|
1570
1620
|
# @return [nil] nil
|
1571
1621
|
#
|
1572
|
-
def scale
|
1622
|
+
def scale(x, y)
|
1573
1623
|
assertDrawing__
|
1574
1624
|
@painter__.scale x, y
|
1575
1625
|
nil
|
@@ -1581,7 +1631,7 @@ module RubySketch
|
|
1581
1631
|
#
|
1582
1632
|
# @return [nil] nil
|
1583
1633
|
#
|
1584
|
-
def rotate
|
1634
|
+
def rotate(angle)
|
1585
1635
|
assertDrawing__
|
1586
1636
|
@painter__.rotate toAngle__ angle
|
1587
1637
|
nil
|
@@ -1591,7 +1641,7 @@ module RubySketch
|
|
1591
1641
|
#
|
1592
1642
|
# @return [nil] nil
|
1593
1643
|
#
|
1594
|
-
def pushMatrix
|
1644
|
+
def pushMatrix(&block)
|
1595
1645
|
assertDrawing__
|
1596
1646
|
@matrixStack__.push @painter__.matrix
|
1597
1647
|
if block
|
@@ -1605,7 +1655,7 @@ module RubySketch
|
|
1605
1655
|
#
|
1606
1656
|
# @return [nil] nil
|
1607
1657
|
#
|
1608
|
-
def popMatrix
|
1658
|
+
def popMatrix()
|
1609
1659
|
assertDrawing__
|
1610
1660
|
raise "matrix stack underflow" if @matrixStack__.empty?
|
1611
1661
|
@painter__.matrix = @matrixStack__.pop
|
@@ -1616,7 +1666,7 @@ module RubySketch
|
|
1616
1666
|
#
|
1617
1667
|
# @return [nil] nil
|
1618
1668
|
#
|
1619
|
-
def resetMatrix
|
1669
|
+
def resetMatrix()
|
1620
1670
|
assertDrawing__
|
1621
1671
|
@painter__.matrix = 1
|
1622
1672
|
nil
|
@@ -1626,7 +1676,7 @@ module RubySketch
|
|
1626
1676
|
#
|
1627
1677
|
# @return [nil] nil
|
1628
1678
|
#
|
1629
|
-
def pushStyle
|
1679
|
+
def pushStyle(&block)
|
1630
1680
|
assertDrawing__
|
1631
1681
|
@styleStack__.push [
|
1632
1682
|
@painter__.fill,
|
@@ -1653,7 +1703,7 @@ module RubySketch
|
|
1653
1703
|
#
|
1654
1704
|
# @return [nil] nil
|
1655
1705
|
#
|
1656
|
-
def popStyle
|
1706
|
+
def popStyle()
|
1657
1707
|
assertDrawing__
|
1658
1708
|
raise "style stack underflow" if @styleStack__.empty?
|
1659
1709
|
@painter__.fill,
|
@@ -1675,7 +1725,7 @@ module RubySketch
|
|
1675
1725
|
#
|
1676
1726
|
# @return [nil] nil
|
1677
1727
|
#
|
1678
|
-
def push
|
1728
|
+
def push(&block)
|
1679
1729
|
pushMatrix
|
1680
1730
|
pushStyle
|
1681
1731
|
if block
|
@@ -1688,18 +1738,18 @@ module RubySketch
|
|
1688
1738
|
#
|
1689
1739
|
# @return [nil] nil
|
1690
1740
|
#
|
1691
|
-
def pop
|
1741
|
+
def pop()
|
1692
1742
|
popMatrix
|
1693
1743
|
popStyle
|
1694
1744
|
end
|
1695
1745
|
|
1696
1746
|
# @private
|
1697
|
-
def getInternal__
|
1747
|
+
def getInternal__()
|
1698
1748
|
@image__
|
1699
1749
|
end
|
1700
1750
|
|
1701
1751
|
# @private
|
1702
|
-
private def assertDrawing__
|
1752
|
+
private def assertDrawing__()
|
1703
1753
|
raise "call beginDraw() before drawing" unless @drawing__
|
1704
1754
|
end
|
1705
1755
|
|
@@ -1714,14 +1764,14 @@ module RubySketch
|
|
1714
1764
|
|
1715
1765
|
# Initialize graphics object.
|
1716
1766
|
#
|
1717
|
-
def initialize
|
1767
|
+
def initialize(width, height)
|
1718
1768
|
image = Rays::Image.new width, height
|
1719
1769
|
init__ image, image.painter
|
1720
1770
|
end
|
1721
1771
|
|
1722
1772
|
# Start drawing.
|
1723
1773
|
#
|
1724
|
-
def beginDraw
|
1774
|
+
def beginDraw(&block)
|
1725
1775
|
@painter__.__send__ :begin_paint
|
1726
1776
|
beginDraw__
|
1727
1777
|
push
|
@@ -1733,7 +1783,7 @@ module RubySketch
|
|
1733
1783
|
|
1734
1784
|
# End drawing.
|
1735
1785
|
#
|
1736
|
-
def endDraw
|
1786
|
+
def endDraw()
|
1737
1787
|
pop
|
1738
1788
|
endDraw__
|
1739
1789
|
@painter__.__send__ :end_paint
|
@@ -1756,12 +1806,12 @@ module RubySketch
|
|
1756
1806
|
@@context__ = nil
|
1757
1807
|
|
1758
1808
|
# @private
|
1759
|
-
def self.context__
|
1809
|
+
def self.context__()
|
1760
1810
|
@@context__
|
1761
1811
|
end
|
1762
1812
|
|
1763
1813
|
# @private
|
1764
|
-
def initialize
|
1814
|
+
def initialize(window)
|
1765
1815
|
@@context__ = self
|
1766
1816
|
|
1767
1817
|
tmpdir__.tap {|dir| FileUtils.rm_r dir.to_s if dir.directory?}
|
@@ -1769,13 +1819,16 @@ module RubySketch
|
|
1769
1819
|
@window__ = window
|
1770
1820
|
init__ @window__.canvas, @window__.canvas_painter.paint {background 0.8}
|
1771
1821
|
|
1772
|
-
@loop__
|
1773
|
-
@redraw__
|
1774
|
-
@frameCount__
|
1775
|
-
@
|
1776
|
-
@
|
1777
|
-
@
|
1778
|
-
@
|
1822
|
+
@loop__ = true
|
1823
|
+
@redraw__ = false
|
1824
|
+
@frameCount__ = 0
|
1825
|
+
@key__ = nil
|
1826
|
+
@keyCode__ = nil
|
1827
|
+
@keysPressed__ = Set.new
|
1828
|
+
@pointerPos__ =
|
1829
|
+
@pointerPrevPos__ = [0, 0]
|
1830
|
+
@pointersPressed__ = Set.new
|
1831
|
+
@touches__ = []
|
1779
1832
|
|
1780
1833
|
@window__.before_draw = proc {beginDraw__}
|
1781
1834
|
@window__.after_draw = proc {endDraw__}
|
@@ -1796,17 +1849,38 @@ module RubySketch
|
|
1796
1849
|
@redraw__ = false
|
1797
1850
|
drawFrame.call
|
1798
1851
|
end
|
1799
|
-
@
|
1852
|
+
@pointerPrevPos__ = @pointerPos__
|
1800
1853
|
end
|
1801
1854
|
|
1855
|
+
updateKeyStates = -> event, pressed {
|
1856
|
+
@key__ = event.chars
|
1857
|
+
@keyCode__ = event.key
|
1858
|
+
if pressed != nil
|
1859
|
+
set, key = @keysPressed__, event.key
|
1860
|
+
pressed ? set.add(key) : set.delete(key)
|
1861
|
+
end
|
1862
|
+
}
|
1863
|
+
|
1802
1864
|
updatePointerStates = -> event, pressed = nil {
|
1803
|
-
@
|
1804
|
-
@
|
1805
|
-
|
1806
|
-
|
1807
|
-
|
1865
|
+
@pointerPos__ = event.pos.to_a
|
1866
|
+
@touches__ = event.positions.map {|pos| Touch.new(*pos.to_a)}
|
1867
|
+
if pressed != nil
|
1868
|
+
set, type = @pointersPressed__, event.pointer_type
|
1869
|
+
pressed ? set.add(type) : set.delete(type)
|
1870
|
+
end
|
1808
1871
|
}
|
1809
1872
|
|
1873
|
+
@window__.key_down = proc do |e|
|
1874
|
+
updateKeyStates.call e, true
|
1875
|
+
@keyPressedBlock__&.call
|
1876
|
+
@keyTypedBlock__&.call unless @key__.empty?
|
1877
|
+
end
|
1878
|
+
|
1879
|
+
@window__.key_up = proc do |e|
|
1880
|
+
updateKeyStates.call e, false
|
1881
|
+
@keyReleasedBlock__&.call
|
1882
|
+
end
|
1883
|
+
|
1810
1884
|
@window__.pointer_down = proc do |e|
|
1811
1885
|
updatePointerStates.call e, true
|
1812
1886
|
(@touchStartedBlock__ || @mousePressedBlock__)&.call
|
@@ -1826,77 +1900,108 @@ module RubySketch
|
|
1826
1900
|
updatePointerStates.call e
|
1827
1901
|
(@touchMovedBlock__ || @mouseDraggedBlock__)&.call
|
1828
1902
|
end
|
1903
|
+
|
1904
|
+
@window__.motion = proc do |e|
|
1905
|
+
@motionGravity__ = createVector(*e.gravity.to_a(3))
|
1906
|
+
@motionBlock__&.call
|
1907
|
+
end
|
1829
1908
|
end
|
1830
1909
|
|
1831
|
-
#
|
1910
|
+
# Defines setup block.
|
1832
1911
|
#
|
1833
|
-
def setup
|
1912
|
+
def setup(&block)
|
1834
1913
|
@window__.setup = block
|
1835
1914
|
nil
|
1836
1915
|
end
|
1837
1916
|
|
1838
|
-
#
|
1917
|
+
# Defines draw block.
|
1839
1918
|
#
|
1840
|
-
def draw
|
1919
|
+
def draw(&block)
|
1841
1920
|
@drawBlock__ = block if block
|
1842
1921
|
nil
|
1843
1922
|
end
|
1844
1923
|
|
1845
|
-
#
|
1846
|
-
|
1847
|
-
|
1924
|
+
# Defines keyPressed block.
|
1925
|
+
#
|
1926
|
+
# @return [Boolean] is any key pressed or not
|
1927
|
+
#
|
1928
|
+
def keyPressed(&block)
|
1929
|
+
@keyPressedBlock__ = block if block
|
1930
|
+
not @keysPressed__.empty?
|
1931
|
+
end
|
1932
|
+
|
1933
|
+
# Defines keyReleased block.
|
1934
|
+
#
|
1935
|
+
def keyReleased(&block)
|
1936
|
+
@keyReleasedBlock__ = block if block
|
1848
1937
|
nil
|
1849
1938
|
end
|
1850
1939
|
|
1851
|
-
#
|
1940
|
+
# Defines keyTyped block.
|
1852
1941
|
#
|
1853
|
-
def
|
1942
|
+
def keyTyped(&block)
|
1943
|
+
@keyTypedBlock__ = block if block
|
1944
|
+
nil
|
1945
|
+
end
|
1946
|
+
|
1947
|
+
# Defines mousePressed block.
|
1948
|
+
#
|
1949
|
+
# @return [Boolean] is any mouse button pressed or not
|
1950
|
+
#
|
1951
|
+
def mousePressed(&block)
|
1854
1952
|
@mousePressedBlock__ = block if block
|
1855
|
-
@
|
1953
|
+
not @pointersPressed__.empty?
|
1856
1954
|
end
|
1857
1955
|
|
1858
|
-
#
|
1956
|
+
# Defines mouseReleased block.
|
1859
1957
|
#
|
1860
|
-
def mouseReleased
|
1958
|
+
def mouseReleased(&block)
|
1861
1959
|
@mouseReleasedBlock__ = block if block
|
1862
1960
|
nil
|
1863
1961
|
end
|
1864
1962
|
|
1865
|
-
#
|
1963
|
+
# Defines mouseMoved block.
|
1866
1964
|
#
|
1867
|
-
def mouseMoved
|
1965
|
+
def mouseMoved(&block)
|
1868
1966
|
@mouseMovedBlock__ = block if block
|
1869
1967
|
nil
|
1870
1968
|
end
|
1871
1969
|
|
1872
|
-
#
|
1970
|
+
# Defines mouseDragged block.
|
1873
1971
|
#
|
1874
|
-
def mouseDragged
|
1972
|
+
def mouseDragged(&block)
|
1875
1973
|
@mouseDraggedBlock__ = block if block
|
1876
1974
|
nil
|
1877
1975
|
end
|
1878
1976
|
|
1879
|
-
#
|
1977
|
+
# Defines touchStarted block.
|
1880
1978
|
#
|
1881
|
-
def touchStarted
|
1979
|
+
def touchStarted(&block)
|
1882
1980
|
@touchStartedBlock__ = block if block
|
1883
1981
|
nil
|
1884
1982
|
end
|
1885
1983
|
|
1886
|
-
#
|
1984
|
+
# Defines touchEnded block.
|
1887
1985
|
#
|
1888
|
-
def touchEnded
|
1986
|
+
def touchEnded(&block)
|
1889
1987
|
@touchEndedBlock__ = block if block
|
1890
1988
|
nil
|
1891
1989
|
end
|
1892
1990
|
|
1893
|
-
#
|
1991
|
+
# Defines touchMoved block.
|
1894
1992
|
#
|
1895
|
-
def touchMoved
|
1993
|
+
def touchMoved(&block)
|
1896
1994
|
@touchMovedBlock__ = block if block
|
1897
1995
|
nil
|
1898
1996
|
end
|
1899
1997
|
|
1998
|
+
# Defines motion block.
|
1999
|
+
#
|
2000
|
+
def motion(&block)
|
2001
|
+
@motionBlock__ = block if block
|
2002
|
+
nil
|
2003
|
+
end
|
2004
|
+
|
1900
2005
|
# Changes canvas size.
|
1901
2006
|
#
|
1902
2007
|
# @param width [Integer] new width
|
@@ -1905,7 +2010,7 @@ module RubySketch
|
|
1905
2010
|
#
|
1906
2011
|
# @return [nil] nil
|
1907
2012
|
#
|
1908
|
-
def size
|
2013
|
+
def size(width, height, pixelDensity: self.pixelDensity)
|
1909
2014
|
resizeCanvas__ :size, width, height, pixelDensity
|
1910
2015
|
nil
|
1911
2016
|
end
|
@@ -1918,7 +2023,7 @@ module RubySketch
|
|
1918
2023
|
#
|
1919
2024
|
# @return [nil] nil
|
1920
2025
|
#
|
1921
|
-
def createCanvas
|
2026
|
+
def createCanvas(width, height, pixelDensity: self.pixelDensity)
|
1922
2027
|
resizeCanvas__ :createCanvas, width, height, pixelDensity
|
1923
2028
|
nil
|
1924
2029
|
end
|
@@ -1929,13 +2034,13 @@ module RubySketch
|
|
1929
2034
|
#
|
1930
2035
|
# @return [Numeric] current pixel density
|
1931
2036
|
#
|
1932
|
-
def pixelDensity
|
2037
|
+
def pixelDensity(density = nil)
|
1933
2038
|
resizeCanvas__ :pixelDensity, width, height, density if density
|
1934
2039
|
@painter__.pixel_density
|
1935
2040
|
end
|
1936
2041
|
|
1937
2042
|
# @private
|
1938
|
-
def resizeCanvas__
|
2043
|
+
def resizeCanvas__(name, width, height, pixelDensity)
|
1939
2044
|
raise '#{name}() must be called on startup or setup block' if @started__
|
1940
2045
|
|
1941
2046
|
@painter__.__send__ :end_paint
|
@@ -1950,7 +2055,7 @@ module RubySketch
|
|
1950
2055
|
#
|
1951
2056
|
# @return [Numeric] pixel density
|
1952
2057
|
#
|
1953
|
-
def displayDensity
|
2058
|
+
def displayDensity()
|
1954
2059
|
@window__.painter.pixel_density
|
1955
2060
|
end
|
1956
2061
|
|
@@ -1958,7 +2063,7 @@ module RubySketch
|
|
1958
2063
|
#
|
1959
2064
|
# @return [Numeric] window width
|
1960
2065
|
#
|
1961
|
-
def windowWidth
|
2066
|
+
def windowWidth()
|
1962
2067
|
@window__.width
|
1963
2068
|
end
|
1964
2069
|
|
@@ -1966,7 +2071,7 @@ module RubySketch
|
|
1966
2071
|
#
|
1967
2072
|
# @return [Numeric] window height
|
1968
2073
|
#
|
1969
|
-
def windowHeight
|
2074
|
+
def windowHeight()
|
1970
2075
|
@window__.height
|
1971
2076
|
end
|
1972
2077
|
|
@@ -1974,7 +2079,7 @@ module RubySketch
|
|
1974
2079
|
#
|
1975
2080
|
# @return [Integer] total number of frames
|
1976
2081
|
#
|
1977
|
-
def frameCount
|
2082
|
+
def frameCount()
|
1978
2083
|
@frameCount__
|
1979
2084
|
end
|
1980
2085
|
|
@@ -1982,55 +2087,79 @@ module RubySketch
|
|
1982
2087
|
#
|
1983
2088
|
# @return [Float] frames per second
|
1984
2089
|
#
|
1985
|
-
def frameRate
|
2090
|
+
def frameRate()
|
1986
2091
|
@window__.event.fps
|
1987
2092
|
end
|
1988
2093
|
|
2094
|
+
# Returns the last key that was pressed or released.
|
2095
|
+
#
|
2096
|
+
# @return [String] last key
|
2097
|
+
#
|
2098
|
+
def key()
|
2099
|
+
@key__
|
2100
|
+
end
|
2101
|
+
|
2102
|
+
# Returns the last key code that was pressed or released.
|
2103
|
+
#
|
2104
|
+
# @return [Symbol] last key code
|
2105
|
+
#
|
2106
|
+
def keyCode()
|
2107
|
+
@keyCode__
|
2108
|
+
end
|
2109
|
+
|
1989
2110
|
# Returns mouse x position
|
1990
2111
|
#
|
1991
2112
|
# @return [Numeric] horizontal position of mouse
|
1992
2113
|
#
|
1993
|
-
def mouseX
|
1994
|
-
@
|
2114
|
+
def mouseX()
|
2115
|
+
@pointerPos__[0]
|
1995
2116
|
end
|
1996
2117
|
|
1997
2118
|
# Returns mouse y position
|
1998
2119
|
#
|
1999
2120
|
# @return [Numeric] vertical position of mouse
|
2000
2121
|
#
|
2001
|
-
def mouseY
|
2002
|
-
@
|
2122
|
+
def mouseY()
|
2123
|
+
@pointerPos__[1]
|
2003
2124
|
end
|
2004
2125
|
|
2005
2126
|
# Returns mouse x position in previous frame
|
2006
2127
|
#
|
2007
2128
|
# @return [Numeric] horizontal position of mouse
|
2008
2129
|
#
|
2009
|
-
def pmouseX
|
2010
|
-
@
|
2130
|
+
def pmouseX()
|
2131
|
+
@pointerPrevPos__[0]
|
2011
2132
|
end
|
2012
2133
|
|
2013
2134
|
# Returns mouse y position in previous frame
|
2014
2135
|
#
|
2015
2136
|
# @return [Numeric] vertical position of mouse
|
2016
2137
|
#
|
2017
|
-
def pmouseY
|
2018
|
-
@
|
2138
|
+
def pmouseY()
|
2139
|
+
@pointerPrevPos__[1]
|
2019
2140
|
end
|
2020
2141
|
|
2021
2142
|
# Returns array of touches
|
2022
2143
|
#
|
2023
2144
|
# @return [Array] Touch objects
|
2024
2145
|
#
|
2025
|
-
def touches
|
2146
|
+
def touches()
|
2026
2147
|
@touches__
|
2027
2148
|
end
|
2028
2149
|
|
2150
|
+
# Returns vector for real world gravity
|
2151
|
+
#
|
2152
|
+
# @return [Vector] gravity vector
|
2153
|
+
#
|
2154
|
+
def motionGravity()
|
2155
|
+
@motionGravity__
|
2156
|
+
end
|
2157
|
+
|
2029
2158
|
# Enables calling draw block on every frame.
|
2030
2159
|
#
|
2031
2160
|
# @return [nil] nil
|
2032
2161
|
#
|
2033
|
-
def loop
|
2162
|
+
def loop()
|
2034
2163
|
@loop__ = true
|
2035
2164
|
end
|
2036
2165
|
|
@@ -2038,7 +2167,7 @@ module RubySketch
|
|
2038
2167
|
#
|
2039
2168
|
# @return [nil] nil
|
2040
2169
|
#
|
2041
|
-
def noLoop
|
2170
|
+
def noLoop()
|
2042
2171
|
@loop__ = false
|
2043
2172
|
end
|
2044
2173
|
|
@@ -2046,7 +2175,7 @@ module RubySketch
|
|
2046
2175
|
#
|
2047
2176
|
# @return [nil] nil
|
2048
2177
|
#
|
2049
|
-
def redraw
|
2178
|
+
def redraw()
|
2050
2179
|
@redraw__ = true
|
2051
2180
|
end
|
2052
2181
|
|
@@ -2060,7 +2189,7 @@ module RubySketch
|
|
2060
2189
|
#
|
2061
2190
|
# @return [Numeric] absolute number
|
2062
2191
|
#
|
2063
|
-
def abs
|
2192
|
+
def abs(value)
|
2064
2193
|
value.abs
|
2065
2194
|
end
|
2066
2195
|
|
@@ -2070,7 +2199,7 @@ module RubySketch
|
|
2070
2199
|
#
|
2071
2200
|
# @return [Numeric] rounded up number
|
2072
2201
|
#
|
2073
|
-
def ceil
|
2202
|
+
def ceil(value)
|
2074
2203
|
value.ceil
|
2075
2204
|
end
|
2076
2205
|
|
@@ -2080,7 +2209,7 @@ module RubySketch
|
|
2080
2209
|
#
|
2081
2210
|
# @return [Numeric] rounded down number
|
2082
2211
|
#
|
2083
|
-
def floor
|
2212
|
+
def floor(value)
|
2084
2213
|
value.floor
|
2085
2214
|
end
|
2086
2215
|
|
@@ -2090,7 +2219,7 @@ module RubySketch
|
|
2090
2219
|
#
|
2091
2220
|
# @return [Numeric] rounded number
|
2092
2221
|
#
|
2093
|
-
def round
|
2222
|
+
def round(value)
|
2094
2223
|
value.round
|
2095
2224
|
end
|
2096
2225
|
|
@@ -2100,7 +2229,7 @@ module RubySketch
|
|
2100
2229
|
#
|
2101
2230
|
# @return [Numeric] result number
|
2102
2231
|
#
|
2103
|
-
def log
|
2232
|
+
def log(n)
|
2104
2233
|
Math.log n
|
2105
2234
|
end
|
2106
2235
|
|
@@ -2110,7 +2239,7 @@ module RubySketch
|
|
2110
2239
|
#
|
2111
2240
|
# @return [Numeric] result number
|
2112
2241
|
#
|
2113
|
-
def exp
|
2242
|
+
def exp(n)
|
2114
2243
|
Math.exp n
|
2115
2244
|
end
|
2116
2245
|
|
@@ -2121,7 +2250,7 @@ module RubySketch
|
|
2121
2250
|
#
|
2122
2251
|
# @return [Numeric] value ** exponent
|
2123
2252
|
#
|
2124
|
-
def pow
|
2253
|
+
def pow(value, exponent)
|
2125
2254
|
value ** exponent
|
2126
2255
|
end
|
2127
2256
|
|
@@ -2131,7 +2260,7 @@ module RubySketch
|
|
2131
2260
|
#
|
2132
2261
|
# @return [Numeric] squared value
|
2133
2262
|
#
|
2134
|
-
def sq
|
2263
|
+
def sq(value)
|
2135
2264
|
value * value
|
2136
2265
|
end
|
2137
2266
|
|
@@ -2141,7 +2270,7 @@ module RubySketch
|
|
2141
2270
|
#
|
2142
2271
|
# @return [Numeric] squared value
|
2143
2272
|
#
|
2144
|
-
def sqrt
|
2273
|
+
def sqrt(value)
|
2145
2274
|
Math.sqrt value
|
2146
2275
|
end
|
2147
2276
|
|
@@ -2156,7 +2285,7 @@ module RubySketch
|
|
2156
2285
|
#
|
2157
2286
|
# @return [Numeric] magnitude
|
2158
2287
|
#
|
2159
|
-
def mag
|
2288
|
+
def mag(*args)
|
2160
2289
|
x, y, z = *args
|
2161
2290
|
case args.size
|
2162
2291
|
when 2 then Math.sqrt x * x + y * y
|
@@ -2179,7 +2308,7 @@ module RubySketch
|
|
2179
2308
|
#
|
2180
2309
|
# @return [Numeric] distance between 2 points
|
2181
2310
|
#
|
2182
|
-
def dist
|
2311
|
+
def dist(*args)
|
2183
2312
|
case args.size
|
2184
2313
|
when 4
|
2185
2314
|
x1, y1, x2, y2 = *args
|
@@ -2201,7 +2330,7 @@ module RubySketch
|
|
2201
2330
|
#
|
2202
2331
|
# @return [Numeric] normalized value between 0..1
|
2203
2332
|
#
|
2204
|
-
def norm
|
2333
|
+
def norm(value, start, stop)
|
2205
2334
|
(value.to_f - start.to_f) / (stop.to_f - start.to_f)
|
2206
2335
|
end
|
2207
2336
|
|
@@ -2213,7 +2342,7 @@ module RubySketch
|
|
2213
2342
|
#
|
2214
2343
|
# @return [Numeric] interporated number
|
2215
2344
|
#
|
2216
|
-
def lerp
|
2345
|
+
def lerp(start, stop, amount)
|
2217
2346
|
start + (stop - start) * amount
|
2218
2347
|
end
|
2219
2348
|
|
@@ -2227,7 +2356,7 @@ module RubySketch
|
|
2227
2356
|
#
|
2228
2357
|
# @return [Numeric] mapped number
|
2229
2358
|
#
|
2230
|
-
def map
|
2359
|
+
def map(value, start1, stop1, start2, stop2)
|
2231
2360
|
lerp start2, stop2, norm(value, start1, stop1)
|
2232
2361
|
end
|
2233
2362
|
|
@@ -2244,7 +2373,7 @@ module RubySketch
|
|
2244
2373
|
#
|
2245
2374
|
# @return [Numeric] minimum value
|
2246
2375
|
#
|
2247
|
-
def min
|
2376
|
+
def min(*args)
|
2248
2377
|
args.flatten.min
|
2249
2378
|
end
|
2250
2379
|
|
@@ -2261,7 +2390,7 @@ module RubySketch
|
|
2261
2390
|
#
|
2262
2391
|
# @return [Numeric] maximum value
|
2263
2392
|
#
|
2264
|
-
def max
|
2393
|
+
def max(*args)
|
2265
2394
|
args.flatten.max
|
2266
2395
|
end
|
2267
2396
|
|
@@ -2273,7 +2402,7 @@ module RubySketch
|
|
2273
2402
|
#
|
2274
2403
|
# @return [Numeric] constrained number
|
2275
2404
|
#
|
2276
|
-
def constrain
|
2405
|
+
def constrain(value, min, max)
|
2277
2406
|
value < min ? min : (value > max ? max : value)
|
2278
2407
|
end
|
2279
2408
|
|
@@ -2283,7 +2412,7 @@ module RubySketch
|
|
2283
2412
|
#
|
2284
2413
|
# @return [Numeric] radian
|
2285
2414
|
#
|
2286
|
-
def radians
|
2415
|
+
def radians(degree)
|
2287
2416
|
degree * DEG2RAD__
|
2288
2417
|
end
|
2289
2418
|
|
@@ -2293,7 +2422,7 @@ module RubySketch
|
|
2293
2422
|
#
|
2294
2423
|
# @return [Numeric] degree
|
2295
2424
|
#
|
2296
|
-
def degrees
|
2425
|
+
def degrees(radian)
|
2297
2426
|
radian * RAD2DEG__
|
2298
2427
|
end
|
2299
2428
|
|
@@ -2303,7 +2432,7 @@ module RubySketch
|
|
2303
2432
|
#
|
2304
2433
|
# @return [Numeric] the sine
|
2305
2434
|
#
|
2306
|
-
def sin
|
2435
|
+
def sin(angle)
|
2307
2436
|
Math.sin angle
|
2308
2437
|
end
|
2309
2438
|
|
@@ -2313,7 +2442,7 @@ module RubySketch
|
|
2313
2442
|
#
|
2314
2443
|
# @return [Numeric] the cosine
|
2315
2444
|
#
|
2316
|
-
def cos
|
2445
|
+
def cos(angle)
|
2317
2446
|
Math.cos angle
|
2318
2447
|
end
|
2319
2448
|
|
@@ -2323,7 +2452,7 @@ module RubySketch
|
|
2323
2452
|
#
|
2324
2453
|
# @return [Numeric] the tangent
|
2325
2454
|
#
|
2326
|
-
def tan
|
2455
|
+
def tan(angle)
|
2327
2456
|
Math.tan angle
|
2328
2457
|
end
|
2329
2458
|
|
@@ -2333,7 +2462,7 @@ module RubySketch
|
|
2333
2462
|
#
|
2334
2463
|
# @return [Numeric] the arc sine
|
2335
2464
|
#
|
2336
|
-
def asin
|
2465
|
+
def asin(value)
|
2337
2466
|
Math.asin value
|
2338
2467
|
end
|
2339
2468
|
|
@@ -2343,7 +2472,7 @@ module RubySketch
|
|
2343
2472
|
#
|
2344
2473
|
# @return [Numeric] the arc cosine
|
2345
2474
|
#
|
2346
|
-
def acos
|
2475
|
+
def acos(value)
|
2347
2476
|
Math.acos value
|
2348
2477
|
end
|
2349
2478
|
|
@@ -2353,7 +2482,7 @@ module RubySketch
|
|
2353
2482
|
#
|
2354
2483
|
# @return [Numeric] the arc tangent
|
2355
2484
|
#
|
2356
|
-
def atan
|
2485
|
+
def atan(value)
|
2357
2486
|
Math.atan value
|
2358
2487
|
end
|
2359
2488
|
|
@@ -2364,7 +2493,7 @@ module RubySketch
|
|
2364
2493
|
#
|
2365
2494
|
# @return [Numeric] the angle in radians
|
2366
2495
|
#
|
2367
|
-
def atan2
|
2496
|
+
def atan2(y, x)
|
2368
2497
|
Math.atan2 y, x
|
2369
2498
|
end
|
2370
2499
|
|
@@ -2380,7 +2509,7 @@ module RubySketch
|
|
2380
2509
|
#
|
2381
2510
|
# @return [Numeric] noise value (0.0..1.0)
|
2382
2511
|
#
|
2383
|
-
def noise
|
2512
|
+
def noise(x, y = 0, z = 0)
|
2384
2513
|
Rays.perlin(x, y, z) / 2.0 + 0.5
|
2385
2514
|
end
|
2386
2515
|
|
@@ -2397,7 +2526,7 @@ module RubySketch
|
|
2397
2526
|
#
|
2398
2527
|
# @return [Float] random number
|
2399
2528
|
#
|
2400
|
-
def random
|
2529
|
+
def random(*args)
|
2401
2530
|
return args.first.sample if args.first.kind_of? Array
|
2402
2531
|
high, low = args.reverse
|
2403
2532
|
rand (low || 0).to_f...(high || 1).to_f
|
@@ -2415,16 +2544,16 @@ module RubySketch
|
|
2415
2544
|
#
|
2416
2545
|
# @return [Vector] new vector
|
2417
2546
|
#
|
2418
|
-
def createVector
|
2419
|
-
Vector.new
|
2547
|
+
def createVector(*args)
|
2548
|
+
Vector.new(*args, context: self)
|
2420
2549
|
end
|
2421
2550
|
|
2422
2551
|
# Creates a camera object as a video input device.
|
2423
2552
|
#
|
2424
2553
|
# @return [Capture] camera object
|
2425
2554
|
#
|
2426
|
-
def createCapture
|
2427
|
-
Capture.new
|
2555
|
+
def createCapture(*args)
|
2556
|
+
Capture.new(*args)
|
2428
2557
|
end
|
2429
2558
|
|
2430
2559
|
# Creates a new off-screen graphics context object.
|
@@ -2434,7 +2563,7 @@ module RubySketch
|
|
2434
2563
|
#
|
2435
2564
|
# @return [Graphics] graphics object
|
2436
2565
|
#
|
2437
|
-
def createGraphics
|
2566
|
+
def createGraphics(width, height)
|
2438
2567
|
Graphics.new width, height
|
2439
2568
|
end
|
2440
2569
|
|
@@ -2445,13 +2574,13 @@ module RubySketch
|
|
2445
2574
|
#
|
2446
2575
|
# @return [Image] loaded image object
|
2447
2576
|
#
|
2448
|
-
def loadImage
|
2577
|
+
def loadImage(filename, extension = nil)
|
2449
2578
|
filename = getImage__ filename, extension if filename =~ %r|^https?://|
|
2450
2579
|
Image.new Rays::Image.load filename
|
2451
2580
|
end
|
2452
2581
|
|
2453
2582
|
# @private
|
2454
|
-
private def getImage__
|
2583
|
+
private def getImage__(uri, ext)
|
2455
2584
|
ext ||= File.extname uri
|
2456
2585
|
raise "unsupported image type -- #{ext}" unless ext =~ /^\.?(png)$/i
|
2457
2586
|
|
@@ -2475,7 +2604,7 @@ module RubySketch
|
|
2475
2604
|
end
|
2476
2605
|
|
2477
2606
|
# @private
|
2478
|
-
private def tmpdir__
|
2607
|
+
private def tmpdir__()
|
2479
2608
|
Pathname(Dir.tmpdir) + Digest::SHA1.hexdigest(self.class.name)
|
2480
2609
|
end
|
2481
2610
|
|