processing 1.1.3 → 1.1.5

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: 8f9bd898aff5ff7b56bfd6ffcc238202a3488cfbc083987dce630b08a88c671b
4
- data.tar.gz: e0f8c2c453e34320e04a45bf13b06f4f45f0b7c79b30007614fbaaa0c9b7c1e7
3
+ metadata.gz: c8f47bfbe64ef981036e63d3764e68d0136d9279f155eda380484c5e82b09c0b
4
+ data.tar.gz: 8d73f1f9a94c04ebe2050007ab2a07c9ca5febae8611373af831b9b1ab30973b
5
5
  SHA512:
6
- metadata.gz: 3195ec55d3d870a3905d17430b86d2cf5772566b9fcd57e6c02242d1e14a01d6562b8b22b2163f19db8eeb285f3d9eaed337f179fc28c8533cf2f671a8bf7f11
7
- data.tar.gz: 596d56d8b9cb9af92df912ef2733195bbc3df0b4ecdac9123e3370610202e2ac90699dfd0a84bf2f396732d278cc620b25e55c450d374b4393837650dfac06ae
6
+ metadata.gz: f38a551e8d521bd34f3c6fd41c554f3fc95cf33fee013e40b4142580cf679078d248d2fe00c5ee84d19a2f24b8108a9bfe6541678e103a59cd5bb845d8fd8006
7
+ data.tar.gz: 9b7fe7c09c8daee0e9d7e0fb44a1e9fe66a95145f20003614492480c2325a650ec860f263062e9b9f4b7defa92a89cd98a59eca446a034f912e48a5d2a95e960
data/ChangeLog.md CHANGED
@@ -1,6 +1,18 @@
1
1
  # processing ChangeLog
2
2
 
3
3
 
4
+ ## [v1.1.5] - 2025-01-30
5
+
6
+ - Do not define snake_case methods by default
7
+
8
+
9
+ ## [v1.1.4] - 2025-01-27
10
+
11
+ - Event blocks can be defined as methods with 'def'
12
+ - Alias snake case methods
13
+ - ellipse() can take 3 params
14
+
15
+
4
16
  ## [v1.1.3] - 2025-01-23
5
17
 
6
18
  - Update dependencies
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.3
1
+ 1.1.5
@@ -9,6 +9,66 @@ require 'net/http'
9
9
  require 'xot/inspectable'
10
10
  require 'reflex'
11
11
 
12
+
13
+ module Processing
14
+
15
+ # @private
16
+ EVENT_NAMES__ = %i[
17
+ setup draw
18
+ keyPressed keyReleased keyTyped
19
+ mousePressed mouseReleased mouseMoved mouseDragged
20
+ mouseClicked doubleClicked mouseWheel
21
+ touchStarted touchEnded touchMoved
22
+ windowMoved windowResized motion
23
+ ]
24
+
25
+ # @private
26
+ def self.setup__(namespace)
27
+ w = (ENV['WIDTH'] || 500).to_i
28
+ h = (ENV['HEIGHT'] || 500).to_i
29
+
30
+ window = Processing::Window.new(w, h) {start}
31
+ context = namespace::Context.new window
32
+
33
+ return window, context
34
+ end
35
+
36
+ # @private
37
+ def self.funcs__(context)
38
+ (context.methods - Object.instance_methods)
39
+ .reject {_1 =~ /__$/} # methods for internal use
40
+ end
41
+
42
+ # @private
43
+ def self.events__(context)
44
+ to_snake_case__(EVENT_NAMES__).flatten.uniq.select {context.respond_to? _1}
45
+ end
46
+
47
+ # @private
48
+ def self.alias_snake_case_methods__(klass, recursive = 1)
49
+ to_snake_case__(klass.instance_methods false)
50
+ .reject {|camel, snake| camel =~ /__$/}
51
+ .reject {|camel, snake| klass.method_defined? snake}
52
+ .each {|camel, snake| klass.alias_method snake, camel}
53
+ if recursive > 0
54
+ klass.constants.map {klass.const_get _1}
55
+ .flatten
56
+ .select {_1.class == Module || _1.class == Class}
57
+ .each {|inner_class| alias_snake_case_methods__ inner_class, recursive - 1}
58
+ end
59
+ end
60
+
61
+ # @private
62
+ def self.to_snake_case__(camel_case_names)
63
+ camel_case_names.map do |camel|
64
+ snake = camel.to_s.gsub(/([a-z])([A-Z])/) {"#{$1}_#{$2.downcase}"}
65
+ [camel, snake].map(&:to_sym)
66
+ end
67
+ end
68
+
69
+ end# Processing
70
+
71
+
12
72
  require 'processing/extension'
13
73
  require 'processing/app'
