processing 0.5.30 → 0.5.32

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.
data/test/test_image.rb CHANGED
@@ -37,6 +37,27 @@ class TestImage < Test::Unit::TestCase
37
37
  assert_equal g.color(0, 0, 255), i.get(0, 1)
38
38
  end
39
39
 
40
+ def test_pixels()
41
+ i = image 2, 2
42
+
43
+ i.loadPixels
44
+ assert_equal [0] * 4, i.pixels
45
+ assert_equal [0] * 4, i.getInternal__.pixels
46
+
47
+ i.pixels.replace [0xffff0000, 0xff00ff00, 0xff0000ff, 0xff000000]
48
+ assert_equal [0xffff0000, 0xff00ff00, 0xff0000ff, 0xff000000], i.pixels
49
+ assert_equal [0] * 4, i.getInternal__.pixels
50
+
51
+ i.updatePixels
52
+ assert_nil i.pixels
53
+ assert_equal [0xffff0000, 0xff00ff00, 0xff0000ff, 0xff000000], i.getInternal__.pixels
54
+ assert_nothing_raised {i.updatePixels}
55
+
56
+ i.loadPixels
57
+ i.pixels.replace [0xff000000]
58
+ assert_raise(ArgumentError) {i.updatePixels}
59
+ end
60
+
40
61
  def test_inspect()
41
62
  assert_match %r|#<Processing::Image:0x\w{16}>|, image.inspect
42
63
  end
