ruby-processing 2.6.2 → 2.6.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (129) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rpextras.jar +0 -0
  3. data/lib/ruby-processing.rb +5 -8
  4. data/lib/ruby-processing/app.rb +26 -27
  5. data/lib/ruby-processing/config.rb +0 -2
  6. data/lib/ruby-processing/exporters/application_exporter.rb +1 -1
  7. data/lib/ruby-processing/exporters/base_exporter.rb +1 -1
  8. data/lib/ruby-processing/exporters/creator.rb +11 -11
  9. data/lib/ruby-processing/helper_methods.rb +33 -31
  10. data/lib/ruby-processing/helpers/numeric.rb +1 -1
  11. data/lib/ruby-processing/helpers/range.rb +11 -0
  12. data/lib/ruby-processing/library_loader.rb +11 -16
  13. data/lib/ruby-processing/runner.rb +22 -24
  14. data/lib/ruby-processing/runners/watch.rb +1 -1
  15. data/lib/ruby-processing/version.rb +1 -1
  16. data/library/boids/boids.rb +39 -70
  17. data/library/control_panel/control_panel.rb +3 -3
  18. data/samples/contributed/circle_collision.rb +3 -3
  19. data/samples/contributed/fern.rb +7 -10
  20. data/samples/contributed/fibonacci_sphere.rb +2 -2
  21. data/samples/contributed/full_screen.rb +23 -22
  22. data/samples/contributed/grapher.rb +3 -3
  23. data/samples/contributed/gravity.rb +1 -1
  24. data/samples/contributed/mandelbrot.rb +10 -13
  25. data/samples/external_library/java_processing/box2d_processing/bumpy_surface_noise.rb +1 -1
  26. data/samples/external_library/java_processing/box2d_processing/library/custom_shape/custom_shape.rb +2 -2
  27. data/samples/external_library/java_processing/box2d_processing/library/particle_system/particle_system.rb +1 -1
  28. data/samples/external_library/java_processing/box2d_processing/library/surface/surface.rb +2 -2
  29. data/samples/external_library/java_processing/box2d_processing/liquidy.rb +1 -1
  30. data/samples/external_library/java_processing/fisica/bubbles.rb +2 -2
  31. data/samples/external_library/java_processing/fisica/joints.rb +4 -4
  32. data/samples/external_library/java_processing/generative_design/node_spring_attractor.rb +2 -2
  33. data/samples/external_library/java_processing/geomerative/hello_world_rotate_firstletter.rb +7 -7
  34. data/samples/external_library/java_processing/hemesh/twin_iso.rb +3 -3
  35. data/samples/external_library/java_processing/pbox2d/bumpy_surface_noise.rb +1 -1
  36. data/samples/external_library/java_processing/pbox2d/library/custom_shape/custom_shape.rb +2 -2
  37. data/samples/external_library/java_processing/pbox2d/library/particle_system/particle_system.rb +1 -1
  38. data/samples/external_library/java_processing/pbox2d/library/surface/surface.rb +2 -2
  39. data/samples/external_library/java_processing/pbox2d/liquidy.rb +1 -1
  40. data/samples/external_library/java_processing/peasy_cam/library/hilbert/hilbert.rb +4 -4
  41. data/samples/external_library/ruby_gem/draw_test.rb +2 -2
  42. data/samples/external_library/ruby_gem/game_of_life.rb +3 -3
  43. data/samples/processing_app/basics/arrays/array_objects.rb +2 -2
  44. data/samples/processing_app/basics/color/hue.rb +1 -1
  45. data/samples/processing_app/basics/control/conditionals1.rb +5 -24
  46. data/samples/processing_app/basics/control/conditionals2.rb +1 -1
  47. data/samples/processing_app/basics/form/bezier_ellipse.rb +1 -1
  48. data/samples/processing_app/basics/form/brick_tower.rb +4 -8
  49. data/samples/processing_app/basics/form/regular_polygon.rb +1 -1
  50. data/samples/processing_app/basics/form/star.rb +1 -1
  51. data/samples/processing_app/basics/form/triangle_strip.rb +1 -1
  52. data/samples/processing_app/basics/input/storing_input.rb +1 -1
  53. data/samples/processing_app/basics/lights/spot.rb +1 -1
  54. data/samples/processing_app/basics/math/additive_wave.rb +2 -2
  55. data/samples/processing_app/basics/math/double_random.rb +2 -2
  56. data/samples/processing_app/basics/math/noise_wave.rb +1 -1
  57. data/samples/processing_app/basics/math/random.rb +1 -1
  58. data/samples/processing_app/basics/objects/module.rb +1 -1
  59. data/samples/processing_app/basics/objects/struct.rb +1 -1
  60. data/samples/processing_app/basics/structure/loop.rb +19 -14
  61. data/samples/processing_app/basics/structure/recursion2.rb +2 -2
  62. data/samples/processing_app/basics/textures/texture3.rb +13 -33
  63. data/samples/processing_app/basics/transform/birds.rb +5 -5
  64. data/samples/processing_app/basics/transform/cubes_in_cube.rb +3 -3
  65. data/samples/processing_app/basics/transform/rotate.rb +1 -1
  66. data/samples/processing_app/basics/typography/kinetic_type.rb +1 -1
  67. data/samples/processing_app/demos/graphics/bezier_patch.rb +34 -34
  68. data/samples/processing_app/demos/graphics/trefoil.rb +1 -1
  69. data/samples/processing_app/demos/graphics/wiggling.rb +5 -5
  70. data/samples/processing_app/demos/performance/esfera.rb +4 -4
  71. data/samples/processing_app/demos/performance/text_rendering.rb +1 -1
  72. data/samples/processing_app/library/dxf/simple_export.rb +3 -3
  73. data/samples/processing_app/library/pdf/complex_3D.rb +11 -11
  74. data/samples/processing_app/library/vecmath/vec2d/bouncing_ball.rb +1 -1
  75. data/samples/processing_app/library/vecmath/vec2d/circle_collision.rb +3 -3
  76. data/samples/processing_app/library/vecmath/vec2d/library/flock/flock.rb +5 -5
  77. data/samples/processing_app/library/vecmath/vec2d/library/particle/{particle_system.rb → particle.rb} +28 -21
  78. data/samples/processing_app/library/vecmath/vec2d/morph.rb +3 -3
  79. data/samples/processing_app/library/vecmath/vec2d/particle_system_pshape.rb +3 -3
  80. data/samples/processing_app/library/vecmath/vec2d/reflection1.rb +2 -2
  81. data/samples/processing_app/library/vecmath/vec2d/seeking_neural.rb +3 -2
  82. data/samples/processing_app/library/vecmath/vec2d/simple_particle_system.rb +1 -1
  83. data/samples/processing_app/library/vecmath/vec3d/frame_of_reference.rb +4 -4
  84. data/samples/processing_app/topics/advanced_data/library/word/word.rb +1 -1
  85. data/samples/processing_app/topics/advanced_data/load_save_XML.rb +1 -1
  86. data/samples/processing_app/topics/advanced_data/load_save_json.rb +1 -1
  87. data/samples/processing_app/topics/advanced_data/load_save_struct_yaml.rb +1 -1
  88. data/samples/processing_app/topics/advanced_data/load_save_yaml.rb +1 -1
  89. data/samples/processing_app/topics/advanced_data/threads_two.rb +1 -2
  90. data/samples/processing_app/topics/cellular_automata/game_of_life.rb +3 -3
  91. data/samples/processing_app/topics/cellular_automata/library/ca/ca.rb +2 -2
  92. data/samples/processing_app/topics/cellular_automata/library/cell/cell.rb +4 -4
  93. data/samples/processing_app/topics/cellular_automata/library/simple_cell/simple_cell.rb +1 -1
  94. data/samples/processing_app/topics/cellular_automata/spore1.rb +1 -1
  95. data/samples/processing_app/topics/cellular_automata/spore2.rb +1 -1
  96. data/samples/processing_app/topics/create_shapes/group_pshape.rb +2 -2
  97. data/samples/processing_app/topics/create_shapes/library/particle/particle_system.rb +3 -3
  98. data/samples/processing_app/topics/create_shapes/library/polygon/polygon.rb +2 -2
  99. data/samples/processing_app/topics/create_shapes/library/star/star.rb +3 -3
  100. data/samples/processing_app/topics/create_shapes/particle_system_pshape.rb +1 -1
  101. data/samples/processing_app/topics/create_shapes/path_pshape.rb +1 -1
  102. data/samples/processing_app/topics/drawing/scribble_plotter.rb +2 -2
  103. data/samples/processing_app/topics/gui/button.rb +16 -16
  104. data/samples/processing_app/topics/gui/rollover.rb +13 -13
  105. data/samples/processing_app/topics/image_processing/blur.rb +2 -2
  106. data/samples/processing_app/topics/image_processing/edge_detection.rb +2 -2
  107. data/samples/processing_app/topics/lsystems/cstest.rb +1 -1
  108. data/samples/processing_app/topics/lsystems/library/stochastic_grammar/stochastic_grammar.rb +1 -1
  109. data/samples/processing_app/topics/motion/bouncy_bubbles.rb +1 -1
  110. data/samples/processing_app/topics/motion/brownian.rb +2 -2
  111. data/samples/processing_app/topics/motion/circle_collision.rb +1 -1
  112. data/samples/processing_app/topics/motion/cubes_in_cube.rb +1 -1
  113. data/samples/processing_app/topics/motion/library/cube/cube.rb +2 -2
  114. data/samples/processing_app/topics/motion/morph.rb +11 -11
  115. data/samples/processing_app/topics/motion/moving_on_curves.rb +4 -4
  116. data/samples/processing_app/topics/motion/puff.rb +4 -4
  117. data/samples/processing_app/topics/motion/reflection1.rb +3 -3
  118. data/samples/processing_app/topics/motion/reflection2.rb +1 -1
  119. data/samples/processing_app/topics/shaders/bw_shader.rb +1 -1
  120. data/samples/processing_app/topics/shaders/glsl_heightmap_noise.rb +2 -2
  121. data/samples/processing_app/topics/simulate/flocking.rb +6 -6
  122. data/samples/processing_app/topics/simulate/library/flock/flock.rb +33 -41
  123. data/samples/processing_app/topics/simulate/multiple_particle_systems.rb +34 -60
  124. data/samples/processing_app/topics/simulate/simple_particle_system.rb +20 -32
  125. data/samples/processing_app/topics/simulate/smoke_particle_system.rb +45 -57
  126. data/samples/processing_app/topics/simulate/springs.rb +40 -44
  127. metadata +4 -5
  128. data/samples/processing_app/library/vecmath/vec2d/multiple_particle_systems.rb +0 -141
  129. data/samples/processing_app/library/vecmath/vec2d/smoke_particle_system.rb +0 -133
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3c47bf5ca5b3ccfac13e28bc08b675ca3ebed4a4
4
- data.tar.gz: 9f852f28cebf20c5f4f040da1f18b59c46520e49
3
+ metadata.gz: 591fe4a424a740865ae79dbf1060221b692ea81a
4
+ data.tar.gz: 5adb639c8832800b21f0877b33ddd366bfe73f44
5
5
  SHA512:
