ruby-processing 2.6.8 → 2.6.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f86e1e9a4937a12e054537a3a11d87bd4d80ca8d
4
- data.tar.gz: d9504d46543bf9467603fd6f0b3b8b25ddcfc366
3
+ metadata.gz: dcf4cc5227072fee5745bcb0c8bac9b58d337b88
4
+ data.tar.gz: 7ea02eb4fbd00855ec8c0b8dab79e407cfb3dfb6
5
5
  SHA512:
6
- metadata.gz: 7618164b1440aa65fb4d8361392fcfde54588741e1f48fcd983c079bfcd936c6a8d1dd32f3a38e56cf63428022df0733641b4ccf0ce462d6377360d7ccbaf734
7
- data.tar.gz: a00bd119873be49f403a5b606e82f98a84a7e10c52a4ab2a5fd741fbbce4d324616e8d3658a2d71743e09b065c245421f3b45779ee915ccb041d0ef18d72503a
6
+ metadata.gz: e04d303df785d8809cc221da6572e2e3bbf71240d94b7c70ebf77d61714d38024f14c4f7575816f342a320ee9ded4d099caf80c605c8a544f30e69a4de100ade
7
+ data.tar.gz: d9afb5ed70c0116bf80593fd716cf784721052f073acf5102fc3a63af664d31b5a9a89e344d28781e0c2ab5fc329b31f13bf7e01bdb33af6815b88d95d7522e2
@@ -19,7 +19,7 @@ end
19
19
  CODE
20
20
 
21
21
  CLASS_BASIC = <<-CODE
22
- class %s
22
+ class %s < Processing::App
23
23
  def setup
24
24
  size %s, %s
25
25
  end
@@ -31,7 +31,7 @@ end
31
31
  CODE
32
32
 
33
33
  CLASS_MODE = <<-CODE
34
- class %s
34
+ class %s < Processing::App
35
35
  def setup
36
36
  size %s, %s, %s
37
37
  end
@@ -13,7 +13,7 @@ module Processing
13
13
  buf.end_draw
14
14
  buf
15
15
  end
16
-
16
+
17
17
  # A nice method to run a given block for a grid.
18
18
  # Lifted from action_coding/Nodebox.
19
19
  def grid(cols, rows, col_size = 1, row_size = 1)
@@ -23,13 +23,13 @@ module Processing
23
23
  yield x, y
24
24
  end
25
25
  end
26
-
26
+
27
27
  # lerp_color takes three or four arguments, in Java that's two
28
28
  # different methods, one regular and one static, so:
29
29
  def lerp_color(*args)
30
30
  args.length > 3 ? self.class.lerp_color(*args) : super(*args)
31
31
  end
32
-
32
+
33
33
  def color(*args)
34
34
  a = args[0]
35
35
  # convert to signed int
@@ -43,7 +43,7 @@ module Processing
43
43
  end
44
44
  super(*args)
45
45
  end
46
-
46
+
47
47
  # Overrides Processing convenience function thread, which takes a String
48
48
  # arg (for a function) to more rubylike version, takes a block...
49
49
  def thread(&block)
@@ -53,50 +53,67 @@ module Processing
53
53
  fail ArgumentError, 'thread must be called with a block', caller
54
54
  end
55
55
  end
56
-
56
+
57
57
  # Explicitly provides 'processing.org' map instance method, in which
58
58
  # value is mapped from range 1, to range 2 (NB: values are not clamped to
59
59
  # range 1). It may be better to explicitly write your own interpolate
60
60
  # function
61
61
  # @param [float] value input
62
62
  # @param [range] start1, stop1
63
- # @param [range] start1, stop2
63
+ # @param [range] start2, stop2
64
64
  # @return [float] mapped value
65
65
  def map(value, start1, stop1, start2, stop2)
66
66
  start2 + (stop2 - start2) * ((value - start1).to_f / (stop1 - start1))
