propane 3.3.1-java → 3.6.0-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (157) hide show
  1. checksums.yaml +4 -4
  2. data/.mvn/extensions.xml +1 -2
  3. data/.mvn/wrapper/MavenWrapperDownloader.java +117 -0
  4. data/.mvn/wrapper/maven-wrapper.properties +2 -3
  5. data/.travis.yml +9 -0
  6. data/CHANGELOG.md +17 -5
  7. data/Gemfile +2 -0
  8. data/README.md +17 -8
  9. data/Rakefile +16 -30
  10. data/bin/propane +3 -1
  11. data/lib/propane.rb +6 -4
  12. data/lib/propane/app.rb +20 -10
  13. data/lib/propane/creators/sketch_class.rb +7 -1
  14. data/lib/propane/creators/sketch_factory.rb +4 -2
  15. data/lib/propane/creators/sketch_writer.rb +1 -0
  16. data/lib/propane/helper_methods.rb +23 -24
  17. data/lib/propane/helpers/numeric.rb +2 -0
  18. data/lib/propane/helpers/version_error.rb +1 -0
  19. data/lib/propane/library.rb +5 -1
  20. data/lib/propane/library_loader.rb +2 -0
  21. data/lib/propane/native_folder.rb +21 -15
  22. data/lib/propane/native_loader.rb +3 -0
  23. data/lib/propane/runner.rb +14 -6
  24. data/lib/propane/version.rb +2 -1
  25. data/library/boids/boids.rb +21 -11
  26. data/library/color_group/color_group.rb +28 -0
  27. data/library/control_panel/control_panel.rb +8 -5
  28. data/library/dxf/dxf.rb +6 -0
  29. data/library/file_chooser/chooser.rb +10 -9
  30. data/library/file_chooser/file_chooser.rb +10 -9
  31. data/library/library_proxy/library_proxy.rb +2 -0
  32. data/library/net/net.rb +7 -0
  33. data/library/simplex_noise/simplex_noise.rb +2 -0
  34. data/library/slider/slider.rb +23 -22
  35. data/library/vector_utils/vector_utils.rb +4 -0
  36. data/library/video_event/video_event.rb +4 -1
  37. data/mvnw +127 -51
  38. data/mvnw.cmd +182 -145
  39. data/pom.rb +53 -50
  40. data/pom.xml +17 -8
  41. data/propane.gemspec +13 -11
  42. data/src/main/java/monkstone/ColorUtil.java +13 -1
  43. data/src/main/java/monkstone/MathToolModule.java +253 -203
  44. data/src/main/java/monkstone/PropaneLibrary.java +2 -2
  45. data/src/main/java/monkstone/fastmath/Deglut.java +1 -1
  46. data/src/main/java/monkstone/filechooser/Chooser.java +2 -1
  47. data/src/main/java/monkstone/noise/SimplexNoise.java +2 -2
  48. data/src/main/java/monkstone/slider/CustomHorizontalSlider.java +1 -1
  49. data/src/main/java/monkstone/slider/CustomVerticalSlider.java +1 -1
  50. data/src/main/java/monkstone/slider/SimpleHorizontalSlider.java +1 -1
  51. data/src/main/java/monkstone/slider/SimpleVerticalSlider.java +1 -1
  52. data/src/main/java/monkstone/slider/SliderBar.java +1 -1
  53. data/src/main/java/monkstone/slider/SliderGroup.java +1 -1
  54. data/src/main/java/monkstone/slider/WheelHandler.java +7 -6
  55. data/src/main/java/monkstone/vecmath/package-info.java +1 -1
  56. data/src/main/java/monkstone/vecmath/vec2/Vec2.java +2 -2
  57. data/src/main/java/monkstone/vecmath/vec3/Vec3.java +1 -1
  58. data/src/main/java/monkstone/videoevent/CaptureEvent.java +27 -0
  59. data/src/main/java/monkstone/videoevent/{VideoInterface.java → MovieEvent.java} +11 -27
  60. data/src/main/java/monkstone/videoevent/package-info.java +1 -1
  61. data/src/main/java/processing/awt/PGraphicsJava2D.java +2164 -1661
  62. data/src/main/java/processing/awt/PImageAWT.java +377 -0
  63. data/src/main/java/processing/awt/PShapeJava2D.java +280 -268
  64. data/src/main/java/processing/awt/PSurfaceAWT.java +942 -829
  65. data/src/main/java/processing/awt/ShimAWT.java +581 -0
  66. data/src/main/java/processing/core/PApplet.java +831 -824
  67. data/src/main/java/processing/core/PConstants.java +477 -447
  68. data/src/main/java/processing/core/PFont.java +914 -880
  69. data/src/main/java/processing/core/PGraphics.java +229 -213
  70. data/src/main/java/processing/core/PImage.java +620 -318
  71. data/src/main/java/processing/core/PMatrix.java +172 -159
  72. data/src/main/java/processing/core/PMatrix2D.java +478 -409
  73. data/src/main/java/processing/core/PMatrix3D.java +762 -735
  74. data/src/main/java/processing/core/PShape.java +2888 -2652
  75. data/src/main/java/processing/core/PShapeOBJ.java +436 -415
  76. data/src/main/java/processing/core/PShapeSVG.java +1702 -1479
  77. data/src/main/java/processing/core/PStyle.java +40 -37
  78. data/src/main/java/processing/core/PSurface.java +139 -97
  79. data/src/main/java/processing/core/PSurfaceNone.java +296 -208
  80. data/src/main/java/processing/core/PVector.java +997 -965
  81. data/src/main/java/processing/core/ThinkDifferent.java +12 -17
  82. data/src/main/java/processing/data/DoubleDict.java +756 -710
  83. data/src/main/java/processing/data/DoubleList.java +749 -696
  84. data/src/main/java/processing/data/FloatDict.java +748 -702
  85. data/src/main/java/processing/data/FloatList.java +751 -697
  86. data/src/main/java/processing/data/IntDict.java +720 -673
  87. data/src/main/java/processing/data/IntList.java +699 -633
  88. data/src/main/java/processing/data/JSONArray.java +931 -873
  89. data/src/main/java/processing/data/JSONObject.java +1262 -1165
  90. data/src/main/java/processing/data/JSONTokener.java +351 -341
  91. data/src/main/java/processing/data/LongDict.java +710 -663
  92. data/src/main/java/processing/data/LongList.java +701 -635
  93. data/src/main/java/processing/data/Sort.java +37 -41
  94. data/src/main/java/processing/data/StringDict.java +525 -486
  95. data/src/main/java/processing/data/StringList.java +626 -580
  96. data/src/main/java/processing/data/Table.java +3690 -3510
  97. data/src/main/java/processing/data/TableRow.java +182 -183
  98. data/src/main/java/processing/data/XML.java +957 -883
  99. data/src/main/java/processing/dxf/RawDXF.java +404 -0
  100. data/src/main/java/processing/event/Event.java +87 -66
  101. data/src/main/java/processing/event/KeyEvent.java +48 -41
  102. data/src/main/java/processing/event/MouseEvent.java +88 -113
  103. data/src/main/java/processing/event/TouchEvent.java +10 -6
  104. data/src/main/java/processing/javafx/PGraphicsFX2D.java +20 -345
  105. data/src/main/java/processing/javafx/PSurfaceFX.java +149 -121
  106. data/src/main/java/processing/net/Client.java +744 -0
  107. data/src/main/java/processing/net/Server.java +388 -0
  108. data/src/main/java/processing/opengl/FontTexture.java +289 -270
  109. data/src/main/java/processing/opengl/FrameBuffer.java +386 -364
  110. data/src/main/java/processing/opengl/LinePath.java +547 -500
  111. data/src/main/java/processing/opengl/LineStroker.java +588 -581
  112. data/src/main/java/processing/opengl/PGL.java +3047 -2914
  113. data/src/main/java/processing/opengl/PGraphics2D.java +408 -315
  114. data/src/main/java/processing/opengl/PGraphics3D.java +107 -72
  115. data/src/main/java/processing/opengl/PGraphicsOpenGL.java +12378 -12075
  116. data/src/main/java/processing/opengl/PJOGL.java +1753 -1670
  117. data/src/main/java/processing/opengl/PShader.java +1266 -1257
  118. data/src/main/java/processing/opengl/PShapeOpenGL.java +4678 -4580
  119. data/src/main/java/processing/opengl/PSurfaceJOGL.java +1114 -1027
  120. data/src/main/java/processing/opengl/Texture.java +1492 -1401
  121. data/src/main/java/processing/opengl/VertexBuffer.java +57 -55
  122. data/test/create_test.rb +21 -20
  123. data/test/deglut_spec_test.rb +4 -2
  124. data/test/helper_methods_test.rb +49 -20
  125. data/test/math_tool_test.rb +39 -32
  126. data/test/native_folder.rb +47 -0
  127. data/test/respond_to_test.rb +3 -2
  128. data/test/sketches/key_event.rb +2 -2
  129. data/test/sketches/library/my_library/my_library.rb +3 -0
  130. data/test/test_helper.rb +2 -0
  131. data/test/vecmath_spec_test.rb +35 -22
  132. data/vendors/Rakefile +33 -62
  133. metadata +54 -45
  134. data/src/main/java/processing/core/util/image/ImageLoadFacade.java +0 -161
  135. data/src/main/java/processing/core/util/image/ImageSaveFacade.java +0 -169
  136. data/src/main/java/processing/core/util/image/constants/TifConstants.java +0 -45
  137. data/src/main/java/processing/core/util/image/load/AwtImageLoadStrategy.java +0 -80
  138. data/src/main/java/processing/core/util/image/load/Base64StringImageLoadStrategy.java +0 -73
  139. data/src/main/java/processing/core/util/image/load/FallbackImageLoadStrategy.java +0 -70
  140. data/src/main/java/processing/core/util/image/load/ImageIoImageLoadStrategy.java +0 -132
  141. data/src/main/java/processing/core/util/image/load/ImageLoadStrategy.java +0 -48
  142. data/src/main/java/processing/core/util/image/load/ImageLoadUtil.java +0 -45
  143. data/src/main/java/processing/core/util/image/load/TgaImageLoadStrategy.java +0 -255
  144. data/src/main/java/processing/core/util/image/load/TiffImageLoadStrategy.java +0 -98
  145. data/src/main/java/processing/core/util/image/save/ImageSaveStrategy.java +0 -49
  146. data/src/main/java/processing/core/util/image/save/ImageSaveUtil.java +0 -48
  147. data/src/main/java/processing/core/util/image/save/ImageWriterImageSaveStrategy.java +0 -179
  148. data/src/main/java/processing/core/util/image/save/SaveImageException.java +0 -41
  149. data/src/main/java/processing/core/util/image/save/TgaImageSaveStrategy.java +0 -198
  150. data/src/main/java/processing/core/util/image/save/TiffImageSaveStrategy.java +0 -91
  151. data/src/main/java/processing/core/util/image/save/TiffNakedFilenameImageSaveStrategy.java +0 -57
  152. data/src/main/java/processing/core/util/io/InputFactory.java +0 -285
  153. data/src/main/java/processing/core/util/io/PathUtil.java +0 -109
  154. data/src/main/java/processing/opengl/shaders/LightVert-brcm.glsl +0 -154
  155. data/src/main/java/processing/opengl/shaders/LightVert-vc4.glsl +0 -154
  156. data/src/main/java/processing/opengl/shaders/TexLightVert-brcm.glsl +0 -160
  157. data/src/main/java/processing/opengl/shaders/TexLightVert-vc4.glsl +0 -160
