processing 0.5.16 → 0.5.17
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ChangeLog.md +8 -0
- data/VERSION +1 -1
- data/lib/processing/context.rb +8 -0
- data/lib/processing/graphics_context.rb +69 -0
- data/lib/processing/image.rb +42 -0
- data/lib/processing/window.rb +14 -5
- data/processing.gemspec +2 -2
- data/test/test_graphics_context.rb +40 -0
- data/test/test_image.rb +30 -2
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d69cca41be46b8a061bcafc55fd36cf71d50616b5b5697ab558dfac1c9c2449c
|
4
|
+
data.tar.gz: 4b3869b1fb410a2da488c03dd58e95fa1f0c42521888869bd70c0c18904831dc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0db54f243695541c85db93d6f28bf3bc42dc76d68e40e3d63cc4e3524110f33372987be661a9fe1e58698d7c3eae40c32b6a76f7660102efbd952591f041db33
|
7
|
+
data.tar.gz: e0719f14ed2fddc28d2dc908339fb633a3dcf645f20a98a52a333541078154aab4c5bcdb1dd36032b1dabbed8f229915ee8b36549085a785446b6aae38e6debc
|
data/ChangeLog.md
CHANGED
@@ -1,6 +1,14 @@
|
|
1
1
|
# processing ChangeLog
|
2
2
|
|
3
3
|
|
4
|
+
## [v0.5.17] - 2023-06-07
|
5
|
+
|
6
|
+
- Add Image#set() and Image#get()
|
7
|
+
- Add color(), red(), green(), blue(), and alpha()
|
8
|
+
- Add lerpColor()
|
9
|
+
- Add focused()
|
10
|
+
|
11
|
+
|
4
12
|
## [v0.5.16] - 2023-06-02
|
5
13
|
|
6
14
|
- Fix failed tests and add tests
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.5.
|
1
|
+
0.5.17
|
data/lib/processing/context.rb
CHANGED
@@ -468,6 +468,14 @@ module Processing
|
|
468
468
|
@window__.height
|
469
469
|
end
|
470
470
|
|
471
|
+
# Returns weather the window is active or not.
|
472
|
+
#
|
473
|
+
# @return [Boolean] active or not
|
474
|
+
#
|
475
|
+
def focused()
|
476
|
+
@window__.active?
|
477
|
+
end
|
478
|
+
|
471
479
|
# Returns the number of frames since the program started.
|
472
480
|
#
|
473
481
|
# @return [Integer] total number of frames
|
@@ -324,6 +324,59 @@ module Processing
|
|
324
324
|
@colorMode__
|
325
325
|
end
|
326
326
|
|
327
|
+
# Creates color value.
|
328
|
+
#
|
329
|
+
# @overload color(gray)
|
330
|
+
# @overload color(gray, alpha)
|
331
|
+
# @overload color(v1, v2, v3)
|
332
|
+
# @overload color(v1, v2, v3, alpha)
|
333
|
+
#
|
334
|
+
# @param gray [Numeric] the value for gray
|
335
|
+
# @param alpha [Numeric] the value for alpha
|
336
|
+
# @param v1 [Numeric] the value for red or hue
|
337
|
+
# @param v2 [Numeric] the value for green or saturation
|
338
|
+
# @param v3 [Numeric] the value for blue or brightness
|
339
|
+
#
|
340
|
+
# @return [Integer] the rgba color value
|
341
|
+
#
|
342
|
+
def color(*args)
|
343
|
+
toRGBA__(*args)
|
344
|
+
.map {|n| (n * 255).to_i.clamp 0, 255}
|
345
|
+
.then {|r, g, b, a| Image.toColor__ r, g, b, a}
|
346
|
+
end
|
347
|
+
|
348
|
+
# Returns the red value of the color.
|
349
|
+
#
|
350
|
+
# @return [Numeric] the red value
|
351
|
+
#
|
352
|
+
def red(color)
|
353
|
+
((color >> 16) & 0xff) / 255.0 * @colorMaxes__[0]
|
354
|
+
end
|
355
|
+
|
356
|
+
# Returns the green value of the color.
|
357
|
+
#
|
358
|
+
# @return [Numeric] the green value
|
359
|
+
#
|
360
|
+
def green(color)
|
361
|
+
((color >> 8) & 0xff) / 255.0 * @colorMaxes__[1]
|
362
|
+
end
|
363
|
+
|
364
|
+
# Returns the blue value of the color.
|
365
|
+
#
|
366
|
+
# @return [Numeric] the blue value
|
367
|
+
#
|
368
|
+
def blue(color)
|
369
|
+
(color & 0xff) / 255.0 * @colorMaxes__[2]
|
370
|
+
end
|
371
|
+
|
372
|
+
# Returns the red value of the color.
|
373
|
+
#
|
374
|
+
# @return [Numeric] the red value
|
375
|
+
#
|
376
|
+
def alpha(color)
|
377
|
+
((color >> 24) & 0xff) / 255.0 * @colorMaxes__[3]
|
378
|
+
end
|
379
|
+
|
327
380
|
# @private
|
328
381
|
private def toRGBA__(*args)
|
329
382
|
a, b, c, d = args
|
@@ -1427,6 +1480,22 @@ module Processing
|
|
1427
1480
|
start + (stop - start) * amount
|
1428
1481
|
end
|
1429
1482
|
|
1483
|
+
# Returns the interpolated color between color1 and color2.
|
1484
|
+
#
|
1485
|
+
# @param color1 [Integer] the 1st color for interpolation
|
1486
|
+
# @param color2 [Integer] the 2nd color for interpolation
|
1487
|
+
# @param amount [Numeric] amount to interpolate
|
1488
|
+
#
|
1489
|
+
# @return [Integer] interporated color
|
1490
|
+
#
|
1491
|
+
def lerpColor(color1, color2, amount)
|
1492
|
+
color(
|
1493
|
+
lerp(red( color1), red( color2), amount),
|
1494
|
+
lerp(green(color1), green(color2), amount),
|
1495
|
+
lerp(blue( color1), blue( color2), amount),
|
1496
|
+
lerp(alpha(color1), alpha(color2), amount))
|
1497
|
+
end
|
1498
|
+
|
1430
1499
|
# Maps a number from range start1..stop1 to range start2..stop2.
|
1431
1500
|
#
|
1432
1501
|
# @param value [Numeric] number to be mapped
|
data/lib/processing/image.rb
CHANGED
@@ -39,6 +39,30 @@ module Processing
|
|
39
39
|
@image.size
|
40
40
|
end
|
41
41
|
|
42
|
+
# Sets the color of the pixel.
|
43
|
+
#
|
44
|
+
# @param x [Integer] x position of the pixel
|
45
|
+
# @param y [Integer] y position of the pixel
|
46
|
+
# @param c [Integer] color value
|
47
|
+
#
|
48
|
+
# @return [nil] nil
|
49
|
+
#
|
50
|
+
def set(x, y, c)
|
51
|
+
@image.bitmap[x, y] = self.class.fromColor__ c
|
52
|
+
nil
|
53
|
+
end
|
54
|
+
|
55
|
+
|
56
|
+
# Returns the color of the pixel.
|
57
|
+
#
|
58
|
+
# @return [Integer] color value (0xAARRGGBB)
|
59
|
+
#
|
60
|
+
def get(x, y)
|
61
|
+
@image.bitmap[x, y]
|
62
|
+
.map {|n| (n * 255).to_i.clamp 0, 255}
|
63
|
+
.then {|r, g, b, a| self.class.toColor__ r, g, b, a}
|
64
|
+
end
|
65
|
+
|
42
66
|
# Applies an image filter.
|
43
67
|
#
|
44
68
|
# overload filter(shader)
|
@@ -135,6 +159,24 @@ module Processing
|
|
135
159
|
end
|
136
160
|
end
|
137
161
|
|
162
|
+
# @private
|
163
|
+
def self.fromColor__(color)
|
164
|
+
[
|
165
|
+
color >> 16 & 0xff,
|
166
|
+
color >> 8 & 0xff,
|
167
|
+
color & 0xff,
|
168
|
+
color >> 24 & 0xff
|
169
|
+
]
|
170
|
+
end
|
171
|
+
|
172
|
+
# @private
|
173
|
+
def self.toColor__(r, g, b, a)
|
174
|
+
(r & 0xff) << 16 |
|
175
|
+
(g & 0xff) << 8 |
|
176
|
+
(b & 0xff) |
|
177
|
+
(a & 0xff) << 24
|
178
|
+
end
|
179
|
+
|
138
180
|
end# Image
|
139
181
|
|
140
182
|
|
data/lib/processing/window.rb
CHANGED
@@ -6,7 +6,7 @@ module Processing
|
|
6
6
|
|
7
7
|
include Xot::Inspectable
|
8
8
|
|
9
|
-
attr_accessor :setup, :update, :draw,
|
9
|
+
attr_accessor :setup, :update, :draw,
|
10
10
|
:key_down, :key_up,
|
11
11
|
:pointer_down, :pointer_up, :pointer_move, :pointer_drag,
|
12
12
|
:move, :resize, :motion,
|
@@ -18,6 +18,7 @@ module Processing
|
|
18
18
|
Processing.instance_variable_set :@window, self
|
19
19
|
|
20
20
|
@events = []
|
21
|
+
@active = false
|
21
22
|
@error = nil
|
22
23
|
@auto_resize = true
|
23
24
|
@canvas = Canvas.new self, width, height
|
@@ -43,6 +44,10 @@ module Processing
|
|
43
44
|
@events.last
|
44
45
|
end
|
45
46
|
|
47
|
+
def active?()
|
48
|
+
@active
|
49
|
+
end
|
50
|
+
|
46
51
|
def add_overlay(view)
|
47
52
|
@overlay_view.add view
|
48
53
|
end
|
@@ -58,14 +63,18 @@ module Processing
|
|
58
63
|
call_block @setup, nil
|
59
64
|
end
|
60
65
|
|
61
|
-
def on_resize(e)
|
62
|
-
on_canvas_resize e
|
63
|
-
end
|
64
|
-
|
65
66
|
def on_change_pixel_density(pixel_density)
|
66
67
|
resize_canvas width, height, window_pixel_density: pixel_density
|
67
68
|
end
|
68
69
|
|
70
|
+
def on_activate(e)
|
71
|
+
@active = true
|
72
|
+
end
|
73
|
+
|
74
|
+
def on_deactivate(e)
|
75
|
+
@active = false
|
76
|
+
end
|
77
|
+
|
69
78
|
def on_draw(e)
|
70
79
|
window_painter.pixel_density.tap do |pd|
|
71
80
|
prev, @prev_pixel_density = @prev_pixel_density, pd
|
data/processing.gemspec
CHANGED
@@ -27,8 +27,8 @@ Gem::Specification.new do |s|
|
|
27
27
|
|
28
28
|
s.add_runtime_dependency 'xot', '~> 0.1.38'
|
29
29
|
s.add_runtime_dependency 'rucy', '~> 0.1.38'
|
30
|
-
s.add_runtime_dependency 'rays', '~> 0.1.
|
31
|
-
s.add_runtime_dependency 'reflexion', '~> 0.1.
|
30
|
+
s.add_runtime_dependency 'rays', '~> 0.1.40'
|
31
|
+
s.add_runtime_dependency 'reflexion', '~> 0.1.43'
|
32
32
|
|
33
33
|
s.add_development_dependency 'rake'
|
34
34
|
s.add_development_dependency 'test-unit'
|
@@ -40,4 +40,44 @@ class TestGraphicsContext < Test::Unit::TestCase
|
|
40
40
|
assert_raise {g.blendMode LEFT}
|
41
41
|
end
|
42
42
|
|
43
|
+
def test_color()
|
44
|
+
g = graphics
|
45
|
+
|
46
|
+
g.colorMode G::RGB, 255
|
47
|
+
c = g.color 10, 20, 30, 40
|
48
|
+
assert_equal 0x280a141e, c
|
49
|
+
assert_equal [10, 20, 30, 40], [g.red(c), g.green(c), g.blue(c), g.alpha(c)]
|
50
|
+
|
51
|
+
g.colorMode G::RGB, 1.0
|
52
|
+
c = g.color 0.1, 0.2, 0.3, 0.4
|
53
|
+
assert_equal 0x6619334c, c
|
54
|
+
assert_in_delta 0.1, g.red(c), 1 / 256.0
|
55
|
+
assert_in_delta 0.2, g.green(c), 1 / 256.0
|
56
|
+
assert_in_delta 0.3, g.blue(c), 1 / 256.0
|
57
|
+
assert_in_delta 0.4, g.alpha(c), 1 / 256.0
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_lerp()
|
61
|
+
g = graphics
|
62
|
+
|
63
|
+
assert_equal 1.0, g.lerp(1.0, 2.0, 0.0)
|
64
|
+
assert_equal 1.5, g.lerp(1.0, 2.0, 0.5)
|
65
|
+
assert_equal 2.0, g.lerp(1.0, 2.0, 1.0)
|
66
|
+
|
67
|
+
assert_equal 0.9, g.lerp(1.0, 2.0, -0.1)
|
68
|
+
assert_equal 2.1, g.lerp(1.0, 2.0, 1.1)
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_lerpColor()
|
72
|
+
g = graphics
|
73
|
+
c = -> red, green, blue {g.color red, green, blue}
|
74
|
+
|
75
|
+
assert_equal c[10, 20, 30], g.lerpColor(c[10, 20, 30], c[50, 60, 70], 0.0)
|
76
|
+
assert_equal c[30, 40, 50], g.lerpColor(c[10, 20, 30], c[50, 60, 70], 0.5)
|
77
|
+
assert_equal c[50, 60, 70], g.lerpColor(c[10, 20, 30], c[50, 60, 70], 1.0)
|
78
|
+
|
79
|
+
assert_equal c[-10, 0, 10], g.lerpColor(c[10, 20, 30], c[50, 60, 70], -0.5)
|
80
|
+
assert_equal c[ 70, 80, 90], g.lerpColor(c[10, 20, 30], c[50, 60, 70], 1.5)
|
81
|
+
end
|
82
|
+
|
43
83
|
end# TestGraphics
|
data/test/test_image.rb
CHANGED
@@ -5,8 +5,36 @@ class TestImage < Test::Unit::TestCase
|
|
5
5
|
|
6
6
|
P = Processing
|
7
7
|
|
8
|
-
def image(w = 10, h = 10)
|
9
|
-
|
8
|
+
def image(w = 10, h = 10, &block)
|
9
|
+
img = Rays::Image.new w, h
|
10
|
+
img.paint &block if block
|
11
|
+
P::Image.new img
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_set_color()
|
15
|
+
g = graphics
|
16
|
+
i = image(2, 2) {fill 0; rect 0, 0, 1, 1}
|
17
|
+
|
18
|
+
assert_equal g.color(0, 0, 0), i.get(0, 0)
|
19
|
+
|
20
|
+
i.set 0, 0, g.color(0, 255, 0)
|
21
|
+
assert_equal g.color(0, 255, 0), i.get(0, 0)
|
22
|
+
|
23
|
+
i.set 0, 0, g.color(0, 0, 255)
|
24
|
+
assert_equal g.color(0, 0, 255), i.get(0, 0)
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_get_color()
|
28
|
+
g = graphics
|
29
|
+
i = image 2, 2 do
|
30
|
+
fill 1, 0, 0; rect 0, 0, 1, 1
|
31
|
+
fill 0, 1, 0; rect 1, 0, 1, 1
|
32
|
+
fill 0, 0, 1; rect 0, 1, 1, 1
|
33
|
+
end
|
34
|
+
|
35
|
+
assert_equal g.color(255, 0, 0), i.get(0, 0)
|
36
|
+
assert_equal g.color(0, 255, 0), i.get(1, 0)
|
37
|
+
assert_equal g.color(0, 0, 255), i.get(0, 1)
|
10
38
|
end
|
11
39
|
|
12
40
|
def test_inspect()
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: processing
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.17
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- xordog
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-06-
|
11
|
+
date: 2023-06-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: xot
|
@@ -44,28 +44,28 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 0.1.
|
47
|
+
version: 0.1.40
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 0.1.
|
54
|
+
version: 0.1.40
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: reflexion
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 0.1.
|
61
|
+
version: 0.1.43
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: 0.1.
|
68
|
+
version: 0.1.43
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rake
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|