67
67
  end
68
-
68
+
69
69
  # ruby alternative implementation of map using range parameters
70
70
  # (begin..end) and excluded end (begin...end) produce the same result
71
71
  def map1d(val, r_in, r_out)
72
72
  r_out.begin + (r_out.end - r_out.begin) *
73
73
  ((val - r_in.begin).to_f / (r_in.end - r_in.begin))
74
74
  end
75
-
75
+
76
+ # Explicitly provides 'processing.org' map instance method, where
77
+ # value is mapped from range 1 to range 2 where values are clamped to
78
+ # range 2.
79
+ # @param val input
80
+ # @param [r_in] start1, stop1
81
+ # @param [r_out] start2, stop2
82
+ # @return mapped value
83
+ def constrained_map(val, r_in, r_out)
84
+ unless r_in.include? val
85
+ return r_out.begin if (val < r_in.begin && r_in.begin < r_in.end) ||
86
+ (val > r_in.begin && r_in.begin > r_in.end)
87
+ return r_out.end
88
+ end
89
+ r_out.begin + (r_out.end - r_out.begin) *
90
+ ((val - r_in.begin).to_f / (r_in.end - r_in.begin))
91
+ end
92
+
76
93
  # explicitly provide 'processing.org' norm instance method
77
94
  def norm(value, start, stop)
78
95
  (value - start).to_f / (stop - start)
79
96
  end
80
-
97
+
81
98
  # explicitly provide 'processing.org' lerp instance method
82
99
  def lerp(start, stop, amt)
83
100
  start + (stop - start) * amt
84
101
  end
85
-
102
+
86
103
  # explicitly provide 'processing.org' min instance method
87
104
  # to return a float:- a, b and c need to be floats
88
-
105
+
89
106
  def min(*args)
90
107
  args.min # { |a,b| a <=> b } optional block not reqd
91
108
  end
92
-
109
+
93
110
  # explicitly provide 'processing.org' max instance method
94
111
  # to return a float:- a, b and c need to be floats
95
-
112
+
96
113
  def max(*args)
97
114
  args.max # { |a, b| a <=> b } optional block not reqd
98
115
  end
99
-
116
+
100
117
  # explicitly provide 'processing.org' dist instance method
101
118
  def dist(*args)
102
119
  len = args.length
@@ -107,25 +124,25 @@ module Processing
107
124
  end
108
125
  fail ArgumentError, 'takes 4 or 6 parameters'
109
126
  end
110
-
127
+
111
128
  # explicitly provide 'processing.org' constrain instance method
112
129
  # to return a float:- amt, low and high need to be floats
113
130
  def constrain(amt, low, high)
114
131
  (low..high).clip(amt)
115
132
  end
116
-
133
+
117
134
  # Uses PImage class method under hood
118
135
  def blend_color(c1, c2, mode)
119
136
  Java::ProcessingCore::PImage::blendColor(c1, c2, mode)
120
137
  end
121
-
138
+
122
139
  # There's just so many functions in Processing,
123
140
  # Here's a convenient way to look for them.
124
141
  def find_method(method_name)
125
142
  reg = Regexp.new("#{method_name}", true)
126
143
  methods.sort.select { |meth| reg.match(meth) }
127
144
  end
128
-
145
+
129
146
  # Proxy over a list of Java declared fields that have the same name as
130
147
  # some methods. Add to this list as needed.
131
148
  def proxy_java_fields
@@ -133,88 +150,88 @@ module Processing
133
150
  methods = fields.map { |field| java_class.declared_field(field) }
134
151
  @declared_fields = Hash[fields.zip(methods)]
135
152
  end
136
-
153
+
137
154
  # By default, your sketch path is the folder that your sketch is in.
138
155
  # If you'd like to do something fancy, feel free.
139
156
  def set_sketch_path(spath = nil)
140
157
  field = @declared_fields['sketchPath']