@@ -5,7 +5,10 @@ class SketchClass
5
5
  attr_reader :name, :width, :height, :mode
6
6
 
7
7
  def initialize(name:, width: 150, height: 150, mode: nil)
8
- @name, @width, @height, @mode = name, width, height, mode
8
+ @name = name
9
+ @width = width
10
+ @height = height
11
+ @mode = mode
9
12
  end
10
13
 
11
14
  def class_sketch
@@ -26,6 +29,7 @@ class SketchClass
26
29
 
27
30
  def size
28
31
  return format(' size %d, %d', width.to_i, height.to_i) unless mode
32
+
29
33
  format(' size %d, %d, %s', width.to_i, height.to_i, mode.upcase)
30
34
  end
31
35
 
@@ -36,6 +40,7 @@ class SketchClass
36
40
 
37
41
  def method_lines(name, content = nil)
38
42
  return [format(' def %s', name), '', ' end'] unless content
43
+
39
44
  [format(' def %s', name), content, ' end', '']
40
45
  end
41
46
 
@@ -43,6 +48,7 @@ class SketchClass
43
48
  lines = [
44
49
  '#!/usr/bin/env jruby',
45
50
  '# frozen_string_literal: false',
51
+ '',
46
52
  "require 'propane'",
47
53
  '',
48
54
  class_sketch
@@ -1,8 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'sketch_writer'
2
4
 
3
5
  class SketchFactory
4
- NAMES = %w[One Two Three]
5
- def initialize(argc)
6
+ NAMES = %w[One Two Three].freeze
7
+ def initialize(_argc)
6
8
  NAMES.each do |name|
7
9
  SketchWriter.new(File.basename(name, '.rb'), width: 300, height: 300).write
8
10
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: false
2
+
2
3
  require_relative 'sketch_class'
3
4
 
4
5
  # The file writer can write a sketch when given instance of Sketch type
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: false
2
+
2
3
  # processing module wrapper
3
- require_relative 'helpers/numeric'
4
4
  module Propane
5
5
  # Provides some convenience methods
6
6
  module HelperMethods
@@ -52,11 +52,12 @@ module Propane
52
52
 
53
53
  def color(*args)
54
54
  return super(*args) unless args.length == 1
55
+
55
56
  super(hex_color(args[0]))
56
57
  end
57
58
 
58
59
  def web_to_color_array(web)
59
- Java::Monkstone::ColorUtil.webArray(web)
60
+ Java::Monkstone::ColorUtil.webArray(web.to_java(:string))
60
61
  end
61
62
 
62
63
  def int_to_ruby_colors(hex)
@@ -66,11 +67,8 @@ module Propane
66
67
  # Overrides Processing convenience function thread, which takes a String
67
68
  # arg (for a function) to more rubylike version, takes a block...
68
69
  def thread(&block)
69
- if block_given?
70
- Thread.new(&block)
71
- else
72
- raise ArgumentError, 'thread must be called with a block', caller
73
- end
70
+ warn 'A Block is Needed' unless block_given?
71
+ Java::JavaLang::Thread.new(&block).start
74
72
  end
75
73
 
76
74
  # explicitly provide 'processing.org' min instance method
@@ -94,9 +92,9 @@ module Propane
94
92
  def dist(*args)
95
93
  case args.length
96
94
  when 4
97
- return dist2d(*args)
95
+ dist2d(*args)
98
96
  when 6
99
- return dist3d(*args)
97
+ dist3d(*args)
100
98
  else
101
99
  raise ArgumentError, 'takes 4 or 6 parameters'
102
100
  end
@@ -111,13 +109,13 @@ module Propane
111
109
  # Here's a convenient way to look for them.
112
110
  def find_method(method_name)
113
111
  reg = Regexp.new(method_name.to_s, true)
114
- methods.sort.select { |meth| reg.match(meth) }
112
+ methods.sort.select { |meth| reg.match?(meth) }
115
113
  end
116
114
 
117
115
  # Proxy over a list of Java declared fields that have the same name as
118
116
  # some methods. Add to this list as needed.
119
117
  def proxy_java_fields
120
- fields = %w(key frameRate mousePressed keyPressed)
118
+ fields = %w[key frameRate mousePressed keyPressed]
121
119
  methods = fields.map { |field| java_class.declared_field(field) }
122
120
  @declared_fields = Hash[fields.zip(methods)]
123
121
  end
@@ -163,6 +161,7 @@ module Propane
163
161
  # frame_rate needs to support reading and writing
164
162
  def frame_rate(fps = nil)
165
163
  return @declared_fields['frameRate'].value(java_self) unless fps
164
+
166
165
  super(fps)
167
166
  end
168
167
 
@@ -178,21 +177,19 @@ module Propane
178
177
 
179
178
  private
180
179
 
181
- INTEGER_COL = -> (x) { x.is_a?(Integer) }
182
- STRING_COL = -> (x) { x.is_a?(String) }
183
- FLOAT_COL = -> (x) { x.is_a?(Float) }
184
180
  # parse single argument color int/double/String
185
- def hex_color(a)
186
- case a
187
- when INTEGER_COL
188
- Java::Monkstone::ColorUtil.colorLong(a)
189
- when STRING_COL
190
- return Java::Monkstone::ColorUtil.colorString(a) if a =~ /#\h+/
191
- raise StandardError, 'Dodgy Hexstring'
192
- when FLOAT_COL
193
- Java::Monkstone::ColorUtil.colorDouble(a)
181
+ def hex_color(arg)
182
+ case arg
183
+ when Integer
184
+ Java::Monkstone::ColorUtil.colorLong(arg)
185
+ when String
186
+ raise 'Dodgy Hexstring' unless /#\h{6}$/.match?(arg)
187
+
188
+ Java::Monkstone::ColorUtil.colorString(arg)
189
+ when Float
190
+ Java::Monkstone::ColorUtil.colorDouble(arg)
194
191
  else
195
- raise StandardError, 'Dodgy Color Conversion'
192
+ raise 'Dodgy Color Conversion'
196
193
  end
197
194
  end
198
195
 
@@ -200,6 +197,7 @@ module Propane
200
197
  dx = args[0] - args[2]
201
198
  dy = args[1] - args[3]
202
199
  return 0 if dx.abs < EPSILON && dy.abs < EPSILON
200
+
203
201
  Math.hypot(dx, dy)
204
202
  end
205
203
 
@@ -208,6 +206,7 @@ module Propane
208
206
  dy = args[1] - args[4]
209
207
  dz = args[2] - args[5]
210
208
  return 0 if dx.abs < EPSILON && dy.abs < EPSILON && dz.abs < EPSILON
209
+
211
210
  Math.sqrt(dx * dx + dy * dy + dz * dz)
212
211
  end
213
212
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Numeric #:nodoc:
2
4
  def degrees
3
5
  self * 57.29577951308232
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
 
2
3
  class JDKVersionError < StandardError
3
4
  def message
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'native_folder'
2
4
  require_relative 'native_loader'
3
5
  require 'pathname'
@@ -18,6 +20,7 @@ class Library
18
20
  return if (@path = Pathname.new(
19
21
  File.join(PROPANE_ROOT, 'library', name, "#{name}.rb")
20
22
  )).exist?
23
+
21
24
  locate_java
22
25
  end
23
26
 
@@ -46,10 +49,11 @@ class Library
46
49
  end
47
50
 
48
51
  def load_jars
49
- Dir.glob("#{dir}/*.jar").each do |jar|
52
+ Dir.glob("#{dir}/*.jar").sort.each do |jar|
50
53
  require jar
51
54
  end
52
55
  return true unless native_binaries?
56
+
53
57
  add_binaries_to_classpath
54
58
  end
55
59
 
@@ -33,10 +33,12 @@ module Propane
33
33
 
34
34
  def loader(name)
35
35
  return true if @loaded_libraries.include?(name)
36
+
36
37
  fname = name.to_s
37
38
  library = Library.new(fname)
38
39
  library.locate
39
40
  return require_library(library, name) if library.ruby?
41
+
40
42
  warn("Not found library: #{fname}") unless library.exist?
41
43
  load_jars(library, name)
42
44
  end
@@ -1,33 +1,39 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rbconfig'
2
4
 
3
5
  # Utility to load native binaries on Java CLASSPATH
4
6
  class NativeFolder
5
7
  attr_reader :os, :bit
6
8
 
7
- WIN_FORMAT = 'windows%d'.freeze
8
- LINUX_FORMAT = 'linux%d'.freeze
9
- # WIN_PATTERNS = [
10
- # /bccwin/i,
11
- # /cygwin/i,
12
- # /djgpp/i,
13
- # /ming/i,
14
- # /mswin/i,
15
- # /wince/i
16
- # ].freeze
9
+ WIN_FORMAT = 'windows%d'
10
+ LINUX_FORMAT = 'linux%d'
11
+ WIN_PATTERNS = [
12
+ /bccwin/i,
13
+ /cygwin/i,
14
+ /djgpp/i,
15
+ /ming/i,
16
+ /mswin/i,
17
+ /wince/i
18
+ ].freeze
17
19
 
18
20
  def initialize
19
21
  @os = RbConfig::CONFIG['host_os'].downcase
20
- @bit = java.lang.System.get_property('os.arch') =~ /64/ ? 64 : 32
22
+ @bit = /64/.match?(java.lang.System.get_property('os.arch')) ? 64 : 32
21
23
  end
22
24
 
23
25
  def name
24
- return 'macosx' if os =~ /darwin/ || os =~ /mac/
25
- # return format(WIN_FORMAT, bit) if WIN_PATTERNS.include? os
26
- return format(LINUX_FORMAT, bit) if os =~ /linux/
26
+ return 'macosx' if /darwin|mac/.match?(os)
27
+ return format(LINUX_FORMAT, bit) if /linux/.match?(os)
28
+ return format(WIN_FORMAT, bit) if WIN_PATTERNS.any? { |pat| pat.match?(os) }
29
+
30
+ raise 'Unsupported Architecture'
27
31
  end
28
32
 
29
33
  def extension
30
- return '*.so' if os =~ /linux/
34
+ return '*.so' if /linux/.match?(os)
35
+ return '*.dll' if WIN_PATTERNS.any? { |pat| pat.match?(os) }
36
+
31
37
  '*.dylib' # MacOS
32
38
  end
33
39
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # This class knows how to dynamically set the 'java' native library path
2
4
  # It might not work with java 9?
3
5
  class NativeLoader
@@ -21,6 +23,7 @@ class NativeLoader
21
23
  field = JC::Class.for_name('java.lang.ClassLoader')
22
24
  .get_declared_field('sys_paths')
23
25
  return unless field
26
+
24
27
  field.accessible = true # some jruby magic
25
28
  field.set(JC::Class.for_name('java.lang.System').get_class_loader, nil)
26
29
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: false
2
+
2
3
  require 'optparse'
3
4
  require_relative 'version'
4
5
 
@@ -40,7 +41,7 @@ module Propane
40
41
  end
41
42
 
42
43
  options[:install] = false
43
- message = '<Samples><GLVideo><Video><Sound> Install samples or library'
44
+ message = '<Samples><Video><Sound> Install samples or library'
44
45
  opts.on('-i', '--install', message) do
45
46
  options[:install] = true
46
47
  end
@@ -54,6 +55,8 @@ module Propane
54
55
  # assumed to have this option.
55
56
  opts.on('-h', '--help', 'Display this screen') do
56
57
  puts opts
58
+ puts ''
59
+ puts 'Run a sketch: jruby [--dev] [<sketch.rb>]'
57
60
  exit
58
61
  end
59
62
  end
@@ -67,7 +70,6 @@ module Propane
67
70
  end
68
71
 
69
72
  def show_version
70
-
71
73
  v_format = "Propane version %s\nJRuby version %s"
72
74
  puts format(v_format, Propane::VERSION, JRUBY_VERSION)
73
75
  end
@@ -75,7 +77,8 @@ module Propane
75
77
  def show_version
76
78
  require 'erb'
77
79
  require_relative 'helpers/version_error'
78
- raise JDKVersionError.new if ENV_JAVA['java.specification.version'] < '11'
80
+ raise JDKVersionError if ENV_JAVA['java.specification.version'] < '11'
81
+
79
82
  template = ERB.new <<-EOF
80
83
  propane version <%= Propane::VERSION %>
81
84
  JRuby version <%= JRUBY_VERSION %>
@@ -86,8 +89,13 @@ module Propane
86
89
  def install(library)
87
90
  choice = library.downcase
88
91
  valid = Regexp.union('samples', 'sound', 'video', 'glvideo')
89
- return warn format('No installer for %s', choice) unless valid =~ choice
92
+ unless valid.match?(choice)
93
+ return warn format('No installer for %<lib>s', lib: choice)
94
+ end
95
+
90
96
  system "cd #{PROPANE_ROOT}/vendors && rake download_and_copy_#{choice}"
91
97
  end
92
- end # class Runner
93
- end # module Propane
98
+ end
99
+ # class Runner
100
+ end
101
+ # module Propane
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Propane
3
- VERSION = '3.3.1'.freeze
4
+ VERSION = '3.6.0'
4
5
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Boids -- after Tom de Smedt.
2
4
  # See his Python version: http://nodebox.net/code/index.php/Boids
3
5
  # This is an example of how a pure-Ruby library can work. Original for
@@ -7,7 +9,8 @@ class Boid
7
9
  attr_accessor :boids, :pos, :vel, :is_perching, :perch_time
8
10
 
9
11
  def initialize(boids, pos)
10
- @boids, @flock = boids, boids
12
+ @boids = boids
13
+ @flock = boids
11
14
  @pos = pos
12
15
  @vel = Vec3D.new
13
16
  @is_perching = false
@@ -53,6 +56,7 @@ class Boid
53
56
  # Tweet, Tweet! The boid police will bust you for breaking the speed limit.
54
57
  most = [vel.x.abs, vel.y.abs, vel.z.abs].max
55
58
  return if most < max
59
+
56
60
  scale = max / most.to_f
57
61
  @vel *= scale
58
62
  end
@@ -75,7 +79,7 @@ class Boids
75
79
  extend Forwardable
76
80
  def_delegators(:@boids, :reject, :<<, :each, :shuffle!, :length, :next)
77
81
 
78
- attr_reader :has_goal, :perch, :perch_tm, :perch_y
82
+ attr_reader :has_goal, :perchance, :perch_tm, :perch_y
79
83
 
80
84
  def initialize
81
85
  @boids = []
@@ -88,16 +92,20 @@ class Boids
88
92
 
89
93
  def setup(n, x, y, w, h)
90
94
  n.times do
91
- dx, dy = rand(w), rand(h)
95
+ dx = rand(w)
96
+ dy = rand(h)
92
97
  z = rand(200.0)
93
98
  self << Boid.new(self, Vec3D.new(x + dx, y + dy, z))
94
99
  end
95
- @x, @y, @w, @h = x, y, w, h
100
+ @x = x
101
+ @y = y
102
+ @w = w
103
+ @h = h
96
104
  @scattered = false
97
105
  @scatter = 0.005
98
106
  @scatter_time = 50.0
99
107
  @scatter_i = 0.0
100
- @perch = 1.0 # Lower this number to divebomb.
108
+ @perchance = 1.0 # Lower this number to divebomb.
101
109
  @perch_y = h
102
110
  @perch_tm = -> { 25.0 + rand(50.0) }
103
111
  @has_goal = false
@@ -118,11 +126,11 @@ class Boids
118
126
  def perch(ground = nil, chance = 1.0, frames = nil)
119
127
  @perch_tm = frames.nil? ? -> { 25.0 + rand(50.0) } : frames
120
128
  @perch_y = ground.nil? ? @h : ground
121
- @perch = chance
129
+ @perchance = chance
122
130
  end
123
131
 
124
132
  def no_perch
125
- @perch = 0.0
133
+ @perchance = 0.0
126
134
  end
127
135
 
128
136
  def goal(target:, flee: false)
@@ -138,7 +146,8 @@ class Boids
138
146
 
139
147
  def constrain
140
148
  # Put them boids in a cage.
141
- dx, dy = @w * 0.1, @h * 0.1
149
+ dx = @w * 0.1
150
+ dy = @h * 0.1
142
151
  each do |b|
143
152
  b.vel.x += rand(dx) if b.pos.x < @x - dx
144
153
  b.vel.x += rand(dy) if b.pos.y < @y - dy
@@ -146,9 +155,10 @@ class Boids
146
155
  b.vel.y -= rand(dy) if b.pos.y > @y + @h + dy
147
156
  b.vel.z += 10.0 if b.pos.z < 0.0
148
157
  b.vel.z -= 10.0 if b.pos.z > 100.0
149
- next unless b.pos.y > perch_y && rand < perch
158
+ next unless b.pos.y > perch_y && rand < perchance
159
+
150
160
  b.pos.y = perch_y
151
- b.vel.y = -(b.vel.y.abs) * 0.2
161
+ b.vel.y = -b.vel.y.abs * 0.2
152
162
  b.is_perching = true
153
163
  b.perch_time = perch_tm.respond_to?(:call) ? perch_tm.call : perch_tm
154
164
  end
@@ -166,7 +176,7 @@ class Boids
166
176
  m2 = 1.0 # separation
167
177
  m3 = 1.0 # alignment
168
178
  m4 = 1.0 # goal
169
- @scattered = true if !(@scattered) && rand < @scatter
179
+ @scattered = true if !@scattered && rand < @scatter
170
180
  if @scattered
171
181
  m1 = -m1
172
182
  m3 *= 0.25