14
74
  require 'processing/window'
@@ -1540,6 +1540,9 @@ module Processing
1540
1540
  #
1541
1541
  # The parameters a, b, c, and d are determined by ellipseMode().
1542
1542
  #
1543
+ # @overload ellipse(a, b, c)
1544
+ # @overload ellipse(a, b, c, d)
1545
+ #
1543
1546
  # @param a [Numeric] horizontal position of the shape, by default
1544
1547
  # @param b [Numeric] vertical position of the shape, by default
1545
1548
  # @param c [Numeric] width of the shape, by default
@@ -1550,9 +1553,9 @@ module Processing
1550
1553
  # @see https://processing.org/reference/ellipse_.html
1551
1554
  # @see https://p5js.org/reference/p5/ellipse/
1552
1555
  #
1553
- def ellipse(a, b, c, d)
1556
+ def ellipse(a, b, c, d = nil)
1554
1557
  assertDrawing__
1555
- x, y, w, h = toXYWH__ @ellipseMode__, a, b, c, d
1558
+ x, y, w, h = toXYWH__ @ellipseMode__, a, b, c, (d || c)
1556
1559
  @painter__.ellipse x, y, w, h
1557
1560
  nil
1558
1561
  end
data/lib/processing.rb CHANGED
@@ -2,23 +2,37 @@ require 'processing/all'
2
2
 
3
3
 
4
4
  module Processing
5
- w = (ENV['WIDTH'] || 500).to_i
6
- h = (ENV['HEIGHT'] || 500).to_i
7
- WINDOW__ = Processing::Window.new(w, h) {start}
8
- CONTEXT__ = Processing::Context.new WINDOW__
5
+ WINDOW__, CONTEXT__ = Processing.setup__ Processing
9
6
 
10
7
  refine Object do
11
- (CONTEXT__.methods - Object.instance_methods)
12
- .reject {_1 =~ /__$/} # methods for internal use
13
- .each do |method|
14
- define_method method do |*args, **kwargs, &block|
15
- CONTEXT__.__send__ method, *args, **kwargs, &block
16
- end
8
+ context = CONTEXT__
9
+ Processing.funcs__(context).each do |func|
10
+ define_method func do |*args, **kwargs, &block|
11
+ context.__send__ func, *args, **kwargs, &block
17
12
  end
13
+ end
18
14
  end
19
15
  end# Processing
20
16
 
21
17
 
18
+ def Processing(snake_case: false)
19
+ return Processing unless snake_case
20
+
21
+ $processing_refinements_with_snake_case ||= Module.new do
22
+ Processing.alias_snake_case_methods__ Processing
23
+
24
+ refine Object do
25
+ context = Processing::CONTEXT__
26
+ Processing.funcs__(context).each do |func|
27
+ define_method func do |*args, **kwargs, &block|
28
+ context.__send__ func, *args, **kwargs, &block
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+
35
+
22
36
  begin
23
37
  w, c = Processing::WINDOW__, Processing::CONTEXT__
24
38
 
@@ -28,6 +42,11 @@ begin
28
42
 
29
43
  w.__send__ :begin_draw
30
44
  at_exit do
45
+ Processing.events__(c).each do |event|
46
+ m = begin method event; rescue NameError; nil end
47
+ c.__send__(event) {__send__ event} if m
48
+ end
49
+
31
50
  w.__send__ :end_draw
32
51
  Processing::App.new {w.show}.start if c.hasUserBlocks__ && !$!
33
52
  end
@@ -198,9 +198,13 @@ class TestGraphicsContext < Test::Unit::TestCase
198
198
 
199
199
  def test_ellipse_with_ellipseMode()
200
200
  assert_p5_draw 'ellipseMode CORNER; ellipse 100, 200, 300, 400'
201
+ assert_p5_draw 'ellipseMode CORNER; ellipse 100, 200, 300'
201
202
  assert_p5_draw 'ellipseMode CORNERS; ellipse 100, 200, 300, 500'
203
+ assert_p5_draw 'ellipseMode CORNERS; ellipse 100, 200, 300'
202
204
  assert_p5_draw 'ellipseMode CENTER; ellipse 400, 500, 300, 400'
205
+ assert_p5_draw 'ellipseMode CENTER; ellipse 400, 500, 300'
203
206
  assert_p5_draw 'ellipseMode RADIUS; ellipse 400, 500, 300, 400'
207
+ assert_p5_draw 'ellipseMode RADIUS; ellipse 400, 500, 300'
204
208
  end
205
209
 
206
210
  def test_circle()
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: 1.1.3
4
+ version: 1.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - xordog
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-01-22 00:00:00.000000000 Z
11
+ date: 2025-01-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rexml