141
158
  field.set_value(java_self, spath || SKETCH_ROOT)
142
159
  end
143
-
160
+
144
161
  # Fix java conversion problems getting the last key
145
162
  # If it's ASCII, return the character, otherwise the integer
146
163
  def key
147
164
  int = @declared_fields['key'].value(java_self)
148
165
  int < 256 ? int.chr : int
149
166
  end
150
-
167
+
151
168
  # Provide a convenient handle for the Java-space version of self.
152
169
  def java_self
153
170
  @java_self ||= to_java(Java::ProcessingCore::PApplet)
154
171
  end
155
-
172
+
156
173
  # Get the sketch path
157
174
  def sketch_path
158
175
  @declared_fields['sketchPath'].value(java_self)
159
176
  end
160
-
177
+
161
178
  # Fields that should be made accessible as under_scored.
162
179
  define_method(:mouse_x) { mouseX }
163
-
180
+
164
181
  define_method(:mouse_y) { mouseY }
165
-
182
+
166
183
  define_method(:pmouse_x) { pmouseX }
167
-
184
+
168
185
  define_method(:pmouse_y) { pmouseY }
169
-
186
+
170
187
  define_method(:frame_count) { frameCount }
171
-
188
+
172
189
  define_method(:mouse_button) { mouseButton }
173
-
190
+
174
191
  define_method(:key_code) { keyCode }
175
-
192
+
176
193
  # Ensure that load_strings returns a real Ruby array
177
194
  def load_strings(file_or_url)
178
195
  loadStrings(file_or_url).to_a
179
196
  end
180
-
197
+
181
198
  # Writes an array of strings to a file, one line per string.
182
199
  # This file is saved to the sketch's data folder
183
200
  def save_strings(filename, strings)
184
201
  saveStrings(filename, [strings].flatten.to_java(:String))
185
202
  end
186
-
203
+
187
204
  # frame_rate needs to support reading and writing
188
205
  def frame_rate(fps = nil)
189
206
  return @declared_fields['frameRate'].value(java_self) unless fps
190
207
  super(fps)
191
208
  end
192
-
209
+
193
210
  # Is the mouse pressed for this frame?
194
211
  def mouse_pressed?
195
212
  @declared_fields['mousePressed'].value(java_self)
196
213
  end
197
-
214
+
198
215
  # Is a key pressed for this frame?
199
216
  def key_pressed?
200
217
  @declared_fields['keyPressed'].value(java_self)
201
- end
202
-
218
+ end
219
+
203
220
  private
204
-
221
+
205
222
  def dist2d(*args)
206
223
  dx = args[0] - args[2]
207
224
  dy = args[1] - args[3]
208
225
  return 0 if dx.abs < EPSILON && dy.abs < EPSILON
209
226
  Math.hypot(dx, dy)
210
227
  end
211
-
228
+
212
229
  def dist3d(*args)
213
230
  dx = args[0] - args[3]
214
231
  dy = args[1] - args[4]
215
232
  dz = args[2] - args[5]
216
233
  return 0 if dx.abs < EPSILON && dy.abs < EPSILON && dz.abs < EPSILON
217
234
  Math.sqrt(dx * dx + dy * dy + dz * dz)
218
- end
235
+ end
219
236
  end
220
237
  end
@@ -1,11 +1,7 @@
1
+ # Extend Range class to include clip (used to implement processing constrain)
1
2
  class Range #:nodoc:
2
3
  def clip(n)
3
- if cover?(n)
4
- n
5
- elsif n < min
6
- min
7
- else
8
- max
9
- end
4
+ return n if cover?(n)
5
+ (n < min) ? min : max
10
6
  end
11
7
  end
@@ -6,15 +6,16 @@ SKETCH_ROOT ||= File.dirname(SKETCH_PATH)
6
6
  require_relative '../../ruby-processing'
7
7
  require_relative '../../ruby-processing/app'