@@ -0,0 +1,512 @@
1
+ require_relative 'helper'
2
+
3
+
4
+ class TestShape < Test::Unit::TestCase
5
+
6
+ P = Processing
7
+ G = P::GraphicsContext
8
+
9
+ def createShape(kind = nil, *args, g: graphics)
10
+ g.createShape kind, *args
11
+ end
12
+
13
+ def vec(*args)
14
+ P::Vector.new(*args)
15
+ end
16
+
17
+ def test_size()
18
+ assert_equal [0, 0], createShape .then {|s| [s.w, s.h]}
19
+ assert_equal [30, 50], createShape(G::RECT, 10, 20, 30, 50).then {|s| [s.w, s.h]}
20
+ assert_equal [20, 30], createShape(G::LINE, 10, 20, 30, 50).then {|s| [s.w, s.h]}
21
+ end
22
+
23
+ def test_visibility()
24
+ gfx = graphics 100, 100 do |g|
25
+ g.background 0
26
+ end
27
+ assert_equal 1, get_pixels(gfx).uniq.size
28
+
29
+ gfx = graphics 100, 100 do |g|
30
+ s = createShape G::RECT, 10, 20, 30, 40, g: g
31
+ assert_true s.isVisible
32
+ assert_true s.visible?
33
+
34
+ g.background 0
35
+ g.fill 255
36
+ g.noStroke
37
+ g.shape s
38
+ end
39
+ assert_equal 2, get_pixels(gfx).uniq.size
40
+
41
+ gfx = graphics 100, 100 do |g|
42
+ s = createShape G::RECT, 10, 20, 30, 40, g: g
43
+ s.setVisible false
44
+ assert_false s.isVisible
45
+ assert_false s.visible?
46
+
47
+ g.background 0
48
+ g.fill 255
49
+ g.noStroke
50
+ g.shape s
51
+ end
52
+ assert_equal 1, get_pixels(gfx).uniq.size
53
+ end
54
+
55
+ def test_beginShape_points()
56
+ assert_equal_draw_vertices 'strokeWeight 200', <<~END
57
+ s.beginShape POINTS
58
+ s.vertex 200, 300
59
+ s.vertex 500, 600
60
+ s.endShape
61
+ END
62
+ end
63
+
64
+ def test_beginShape_lines()
65
+ assert_equal_draw_vertices 'strokeWeight 200', <<~END
66
+ s.beginShape LINES
67
+ s.vertex 100, 200
68
+ s.vertex 300, 400
69
+ s.vertex 500, 600
70
+ s.vertex 700, 800
71
+ s.endShape
72
+ END
73
+ end
74
+
75
+ def test_beginShape_triangles()
76
+ assert_equal_draw_vertices <<~END
77
+ s.beginShape TRIANGLES
78
+ s.vertex 100, 100
79
+ s.vertex 100, 500
80
+ s.vertex 400, 200
81
+ s.vertex 500, 100
82
+ s.vertex 500, 500
83
+ s.vertex 900, 200
84
+ s.endShape
85
+ END
86
+ end
87
+
88
+ def test_beginShape_triangle_fan()
89
+ assert_equal_draw_vertices <<~END
90
+ s.beginShape TRIANGLE_FAN
91
+ s.vertex 100, 100
92
+ s.vertex 100, 500
93
+ s.vertex 200, 600
94
+ s.vertex 300, 500
95
+ s.vertex 400, 600
96
+ s.vertex 500, 200
97
+ s.vertex 400, 100
98
+ s.endShape
99
+ END
100
+ end
101
+
102
+ def test_beginShape_triangle_strip()
103
+ assert_equal_draw_vertices <<~END
104
+ s.beginShape TRIANGLE_STRIP
105
+ s.vertex 100, 100
106
+ s.vertex 100, 900
107
+ s.vertex 500, 200
108
+ s.vertex 500, 800
109
+ s.vertex 900, 100
110
+ s.vertex 900, 900
111
+ s.endShape
112
+ END
113
+ end
114
+
115
+ def test_beginShape_quads()
116
+ assert_equal_draw_vertices <<~END
117
+ s.beginShape QUADS
118
+ s.vertex 100, 100
119
+ s.vertex 200, 500
120
+ s.vertex 300, 400
121
+ s.vertex 400, 200
122
+ s.vertex 500, 100
123
+ s.vertex 600, 500
124
+ s.vertex 700, 400
125
+ s.vertex 800, 200
126
+ s.endShape
127
+ END
128
+ end
129
+
130
+ def test_beginShape_quad_strip()
131
+ assert_equal_draw_vertices <<~END
132
+ s.beginShape QUAD_STRIP
133
+ s.vertex 100, 100
134
+ s.vertex 100, 500
135
+ s.vertex 500, 200
136
+ s.vertex 500, 400
137
+ s.vertex 900, 100
138
+ s.vertex 900, 500
139
+ s.endShape
140
+ END
141
+ end
142
+
143
+ def test_beginShape_tess()
144
+ assert_equal_draw_vertices <<~END
145
+ s.beginShape TESS
146
+ s.vertex 100, 100
147
+ s.vertex 100, 500
148
+ s.vertex 500, 500
149
+ s.vertex 500, 400
150
+ s.vertex 300, 400
151
+ s.vertex 300, 300
152
+ s.vertex 500, 300
153
+ s.vertex 500, 100
154
+ s.endShape
155
+ END
156
+ end
157
+
158
+ def test_beginShape_polygon()
159
+ assert_equal_draw_vertices <<~END
160
+ s.beginShape
161
+ s.vertex 100, 100
162
+ s.vertex 100, 500
163
+ s.vertex 500, 500
164
+ s.vertex 500, 400
165
+ s.vertex 300, 400
166
+ s.vertex 300, 300
167
+ s.vertex 500, 300
168
+ s.vertex 500, 100
169
+ s.endShape
170
+ END
171
+ end
172
+
173
+ def test_beginShape_twice()
174
+ first, second = <<~FIRST, <<~SECOND
175
+ s.vertex 100, 100
176
+ s.vertex 100, 500
177
+ s.vertex 400, 500
178
+ s.vertex 400, 300
179
+ FIRST
180
+ s.vertex 500, 300
181
+ s.vertex 500, 500
182
+ s.vertex 800, 500
183
+ s.vertex 800, 100
184
+ SECOND
185
+
186
+ assert_equal_draw <<~EXPECTED, <<~ACTUAL
187
+ s = self
188
+ s.beginShape
189
+ #{first}
190
+ #{second}
191
+ s.endShape
192
+ EXPECTED
193
+ s = createShape
194
+ s.beginShape
195
+ #{first}
196
+ s.endShape
197
+ s.beginShape
198
+ #{second}
199
+ s.endShape
200
+ shape s
201
+ ACTUAL
202
+
203
+ assert_equal_draw <<~EXPECTED, <<~ACTUAL
204
+ s = self
205
+ s.beginShape
206
+ #{first}
207
+ #{second}
208
+ s.endShape CLOSE
209
+ EXPECTED
210
+ s = createShape
211
+ s.beginShape
212
+ #{first}
213
+ s.endShape
214
+ s.beginShape
215
+ #{second}
216
+ s.endShape CLOSE
217
+ shape s
218
+ ACTUAL
219
+
220
+ assert_equal_draw <<~EXPECTED, <<~ACTUAL
221
+ s = self
222
+ s.beginShape
223
+ #{first}
224
+ #{second}
225
+ s.endShape
226
+ EXPECTED
227
+ s = createShape
228
+ s.beginShape TRIANGLES
229
+ #{first}
230
+ s.endShape
231
+ s.beginShape
232
+ #{second}
233
+ s.endShape
234
+ shape s
235
+ ACTUAL
236
+ end
237
+
238
+ def test_curveVertex()
239
+ assert_equal_draw_vertices <<~END
240
+ s.beginShape
241
+ s.curveVertex 100, 100
242
+ s.curveVertex 800, 100
243
+ s.curveVertex 800, 800
244
+ s.curveVertex 100, 800
245
+ s.endShape
246
+ END
247
+
248
+ assert_equal_draw_vertices <<~END
249
+ s.beginShape
250
+ s.curveVertex 200, 200
251
+ s.curveVertex 200, 200
252
+ s.curveVertex 800, 200
253
+ s.curveVertex 800, 400
254
+ s.curveVertex 200, 400
255
+ s.curveVertex 200, 800
256
+ s.curveVertex 800, 800
257
+ s.curveVertex 800, 700
258
+ s.curveVertex 800, 700
259
+ s.endShape
260
+ END
261
+ end
262
+
263
+ def test_bezierVertex()
264
+ assert_equal_draw_vertices <<~END
265
+ s.beginShape
266
+ s.vertex 100, 100
267
+ s.bezierVertex 900, 100, 900, 900, 200, 500
268
+ s.endShape
269
+ END
270
+
271
+ assert_equal_draw_vertices <<~END
272
+ s.beginShape
273
+ s.vertex 100, 100
274
+ s.bezierVertex 900, 100, 900, 500, 300, 500
275
+ s.bezierVertex 100, 900, 900, 900, 900, 600
276
+ s.endShape
277
+ END
278
+ end
279
+
280
+ def test_quadraticVertex()
281
+ assert_equal_draw_vertices <<~END
282
+ s.beginShape
283
+ s.vertex 100, 100
284
+ s.quadraticVertex 800, 500, 200, 800
285
+ s.endShape
286
+ END
287
+
288
+ assert_equal_draw_vertices <<~END
289
+ s.beginShape
290
+ s.vertex 100, 100
291
+ s.quadraticVertex 800, 100, 500, 500
292
+ s.quadraticVertex 100, 800, 800, 800
293
+ s.endShape
294
+ END
295
+ end
296
+
297
+ def test_contour()
298
+ assert_equal_draw_vertices <<~END
299
+ s.beginShape
300
+ s.vertex 100, 100
301
+ s.vertex 100, 900
302
+ s.vertex 900, 900
303
+ s.vertex 900, 100
304
+ s.beginContour
305
+ s.vertex 200, 200
306
+ s.vertex 800, 200
307
+ s.vertex 700, 700
308
+ s.vertex 200, 800
309
+ s.endContour
310
+ s.endShape
311
+ END
312
+ end
313
+
314
+ def test_getVertex()
315
+ s = createShape
316
+ s.beginShape
317
+ s.vertex 1, 2
318
+ s.vertex 3, 4
319
+ s.vertex 5, 6
320
+ s.endShape
321
+
322
+ assert_equal vec(1, 2), s.getVertex(0)
323
+ assert_equal vec(3, 4), s.getVertex(1)
324
+ assert_equal vec(5, 6), s.getVertex(-1)
325
+ assert_equal vec(3, 4), s.getVertex(-2)
326
+ end
327
+
328
+ def test_setVertex()
329
+ s = createShape
330
+ s.beginShape
331
+ s.vertex 1, 2
332
+ s.vertex 3, 4
333
+ s.vertex 5, 6
334
+ s.endShape
335
+
336
+ points = -> do
337
+ s.getVertexCount.times.map {|i|
338
+ s.getVertex(i).then {|v| [v.x, v.y]}
339
+ }.flatten
340
+ end
341
+
342
+ s.setVertex(0, vec(7, 8))
343
+ assert_equal [7, 8, 3, 4, 5, 6], points.call
344
+
345
+ s.setVertex(-1, vec(9, 10))
346
+ assert_equal [7, 8, 3, 4, 9, 10], points.call
347
+ end
348
+
349
+ def test_getVertexCount()
350
+ s = createShape
351
+ s.beginShape G::TRIANGLES
352
+ assert_equal 0, s.getVertexCount
353
+
354
+ s.vertex 1, 2
355
+ assert_equal 1, s.getVertexCount
356
+
357
+ s.vertex 3, 4
358
+ assert_equal 2, s.getVertexCount
359
+
360
+ s.vertex 5, 6
361
+ assert_equal 3, s.getVertexCount
362
+
363
+ s.endShape
364
+ assert_equal 3, s.getVertexCount
365
+ end
366
+
367
+ def test_fill()
368
+ assert_equal_draw <<~HEADER, <<~EXPECTED, <<~ACTUAL
369
+ noStroke
370
+ HEADER
371
+ fill 0, 255, 0
372
+ rect 100, 100, 500, 400
373
+ EXPECTED
374
+ s = createShape
375
+ s.beginShape
376
+ s.fill 0, 255, 0
377
+ s.vertex 100, 100
378
+ s.vertex 600, 100
379
+ s.vertex 600, 500
380
+ s.vertex 100, 500
381
+ s.endShape
382
+ shape s
383
+ ACTUAL
384
+ end
385
+
386
+ def test_setFill()
387
+ assert_equal_draw <<~HEADER, <<~EXPECTED, <<~ACTUAL
388
+ noStroke
389
+ HEADER
390
+ fill 0, 255, 0
391
+ rect 100, 100, 500, 400
392
+ EXPECTED
393
+ s = createShape
394
+ s.beginShape
395
+ s.vertex 100, 100
396
+ s.vertex 600, 100
397
+ s.vertex 600, 500
398
+ s.vertex 100, 500
399
+ s.endShape
400
+ s.setFill 0, 255, 0
401
+ shape s
402
+ ACTUAL
403
+
404
+ assert_equal_draw <<~HEADER, <<~EXPECTED, <<~ACTUAL
405
+ noStroke
406
+ HEADER
407
+ fill 0, 255, 0
408
+ ellipse 300, 400, 500, 400
409
+ EXPECTED
410
+ s = createShape ELLIPSE, 300, 400, 500, 400
411
+ s.setFill 0, 255, 0
412
+ shape s
413
+ ACTUAL
414
+ end
415
+
416
+ def test_addChild()
417
+ group = createShape G::GROUP
418
+ assert_nil group.getChild(0)
419
+
420
+ rect = createShape G::RECT, 100, 100, 200, 300
421
+ group.addChild rect
422
+ assert_equal 1, group.getChildCount
423
+ assert_equal rect, group.getChild(0)
424
+ end
425
+
426
+ def test_addChild_to_non_group_shape()
427
+ s = createShape
428
+ assert_equal 0, s.getChildCount
429
+
430
+ assert_nothing_raised {
431
+ s.addChild createShape(G::RECT, 100, 100, 200, 300)
432
+ }
433
+ assert_equal 0, s.getChildCount
434
+ end
435
+
436
+ def test_getChildCount()
437
+ s = createShape G::GROUP
438
+ assert_equal 0, s.getChildCount
439
+
440
+ s.addChild createShape
441
+ assert_equal 1, s.getChildCount
442
+
443
+ s.addChild createShape
444
+ assert_equal 2, s.getChildCount
445
+ end
446
+
447
+ def test_translate()
448
+ assert_equal_draw <<~EXPECTED, <<~ACTUAL
449
+ translate 100, 200
450
+ rect 0, 0, 300, 400
451
+ EXPECTED
452
+ s = createShape RECT, 0, 0, 300, 400
453
+ s.translate 100, 200
454
+ shape s
455
+ ACTUAL
456
+ end
457
+
458
+ def test_rotate()
459
+ assert_equal_draw <<~EXPECTED, <<~ACTUAL
460
+ rotate PI / 10
461
+ rect 100, 200, 300, 400
462
+ EXPECTED
463
+ s = createShape RECT, 100, 200, 300, 400
464
+ s.rotate PI / 10
465
+ shape s
466
+ ACTUAL
467
+ end
468
+
469
+ def test_scale()
470
+ assert_equal_draw <<~EXPECTED, <<~ACTUAL
471
+ scale 0.5, 0.6
472
+ rect 100, 200, 300, 400
473
+ EXPECTED
474
+ s = createShape RECT, 100, 200, 300, 400
475
+ s.scale 0.5, 0.6
476
+ shape s
477
+ ACTUAL
478
+ end
479
+
480
+ def test_sequential_transformation()
481
+ assert_equal_draw <<~EXPECTED, <<~ACTUAL
482
+ translate 100, 200
483
+ rotate PI / 4
484
+ scale 0.5, 0.6
485
+ translate 100, 200
486
+ rotate(-PI / 4)
487
+ scale 2, 3
488
+ rect 0, 0, 300, 400
489
+ EXPECTED
490
+ s = createShape RECT, 0, 0, 300, 400
491
+ s.translate 100, 200
492
+ s.rotate PI / 4
493
+ s.scale 0.5, 0.6
494
+ s.translate 100, 200
495
+ s.rotate(-PI / 4)
496
+ s.scale 2, 3
497
+ shape s
498
+ ACTUAL
499
+ end
500
+
501
+ def assert_equal_draw_vertices(*shared_header, source)
502
+ assert_equal_draw(*shared_header, <<~EXPECTED, <<~ACTUAL, label: test_label)
503
+ s = self
504
+ #{source}
505
+ EXPECTED
506
+ s = createShape
507
+ #{source}
508
+ shape s
509
+ ACTUAL
510
+ end
511
+
512
+ end# TestShape
data/test/test_vector.rb CHANGED
@@ -325,7 +325,7 @@ class TestVector < Test::Unit::TestCase
325
325
  def test_rotate()