6
- metadata.gz: 06009cf60df0dfd4d03655e8672d8dd6fcce75cc66892bc5ed7a5941b6ad81f3b36449bee4930b54ac2ef474e2834bc997436a354615a4dc71d5dfe7ab125523
7
- data.tar.gz: e637f0ded0113ed8b710cf1b9107b7e17c4cee235b0caab5968d78eb1449710dab2639be81084790c30934ac6d4164a84f44e549667859bd39b61a8d6c0adebd
6
+ metadata.gz: ed7651d8224f586ba6fc194cee99bdbef01248485cbabc3b92cb31514e746d1fa74a65d72fb8b8c8f189df56484728b2afa1984a5711359bd29761e9acadd688
7
+ data.tar.gz: 050764df809b66e1b7434368d7135309d2e61d6d842c6f976dacac90be50affd027d10031c634903d1057e77fe7593d7cf54739a00c4985838d0d9211230d101
Binary file
@@ -1,10 +1,9 @@
1
1
  # Ruby-Processing is for Code Art.
2
2
  # Send suggestions, ideas, and hate-mail to jashkenas [at] gmail.com
3
3
  # Also, send samples and libraries.
4
-
5
4
  unless defined? RP5_ROOT
6
5
  $LOAD_PATH << File.expand_path(File.dirname(__FILE__))
