processing 0.5.14 → 0.5.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 311dd968164719386205299dcfeaf129213ab0837975e995f09568fb9180e0e3
4
- data.tar.gz: 0b566cc36e09ba7e87624144ad5293f699f3662f1b114d24fd5738ed137a079b
3
+ metadata.gz: d69cca41be46b8a061bcafc55fd36cf71d50616b5b5697ab558dfac1c9c2449c
4
+ data.tar.gz: 4b3869b1fb410a2da488c03dd58e95fa1f0c42521888869bd70c0c18904831dc
5
5
  SHA512:
6
- metadata.gz: c4c627e0c5f44104b12dcb83b0e08257d416115797923af02ee156d8c6c72f309bc55fe19cce5db73de41582546550e31e42d0e543bd9a368107cfb7a3870ec4
7
- data.tar.gz: 7c452bb4ad0144326991dddfd12f4e2ff60b5db8095b649630d27a9620b2070eb1b3a63424f03b13d26c45bc2c9a346670b3bd814604fce8f10d67a5612a9e54
6
+ metadata.gz: 0db54f243695541c85db93d6f28bf3bc42dc76d68e40e3d63cc4e3524110f33372987be661a9fe1e58698d7c3eae40c32b6a76f7660102efbd952591f041db33
7
+ data.tar.gz: e0719f14ed2fddc28d2dc908339fb633a3dcf645f20a98a52a333541078154aab4c5bcdb1dd36032b1dabbed8f229915ee8b36549085a785446b6aae38e6debc
data/ChangeLog.md CHANGED
@@ -1,6 +1,28 @@
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
+
12
+ ## [v0.5.16] - 2023-06-02
13
+
14
+ - Fix failed tests and add tests
15
+
16
+
17
+ ## [v0.5.15] - 2023-06-02
18
+
19
+ - Set initial canvas size to same as the window size
20
+ - Use WIDTH and HEIGHT env vars for initial canvas size
21
+ - Shader class can take shadertoy frament shader source
22
+ - createGraphics() can take pixelDensity parameter
23
+ - Pass self to the block call of beginDraw(), and ensure endDraw
24
+
25
+
4
26
  ## [v0.5.14] - 2023-05-29
5
27
 
6
28
  - Add windowMove() and windowResize()
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.14
1
+ 0.5.17
@@ -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
@@ -10,8 +10,8 @@ module Processing
10
10
 
11
11
  # Initialize graphics object.
12
12
  #
13
- def initialize(width, height)
14
- image = Rays::Image.new width, height
13
+ def initialize(width, height, pixelDensity = 1)
14
+ image = Rays::Image.new width, height, Rays::RGBA, pixelDensity
15
15
  init__ image, image.painter
16
16
  end
17
17
 
@@ -22,8 +22,11 @@ module Processing
22
22
  @painter__.__send__ :begin_paint
23
23
  push
24
24
  if block
25
- block.call
26
- endDraw
25
+ begin
26
+ block.call self
27
+ ensure
28
+ endDraw
29
+ end
27
30
  end
28
31
  end
29
32
 
@@ -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
@@ -1648,13 +1717,14 @@ module Processing
1648
1717
 
1649
1718
  # Creates a new off-screen graphics context object.
1650
1719
  #
1651
- # @param width [Numeric] width of graphics image
1652
- # @param height [Numeric] height of graphics image
1720
+ # @param width [Numeric] width of graphics image
1721
+ # @param height [Numeric] height of graphics image
1722
+ # @param pixelDensity [Numeric] pixel density of graphics image
1653
1723
  #
1654
1724
  # @return [Graphics] graphics object
1655
1725
  #
1656
- def createGraphics(width, height)
1657
- Graphics.new width, height
1726
+ def createGraphics(width, height, pixelDensity = 1)
1727
+ Graphics.new width, height, pixelDensity
1658
1728
  end
1659
1729
 
1660
1730
  # Creates a shader object.
@@ -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
 
@@ -13,7 +13,7 @@ module Processing
13
13
  # @param fragSrc [String] fragment shader source
14
14
  #
15
15
  def initialize(vertSrc, fragSrc)
16
- @shader = Rays::Shader.new fragSrc, vertSrc, ENV__
16
+ @shader = Rays::Shader.new modifyFragSource(fragSrc), vertSrc, ENV__
17
17
  end
18
18
 
19
19
  # Sets uniform variables.
@@ -83,74 +83,117 @@ module Processing
83
83
  when Shader
84
84
  arg
85
85
  when :threshold
86
- self.new(nil, <<~END).tap {|sh| sh.set :threshold, (args.shift || 0.5)}
87
- uniform float threshold;
88
- uniform sampler2D texMap;
89
- varying vec4 vertTexCoord;
90
- varying vec4 vertColor;
91
- void main() {
92
- vec4 col = texture2D(texMap, vertTexCoord.xy) * vertColor;
93
- float gray = col.r * 0.3 + col.g * 0.59 + col.b * 0.11;
94
- gl_FragColor = vec4(vec3(gray > threshold ? 1.0 : 0.0), 1.0);
95
- }
96
- END
86
+ self.new(nil, THRESHOLD_SOURCE).tap {|sh| sh.set :threshold, (args.shift || 0.5)}
97
87
  when :gray