326
326
  angle = PI * 2 * 0.1
327
327
  context = Object.new.tap {|o|
328
- def o.toAngle__(a)
328
+ def o.toDegrees__(a)
329
329
  a * 2 * P::GraphicsContext::RAD2DEG__
330
330
  end
331
331
  }
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.30
4
+ version: 0.5.32
5
5
  platform: ruby
6
6
  authors:
7
7
  - xordog
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-11-08 00:00:00.000000000 Z
11
+ date: 2024-01-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: xot
@@ -16,56 +16,56 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.1.40
19
+ version: 0.1.41
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.1.40
26
+ version: 0.1.41
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rucy
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 0.1.41
33
+ version: 0.1.43
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 0.1.41
40
+ version: 0.1.43
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rays
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 0.1.46
47
+ version: 0.1.48
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.46
54
+ version: 0.1.48
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.54
61
+ version: 0.1.56
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.54
68
+ version: 0.1.56
69
69
  description: Creative Coding Framework has API compatible to Processing or p5.js.
70
70
  email: xordog@gmail.com
71
71
  executables: []
@@ -106,20 +106,20 @@ files:
106
106
  - lib/processing/graphics_context.rb
107
107
  - lib/processing/image.rb
108
108
  - lib/processing/shader.rb
109
+ - lib/processing/shape.rb
109
110
  - lib/processing/touch.rb