8
8
 
9
+ # More processing module
9
10
  module Processing
10
11
  # For use with "bare" sketches that don't want to define a class or methods
11
- BARE_TEMPLATE = <<-EOS
12
+ BARE_WRAP = <<-EOS
12
13
  class Sketch < Processing::App
13
14
  %s
14
15
  end
15
16
  EOS
16
17
 
17
- NAKED_TEMPLATE = <<-EOS
18
+ NAKED_WRAP = <<-EOS
18
19
  class Sketch < Processing::App
19
20
  def setup
20
21
  size(DEFAULT_WIDTH, DEFAULT_HEIGHT)
@@ -27,15 +28,14 @@ module Processing
27
28
  # This method is the common entry point to run a sketch, bare or complete.
28
29
  def self.load_and_run_sketch
29
30
  source = read_sketch_source
30
- has_sketch = !source.match(/^[^#]*< Processing::App/).nil?
31
- has_methods = !source.match(/^[^#]*(def\s+setup|def\s+draw)/).nil?
32
-
33
- return load File.join(SKETCH_ROOT, SKETCH_PATH) if has_sketch
34
- if has_methods
35
- code = format(BARE_TEMPLATE, source)
36
- else
37
- code = format(NAKED_TEMPLATE, source)
31
+ wrapped = !source.match(/^[^#]*< Processing::App/).nil?
32
+ no_methods = source.match(/^[^#]*(def\s+setup|def\s+draw)/).nil?
33
+ if wrapped
34
+ load SKETCH_PATH
35
+ Processing::App.sketch_class.new unless $app
36
+ return
38
37
  end
38
+ code = no_methods ? format(NAKED_WRAP, source) : format(BARE_WRAP, source)
39
39
  Object.class_eval code, SKETCH_PATH, -1
40
40
  Processing::App.sketch_class.new
41
41
  end
@@ -34,8 +34,10 @@ module Processing
34
34
  def report_errors
35
35
  yield
36
36
  rescue Exception => e
37
- warn "Exception occured while running sketch #{File.basename SKETCH_PATH}..."
38
- puts "Backtrace:\n\t#{e.backtrace.join("\n\t")}"
37
+ wformat = 'Exception occured while running sketch %s...'
38
+ tformat = "Backtrace:\n\t%s"
39
+ warn format(wformat, File.basename(SKETCH_PATH))
40
+ puts format(tformat, e.backtrace.join("\n\t"))
39
41
  end
40
42
 
41
43
  def start_runner
@@ -48,7 +50,7 @@ module Processing
48
50
  end
49
51
 
50
52
  def reload_files_to_watch
51
- @files = ([SKETCH_PATH] + Dir.glob(File.dirname(SKETCH_PATH) + '/*.rb')).uniq
53
+ @files = Dir.glob(File.join(SKETCH_ROOT, '**/*.rb'))
52
54
  end
53
55
  end
54
56
  end
@@ -1,3 +1,3 @@
1
1
  module RubyProcessing
2
- VERSION = '2.6.8'
2
+ VERSION = '2.6.9'
3
3
  end
@@ -9,7 +9,7 @@ WARNING = <<-EOS
9
9
  EOS
10
10
 
11
11
  JRUBYC_VERSION = '1.7.19'
12
- EXAMPLES = '1.4'
12
+ EXAMPLES = '1.5'
13
13
  HOME_DIR = ENV['HOME']
14
14
  MAC_OR_LINUX = /linux|mac|darwin/ =~ RbConfig::CONFIG['host_os']
15
15
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-processing
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.6.8
4
+ version: 2.6.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Ashkenas
@@ -16,7 +16,7 @@ authors:
16
16
  autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
- date: 2015-04-03 00:00:00.000000000 Z
19
+ date: 2015-04-19 00:00:00.000000000 Z
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  requirement: !ruby/object:Gem::Requirement