7
- RP5_ROOT = File.expand_path(File.dirname(__FILE__) + "/../")
6
+ RP5_ROOT = File.expand_path(File.dirname(__FILE__) + '/../')
8
7
  end
9
8
 
10
9
  SKETCH_ROOT ||= Dir.pwd
@@ -12,21 +11,19 @@ SKETCH_ROOT ||= Dir.pwd
12
11
  require 'ruby-processing/version'
13
12
  require 'ruby-processing/helpers/string'
14
13
  require 'ruby-processing/helpers/numeric'
14
+ require 'ruby-processing/helpers/range'
15
15
 
16
16
  # The top-level namespace, a home for all Ruby-Processing classes.
17
17
  module Processing
18
-
19
18
  def self.exported?
20
19
  @exported ||= ENV['EXPORTED'].eql?('true')
21
20
  end
22
21
 
23
22
  # Autoload a number of path/constants that we may end up using.
24
- # mri ruby does not understand ** require 'java' ** and we may otherwise call it
25
- # from mri ruby without lazy path loading of autoload
23
+ # mri ruby does not understand ** require 'java' ** and we may otherwise call
24
+ # it from mri ruby without lazy path loading of autoload
26
25
  # NB: autoload is slated for possible removal by ruby-2.2
27
-
28
26
  autoload :App, 'ruby-processing/app'