110
111
  - lib/processing/vector.rb
111
112
  - lib/processing/window.rb
112
113
  - processing.gemspec
113
- - test/draw/helper.rb
114
- - test/draw/p5.rb
115
- - test/draw/test_draw.rb
116
114
  - test/helper.rb
115
+ - test/p5.rb
117
116
  - test/test_capture.rb
118
117
  - test/test_font.rb
119
118
  - test/test_graphics.rb
120
119
  - test/test_graphics_context.rb
121
120
  - test/test_image.rb
122
121
  - test/test_shader.rb
122
+ - test/test_shape.rb
123
123
  - test/test_text_bounds.rb
124
124
  - test/test_touch.rb
125
125
  - test/test_utility.rb
@@ -148,16 +148,15 @@ signing_key:
148
148
  specification_version: 4
149
149
  summary: Processing compatible Creative Coding Framework.
150
150
  test_files:
151
- - test/draw/helper.rb
152
- - test/draw/p5.rb
153
- - test/draw/test_draw.rb
154
151
  - test/helper.rb
152
+ - test/p5.rb
155
153
  - test/test_capture.rb
156
154
  - test/test_font.rb
157
155
  - test/test_graphics.rb
158
156
  - test/test_graphics_context.rb
159
157
  - test/test_image.rb