98
- self.new nil, <<~END
99
- uniform sampler2D texMap;
100
- varying vec4 vertTexCoord;
101
- varying vec4 vertColor;
102
- void main() {
103
- vec4 col = texture2D(texMap, vertTexCoord.xy);
104
- float gray = col.r * 0.3 + col.g * 0.59 + col.b * 0.11;
105
- gl_FragColor = vec4(vec3(gray), 1.0) * vertColor;
106
- }
107
- END
88
+ self.new nil, GRAY_SOURCE
108
89
  when :invert
109
- self.new nil, <<~END
110
- uniform sampler2D texMap;
111
- varying vec4 vertTexCoord;
112
- varying vec4 vertColor;
113
- void main() {
114
- vec4 col = texture2D(texMap, vertTexCoord.xy);
115
- gl_FragColor = vec4(vec3(1.0 - col.rgb), 1.0) * vertColor;
116
- }
117
- END
90
+ self.new nil, INVERT_SOURCE
118
91
  when :blur
119
- self.new(nil, <<~END).tap {|sh| sh.set :radius, (args.shift || 1).to_f}
120
- #define PI 3.1415926538
121
- uniform float radius;
122
- uniform sampler2D texMap;
123
- uniform vec3 texMin;
124
- uniform vec3 texMax;
125
- uniform vec3 texOffset;
92
+ self.new(nil, BLUR_SOURCE).tap {|sh| sh.set :radius, (args.shift || 1).to_f}
93
+ else
94
+ nil
95
+ end
96
+ end
97
+
98
+ private
99
+
100
+ THRESHOLD_SOURCE = <<~END
101
+ uniform float threshold;
102
+ uniform sampler2D texMap;
103
+ varying vec4 vertTexCoord;
104
+ varying vec4 vertColor;
105
+ void main() {
106
+ vec4 col = texture2D(texMap, vertTexCoord.xy) * vertColor;
107
+ float gray = col.r * 0.3 + col.g * 0.59 + col.b * 0.11;
108
+ gl_FragColor = vec4(vec3(gray > threshold ? 1.0 : 0.0), 1.0);
109
+ }
110
+ END
111
+
112
+ GRAY_SOURCE = <<~END
113
+ uniform sampler2D texMap;
114
+ varying vec4 vertTexCoord;
115
+ varying vec4 vertColor;
116
+ void main() {
117
+ vec4 col = texture2D(texMap, vertTexCoord.xy);
118
+ float gray = col.r * 0.3 + col.g * 0.59 + col.b * 0.11;
119
+ gl_FragColor = vec4(vec3(gray), 1.0) * vertColor;
120
+ }
121
+ END
122
+
123
+ INVERT_SOURCE = <<~END
124
+ uniform sampler2D texMap;
125
+ varying vec4 vertTexCoord;
126
+ varying vec4 vertColor;
127
+ void main() {
128
+ vec4 col = texture2D(texMap, vertTexCoord.xy);
129
+ gl_FragColor = vec4(vec3(1.0 - col.rgb), 1.0) * vertColor;
130
+ }
131
+ END
132
+
133
+ BLUR_SOURCE = <<~END
134
+ #define PI 3.1415926538
135
+ uniform float radius;
136
+ uniform sampler2D texMap;
137
+ uniform vec3 texMin;
138
+ uniform vec3 texMax;
139
+ uniform vec3 texOffset;
140
+ varying vec4 vertTexCoord;
141
+ varying vec4 vertColor;
142
+ float gaussian(vec2 pos, float sigma) {
143
+ float s2 = sigma * sigma;
144
+ return 1.0 / (2.0 * PI * s2) * exp(-(dot(pos, pos) / (2.0 * s2)));
145
+ }
146
+ void main() {
147
+ float sigma = radius * 0.5;
148
+ vec3 color = vec3(0.0);
149
+ float total_weight = 0.0;
150
+ for (float y = -radius; y < radius; y += 1.0)
151
+ for (float x = -radius; x < radius; x += 1.0) {
152
+ vec2 offset = vec2(x, y);
153
+ float weight = gaussian(offset, sigma);
154
+ vec2 texcoord = vertTexCoord.xy + offset * texOffset.xy;
155
+ if (
156
+ texcoord.x < texMin.x || texMax.x < texcoord.x ||
157
+ texcoord.y < texMin.y || texMax.y < texcoord.y
158
+ ) continue;
159
+ color += texture2D(texMap, texcoord).rgb * weight;
160
+ total_weight += weight;
161
+ }
162
+ gl_FragColor = vec4(color / total_weight, 1.0) * vertColor;
163
+ }
164
+ END
165
+
166
+ def modifyFragSource(source)
167
+ return nil unless source
168
+ if hasShadertoyMainImage?(source) && source !~ /void\s+main\s*\(/
169
+ source += <<~END
126
170
  varying vec4 vertTexCoord;
127
- varying vec4 vertColor;
128
- float gaussian(vec2 pos, float sigma) {
129
- float s2 = sigma * sigma;
130
- return 1.0 / (2.0 * PI * s2) * exp(-(dot(pos, pos) / (2.0 * s2)));
131
- }
132
171
  void main() {
133
- float sigma = radius * 0.5;
134
- vec3 color = vec3(0.0);
135
- float total_weight = 0.0;
136
- for (float y = -radius; y < radius; y += 1.0)
137
- for (float x = -radius; x < radius; x += 1.0) {
138
- vec2 offset = vec2(x, y);
139
- float weight = gaussian(offset, sigma);
140
- vec2 texcoord = vertTexCoord.xy + offset * texOffset.xy;
141
- if (
142
- texcoord.x < texMin.x || texMax.x < texcoord.x ||
143
- texcoord.y < texMin.y || texMax.y < texcoord.y
144
- ) continue;
145
- color += texture2D(texMap, texcoord).rgb * weight;
146
- total_weight += weight;
147
- }
148
- gl_FragColor = vec4(color / total_weight, 1.0) * vertColor;
172
+ mainImage(gl_FragColor, vertTexCoord.xy);
149
173
  }
150
174
  END
151
- else
152
- nil
153
175
  end
176
+ {
177
+ iTime: :float,
178
+ iResolution: :vec2,
179
+ iMouse: :vec2
180
+ }.each do |uniformName, type|
181
+ if needsUniformDeclaration type, uniformName, source
182
+ source = <<~END + source
183
+ uniform #{type} #{uniformName};
184
+ END
185
+ end
186
+ end
187
+ source
188
+ end
189
+
190
+ def hasShadertoyMainImage?(source)
191
+ source =~ /void\s+mainImage\s*\(\s*out\s+vec4\s+\w+\s*,\s*in\s+vec2\s+\w+\s*\)/
192
+ end
193
+
194
+ def needsUniformDeclaration(type, uniformName, source)
195
+ source.include?(uniformName.to_s) &&
196
+ source !~ /uniform\s+#{type}\s+#{uniformName}/
154
197
  end
155
198
 
156
199
  end# Shader
@@ -6,7 +6,7 @@ module Processing
6
6
 
7
7
  include Xot::Inspectable
8
8
 
9
- attr_accessor :setup, :update, :draw, :resize,
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,9 +18,10 @@ 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
- @canvas = Canvas.new self
24
+ @canvas = Canvas.new self, width, height
24
25
  @canvas_view = add CanvasView.new name: :canvas
25
26
  @overlay_view = @canvas_view.add Reflex::View.new name: :overlay
26
27
 
@@ -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
@@ -204,11 +213,11 @@ module Processing
204
213
 
205
214
  attr_reader :image, :painter
206
215
 
207
- def initialize(window)
216
+ def initialize(window, width, height)
208
217
  @image = nil
209
218
  @painter = window.painter
210
219
 
211
- resize 1, 1
220
+ resize width, height
212
221
  painter.miter_limit = 10
213
222
  end
214
223
 
data/lib/processing.rb CHANGED
@@ -2,7 +2,9 @@ require 'processing/all'
2
2
 
3
3
 
4
4
  module Processing
5
- WINDOW = Processing::Window.new {start}
5
+ w = (ENV['WIDTH'] || 500).to_i
6
+ h = (ENV['HEIGHT'] || 500).to_i
7
+ WINDOW = Processing::Window.new(w, h) {start}
6
8
  CONTEXT = Processing::Context.new WINDOW
7
9
 
8
10
  refine Object do
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.39'
31
- s.add_runtime_dependency 'reflexion', '~> 0.1.41'
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
- P::Image.new(Rays::Image.new w, h)
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()
data/test/test_shader.rb CHANGED
@@ -41,6 +41,20 @@ class TestShader < Test::Unit::TestCase
41
41
  end
42
42
  end
43
43
 
44
+ def test_shadertoy_shader()
45
+ assert_equal <<~EXPECTED, shader(nil, <<~ACTUAL).instance_variable_get(:@shader).fragment_shader_source
46
+ void mainImage(out vec4 fragColor, in vec2 fragCoord) {
47
+ }
48
+ varying vec4 vertTexCoord;
49
+ void main() {
50
+ mainImage(gl_FragColor, vertTexCoord.xy);
51
+ }
52
+ EXPECTED
53
+ void mainImage(out vec4 fragColor, in vec2 fragCoord) {
54
+ }
55
+ ACTUAL
56
+ end
57
+
44
58
  def test_inspect()
45
59
  assert_match %r|#<Processing::Shader:0x\w{16}>|, shader.inspect
46
60
  end
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.14
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-05-29 00:00:00.000000000 Z
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.39
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.39
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.41
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.41
68
+ version: 0.1.43
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rake
71
71
  requirement: !ruby/object:Gem::Requirement