29
27
  autoload :Runner, 'ruby-processing/runner'
30
28
  autoload :Watcher, 'ruby-processing/runners/watch'
31
-
32
- end
29
+ end
@@ -7,7 +7,7 @@ require_relative '../ruby-processing/helper_methods'
7
7
  require_relative '../ruby-processing/library_loader'
8
8
  require_relative '../ruby-processing/config'
9
9
 
10
- Dir["#{Processing::RP_CONFIG["PROCESSING_ROOT"]}/core/library/\*.jar"].each { |jar| require jar }
10
+ Dir["#{Processing::RP_CONFIG['PROCESSING_ROOT']}/core/library/\*.jar"].each { |jar| require jar }
11
11
 
12
12
  # Include some core processing classes that we'd like to use:
13
13
  %w(PApplet PConstants PFont PImage PShape PShapeOBJ PShapeSVG PStyle
@@ -29,7 +29,7 @@ module Processing
29
29
  include HelperMethods
30
30
 
31
31
  # Alias some methods for familiarity for Shoes coders.
32
- #attr_accessor :frame, :title
32
+ # attr_accessor :frame, :title
33
33
  alias_method :oval, :ellipse
34
34
  alias_method :stroke_width, :stroke_weight
35
35
  alias_method :rgb, :color
@@ -57,11 +57,13 @@ module Processing
57
57
  end
58
58
 
59
59
  # Handy getters and setters on the class go here:
60
- def self.sketch_class; @sketch_class; end
61
- @@full_screen = false
62
- def self.full_screen; @@full_screen = true; end
63
- def full_screen?; @@full_screen; end
64
-
60
+ class << self
61
+ attr_accessor :sketch_class
62
+ end
63
+
64
+ def sketch_class
65
+ self.class.sketch_class
66
+ end
65
67
 
66
68
  # Keep track of what inherits from the Processing::App, because we're going
67
69
  # to want to instantiate one.
@@ -75,7 +77,7 @@ module Processing
75
77
  def load_libraries(*args)
76
78
  @@library_loader.load_library(*args)
77
79
  end
78
- alias :load_library :load_libraries
80
+ alias_method :load_library, :load_libraries
79
81
 
80
82
  def library_loaded?(library_name)
81
83
  @@library_loader.library_loaded?(library_name)
@@ -101,19 +103,19 @@ module Processing
101
103
  # argument in setup. Sensible options to pass are x and y to locate sketch
102
104
  # on the screen, or full_screen: true (prefer new hash syntax)
103
105
 
104
- def initialize(options={})
106
+ def initialize(options = {})
105
107
  super()
106
108
  post_initialize(options)
107
109
  $app = self
108
110
  proxy_java_fields
109
- set_sketch_path #unless Processing.online?
111
+ set_sketch_path # unless Processing.online?
110
112
  mix_proxy_into_inner_classes
111
- #@started = false
113
+ # @started = false
112
114
 
113
115
  java.lang.Thread.default_uncaught_exception_handler = proc do |_thread_, exception|
114
116
  puts(exception.class.to_s)
115
117
  puts(exception.message)
116
- puts(exception.backtrace.collect { |trace| "\t" + trace })
118
+ puts(exception.backtrace.map { |trace| '\t' + trace })
117
119
  close
118
120
  end
119
121
 
@@ -125,20 +127,19 @@ module Processing
125
127
 
126
128
  args = []
127
129
  @width, @height = options[:width], options[:height]
128
- if @@full_screen || options[:full_screen]
129
- @@full_screen = true
130
- args << "--present"
130
+ if @full_screen || options[:full_screen]
131
+ @full_screen = true
132
+ args << '--present'
131
133
  end
132
134
  @render_mode ||= JAVA2D
133
- xc = Processing::RP_CONFIG["X_OFF"] ||= 0
134
- yc = Processing::RP_CONFIG["Y_OFF"] ||= 0
135
+ xc = Processing::RP_CONFIG['X_OFF'] ||= 0
136
+ yc = Processing::RP_CONFIG['Y_OFF'] ||= 0
135
137
  x = options[:x] || xc
136
138
  y = options[:y] || yc
137
139
  args << "--location=#{x},#{y}" # important no spaces here
138
140
  title = options[:title] || File.basename(SKETCH_PATH).sub(/(\.rb)$/, '').titleize
139
141
  args << title
140
142
  PApplet.run_sketch(args, self)
141
- #end
142
143
  end
143
144
 
144
145
  def size(*args)
@@ -155,27 +156,26 @@ module Processing
155
156
  super(*args)
156
157
  end
157
158
 
158
- def post_initialize(args)
159
+ def post_initialize(_args)
159
160
  nil
160
161
  end
161
162
 
162
163
  # Make sure we set the size if we set it before we start the animation thread.
163
164
  def start
164
- self.size(@width, @height) if @width && @height
165
+ size(@width, @height) if @width && @height
165
166
  super()
166
167
  end
167
168
 
168
169
  # Provide a loggable string to represent this sketch.
169
170
  def inspect
170
171
  "#<Processing::App:#{self.class}:#{@title}>"
171
- #"#<Processing::App:#{self.class}>"
172
172
  end
173
173
 
174
174
  # Cleanly close and shutter a running sketch.
175
175
  def close
176
176
  control_panel.remove if respond_to?(:control_panel)
177
- self.dispose
178
- self.frame.dispose
177
+ dispose
178
+ frame.dispose
179
179
  end
180
180
 
181
181
  private
@@ -183,7 +183,6 @@ module Processing
183
183
  # Mix the Processing::Proxy into any inner classes defined for the
184
184
  # sketch, attempting to mimic the behavior of Java's inner classes.
185
185
  def mix_proxy_into_inner_classes
186
-
187
186
  klass = Processing::App.sketch_class
188
187
  klass.constants.each do |name|
189
188
  const = klass.const_get name
@@ -203,14 +202,14 @@ module Processing
203
202
  def self.desired_method_names(inner_class)
204
203
  bad_method = /__/ # Internal JRuby methods.
205
204
  unwanted = PApplet.superclass.instance_methods + Object.instance_methods
206
- unwanted -= ['width', 'height', 'cursor', 'create_image', 'background', 'size', 'resize']
205
+ unwanted -= %w(width height cursor create_image background size resize)
207
206
  methods = Processing::App.public_instance_methods
208
- methods.reject {|m| unwanted.include?(m) || bad_method.match(m) || inner_class.method_defined?(m) }
207
+ methods.reject { |m| unwanted.include?(m) || bad_method.match(m) || inner_class.method_defined?(m) }
209
208
  end
210
209
 
211
210
  # Proxy methods through to the sketch.
212
211
  def self.proxy_methods(inner_class)
213
- code = desired_method_names(inner_class).inject('') do |rcode, method|
212
+ code = desired_method_names(inner_class).reduce('') do |rcode, method|
214
213
  rcode << <<-EOS
215
214
  def #{method}(*args, &block) # def rect(*args, &block)
216
215
  if block_given? # if block_given?
@@ -1,11 +1,9 @@
1
1
  require 'psych'
2
2
 
3
3
  module Processing
4
-
5
4
  if Processing.exported?
6
5
  RP_CONFIG = { 'PROCESSING_ROOT' => RP5_ROOT, 'JRUBY' => 'false' }
7
6
  end
8
-
9
7
  unless defined? RP_CONFIG
10
8
  begin
11
9
  CONFIG_FILE_PATH = File.expand_path('~/.rp5rc')
@@ -61,7 +61,7 @@ module Processing
61
61
 
62
62
  def calculate_substitutions
63
63
  file_list = ['lib/ruby/jruby-complete.jar']
64
- @class_path = file_list.map { |f| '$JAVAROOT/' + f.sub(@prefix + "/", '') }.join(":")
64
+ @class_path = file_list.map { |f| '$JAVAROOT/' + f.sub(@prefix + '/', '') }.join(':')
65
65
  @linux_class_path = '.:../lib/ruby/*:../lib/*:../lib/library/*'
66
66
  @windows_class_path = '.;../lib/ruby/*;../lib/*;../lib/library/*'
67
67
  end
@@ -83,7 +83,7 @@ module Processing
83
83
  code = source.dup
84
84
  requirements = []
85
85
  partial_paths = []
86
- loop do
86
+ Kernel.loop do
87
87
  matchdata = code.match(
88
88
  /^.*[^::\.\w](require_relative|require|load)\b.*$/
89
89
  )
@@ -62,7 +62,7 @@ module Processing
62
62
  class BasicSketch < Creator
63
63
  # Create a blank sketch, given a path.
64
64
  def basic_template
65
- %{
65
+ %(
66
66
  def setup
67
67
  size <%=@width%>, <%=@height%>
68
68
  end
@@ -70,11 +70,11 @@ end
70
70
  def draw
71
71
 
72
72
  end
73
- }
73
+ )
74
74
  end
75
75
 
76
76
  def basic_template_mode
77
- %{
77
+ %(
78
78
  def setup
79
79
  size <%=@width%>, <%=@height%>, <%=@mode%>
80
80
  end
@@ -82,7 +82,7 @@ end
82
82
  def draw
83
83
 
84
84
  end
85
- }
85
+ )
86
86
  end
87
87
 
88
88
  def create!(path, args)
@@ -109,7 +109,7 @@ end
109
109
  class ClassSketch < Creator
110
110
 
111
111
  def class_template
112
- %{
112
+ %(
113
113
  class <%=@name%> < Processing::App
114
114
  def setup
115
115
  size <%=@width%>, <%=@height%>
@@ -121,11 +121,11 @@ class <%=@name%> < Processing::App
121
121
  end
122
122
 
123
123
  # <%=@name%>.new(x: 20, y: 20)
124
- }
124
+ )
125
125
  end
126
126
 
127
127
  def class_template_mode
128
- %{
128
+ %(
129
129
  class <%=@name%> < Processing::App
130
130
  def setup
131
131
  size <%=@width%>, <%=@height%>, <%=@mode%>
@@ -137,7 +137,7 @@ class <%=@name%> < Processing::App
137
137
  end
138
138
 
139
139
  # <%=@name%>.new(x: 20, y: 20)
140
- }
140
+ )
141
141
  end
142
142
  # Create a bare blank sketch, given a path.
143
143
  def create!(path, args)
@@ -163,12 +163,12 @@ end
163
163
  # This class creates a ruby-processing class that mimics java inner class
164
164
  class Inner < Creator
165
165
  def inner_class_template
166
- %{
166
+ %(
167
167
  class <%=@name%>
168
- include_module Processing::Proxy
168
+ include Processing::Proxy
169
169
 
170
170
  end
171
- }
171
+ )
172
172
  end
173
173
  # Create a blank sketch, given a path.
174
174
  def create!(path, _args_)
@@ -1,6 +1,7 @@
1
1
  module Processing
2
2
  module HelperMethods
3
-
3
+ # processings epsilon may not be defined yet
4
+ EPSILON ||= 1.0e-04
4
5
  # Nice block method to draw to a buffer.
5
6
  # You can optionally pass it a width, a height, and a renderer.
6
7
  # Takes care of starting and ending the draw for you.
@@ -42,31 +43,20 @@ module Processing
42
43
  super(*args)
43
44
  end
44
45
 
45
- # Overrides convenience function loop, to add ability to loop over a block
46
- # if supplied, otherwise perform as the PApplet class would
47
- def loop(&block)
48
- if block_given?
49
- while true do
50
- yield
51
- end
52
- else
53
- super
54
- end
55
- end
56
-
57
46
  # Overrides Processing convenience function thread, which takes a String
58
47
  # arg (for a function) to more rubylike version, takes a block...
59
48
  def thread(&block)
60
49
  if block_given?
61
50
  Thread.new(&block)
62
51
  else
63
- fail ArgumentError, 'thread must be called with a block' , caller
52
+ fail ArgumentError, 'thread must be called with a block', caller
64
53
  end
65
54
  end
66
55
 
67
56
  # Explicitly provides 'processing.org' map instance method, in which
68
57
  # value is mapped from range 1, to range 2 (NB: values are not clamped to
69
- # range 1). It may be better to explicitly write your own interpolate function
58
+ # range 1). It may be better to explicitly write your own interpolate
59
+ # function
70
60
  # @param [float] value input
71
61
  # @param [range] start1, stop1
72
62
  # @param [range] start1, stop2
@@ -74,11 +64,12 @@ module Processing
74
64
  def map(value, start1, stop1, start2, stop2)
75
65
  start2 + (stop2 - start2) * ((value - start1).to_f / (stop1 - start1))
76
66
  end
77
-
67
+
78
68
  # ruby alternative implementation of map using range parameters
79
- # NB: (begin .. end) and excluded end (begin ... end) versions produce the same result
69
+ # (begin..end) and excluded end (begin...end) produce the same result
80
70
  def map1d(val, r_in, r_out)
81
- r_out.begin + (r_out.end - r_out.begin) * ((val - r_in.begin).to_f / (r_in.end - r_in.begin))
71
+ r_out.begin + (r_out.end - r_out.begin) *
72
+ ((val - r_in.begin).to_f / (r_in.end - r_in.begin))
82
73
  end
83
74
 
84
75
  # explicitly provide 'processing.org' norm instance method
@@ -95,34 +86,40 @@ module Processing
95
86
  # to return a float:- a, b and c need to be floats
96
87
 
97
88
  def min(*args)
98
- args.min { |a,b| a <=> b }
89
+ args.min # { |a,b| a <=> b } optional block not reqd
99
90
  end
100
91
 
101
92
  # explicitly provide 'processing.org' max instance method
102
93
  # to return a float:- a, b and c need to be floats
103
94
 
104
95
  def max(*args)
105
- args.max { |a, b| a <=> b }
96
+ args.max # { |a, b| a <=> b } optional block not reqd
106
97
  end
107
-
108
98
 
109
99
  # explicitly provide 'processing.org' dist instance method
110
100
  def dist(*args)
111
- alen = args.length
112
- return Math.hypot(args[0] - args[2], args[1] - args[3]) if alen == 4
113
- return Math.sqrt((args[0] - args[3]) * (args[0] - args[3]) +
114
- (args[1] - args[4]) * (args[1] - args[4]) +
115
- (args[2] - args[5]) * (args[2] - args[5])) if alen == 6
101
+ len = args.length
102
+ if len == 4
103
+ dx = args[0] - args[2]
104
+ dy = args[1] - args[3]
105
+ return 0 if dx.abs < EPSILON && dy.abs < EPSILON
106
+ return Math.hypot(dx, dy)
107
+ elsif len == 6
108
+ dx = args[0] - args[3]
109
+ dy = args[1] - args[4]
110
+ dz = args[2] - args[5]
111
+ return 0 if dx.abs < EPSILON && dy.abs < EPSILON && dz.abs < EPSILON
112
+ return Math.sqrt(dx * dx + dy * dy + dz * dz)
113
+ end
116
114
  fail ArgumentError, 'takes 4 or 6 parameters'
117
115
  end
118
116
 
119
117
  # explicitly provide 'processing.org' constrain instance method
120
118
  # to return a float:- amt, low and high need to be floats
121
119
  def constrain(amt, low, high)
122
- (amt < low) ? low : ((amt > high) ? high : amt)
120
+ (low..high).clip(amt)
123
121
  end
124
122
 
125
-
126
123
  # Uses PImage class method under hood
127
124
  def blend_color(c1, c2, mode)
128
125
  PImage.blendColor(c1, c2, mode)
@@ -132,7 +129,7 @@ module Processing
132
129
  # Here's a convenient way to look for them.
133
130
  def find_method(method_name)
134
131
  reg = Regexp.new("#{method_name}", true)
135
- self.methods.sort.select { |meth| reg.match(meth) }
132
+ methods.sort.select { |meth| reg.match(meth) }
136
133
  end
137
134
 
138
135
  # Proxy over a list of Java declared fields that have the same name as
@@ -159,7 +156,7 @@ module Processing
159
156
 
160
157
  # Provide a convenient handle for the Java-space version of self.
161
158
  def java_self
162
- @java_self ||= self.to_java(Java::ProcessingCore::PApplet)
159
+ @java_self ||= to_java(Java::ProcessingCore::PApplet)
163
160
  end
164
161
 
165
162
 
@@ -170,13 +167,18 @@ module Processing
170
167
 
171
168
  # Fields that should be made accessible as under_scored.
172
169
  def mouse_x; mouseX; end
170
+
173
171
  def mouse_y; mouseY; end
172
+
174
173
  def pmouse_x; pmouseX; end
174
+
175
175
  def pmouse_y; pmouseY; end
176
+
176
177
  def frame_count; frameCount; end
178
+
177
179
  def mouse_button; mouseButton; end
178
- def key_code; keyCode; end
179
180
 
181
+ def key_code; keyCode; end
180
182
 
181
183
  # Ensure that load_strings returns a real Ruby array
182
184
  def load_strings(file_or_url)