160
158
  - test/test_shader.rb
159
+ - test/test_shape.rb
161
160
  - test/test_text_bounds.rb
162
161
  - test/test_touch.rb
163
162
  - test/test_utility.rb
data/test/draw/helper.rb DELETED
@@ -1,31 +0,0 @@
1
- require 'digest/md5'
2
- require 'fileutils'
3
-
4
- require_relative '../helper'
5
- require_relative 'p5'
6
-
7
-
8
- def md5(s)
9
- Digest::MD5.hexdigest s
10
- end
11
-
12
- def mkdir(dir: nil, filename: nil)
13
- path = dir || File.dirname(filename)
14
- FileUtils.mkdir_p path unless File.exist? path
15
- end
16
-
17
- def assert_draw(width = 100, height = 100, draw_src, threshold: 1.0)
18
- path = File.join __dir__, "p5rb", "#{md5(draw_src)}.png"
19
- mkdir filename: path
20
- density = draw_p5rb width, height, draw_src, path, headless: false
21
- gfx = graphics(width, height, density).tap do |g|
22
- g.beginDraw do
23
- g.background 0
24
- g.fill 255, 0, 0
25
- g.noStroke
26
- g.instance_eval draw_src
27
- end
28
- end
29
- gfx.save path.sub(/\.png$/, '.actual.png')
30
- assert_equal_pixels gfx.loadImage(path), gfx, threshold: threshold
31
- end