picrate 1.3.0-java → 2.0.0.pre-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (81) hide show
  1. checksums.yaml +4 -4
  2. data/.mvn/extensions.xml +1 -1
  3. data/.mvn/wrapper/maven-wrapper.properties +2 -2
  4. data/CHANGELOG.md +2 -1
  5. data/Gemfile +3 -1
  6. data/README.md +4 -2
  7. data/Rakefile +8 -4
  8. data/bin/picrate +3 -1
  9. data/docs/_posts/2019-11-11-getting_started_buster.md +1 -1
  10. data/lib/picrate.rb +1 -1
  11. data/lib/picrate/app.rb +10 -3
  12. data/lib/picrate/creators/parameters.rb +8 -8
  13. data/lib/picrate/creators/sketch_factory.rb +5 -3
  14. data/lib/picrate/helper_methods.rb +21 -21
  15. data/lib/picrate/helpers/numeric.rb +2 -0
  16. data/lib/picrate/library.rb +5 -1
  17. data/lib/picrate/library_loader.rb +2 -0
  18. data/lib/picrate/native_folder.rb +6 -4
  19. data/lib/picrate/native_loader.rb +3 -0
  20. data/lib/picrate/runner.rb +1 -0
  21. data/lib/picrate/version.rb +1 -1
  22. data/library/boids/boids.rb +17 -8
  23. data/library/chooser/chooser.rb +10 -9
  24. data/library/color_group/color_group.rb +2 -0
  25. data/library/control_panel/control_panel.rb +7 -4
  26. data/library/dxf/dxf.rb +2 -0
  27. data/library/library_proxy/library_proxy.rb +2 -0
  28. data/library/net/net.rb +2 -0
  29. data/library/slider/slider.rb +24 -23
  30. data/library/vector_utils/vector_utils.rb +4 -0
  31. data/library/video_event/video_event.rb +2 -0
  32. data/picrate.gemspec +14 -12
  33. data/pom.rb +15 -15
  34. data/pom.xml +5 -5
  35. data/src/main/java/monkstone/ColorUtil.java +1 -1
  36. data/src/main/java/monkstone/MathToolModule.java +1 -1
  37. data/src/main/java/monkstone/PicrateLibrary.java +8 -8
  38. data/src/main/java/monkstone/fastmath/Deglut.java +16 -16
  39. data/src/main/java/monkstone/filechooser/Chooser.java +1 -1
  40. data/src/main/java/monkstone/noise/SimplexNoise.java +3 -3
  41. data/src/main/java/monkstone/slider/CustomHorizontalSlider.java +1 -1
  42. data/src/main/java/monkstone/slider/CustomVerticalSlider.java +1 -1
  43. data/src/main/java/monkstone/slider/SimpleHorizontalSlider.java +12 -12
  44. data/src/main/java/monkstone/slider/SimpleVerticalSlider.java +1 -1
  45. data/src/main/java/monkstone/slider/SliderBar.java +1 -1
  46. data/src/main/java/monkstone/slider/SliderGroup.java +1 -1
  47. data/src/main/java/monkstone/slider/WheelHandler.java +1 -1
  48. data/src/main/java/monkstone/vecmath/package-info.java +1 -1
  49. data/src/main/java/monkstone/vecmath/vec2/Vec2.java +1 -1
  50. data/src/main/java/monkstone/vecmath/vec3/Vec3.java +1 -1
  51. data/src/main/java/monkstone/videoevent/CaptureEvent.java +1 -1
  52. data/src/main/java/monkstone/videoevent/MovieEvent.java +1 -1
  53. data/src/main/java/monkstone/videoevent/package-info.java +1 -1
  54. data/src/main/java/processing/awt/PGraphicsJava2D.java +11 -13
  55. data/src/main/java/processing/awt/PSurfaceAWT.java +0 -20
  56. data/src/main/java/processing/core/PApplet.java +1949 -2247
  57. data/src/main/java/processing/core/PConstants.java +180 -180
  58. data/src/main/java/processing/core/PFont.java +2 -2
  59. data/src/main/java/processing/core/PGraphics.java +90 -90
  60. data/src/main/java/processing/core/PImage.java +65 -65
  61. data/src/main/java/processing/core/PMatrix.java +39 -39
  62. data/src/main/java/processing/core/PSurface.java +37 -37
  63. data/src/main/java/processing/core/PVector.java +2 -2
  64. data/src/main/java/processing/data/FloatDict.java +251 -284
  65. data/src/main/java/processing/data/TableRow.java +32 -32
  66. data/src/main/java/processing/dxf/RawDXF.java +3 -3
  67. data/src/main/java/processing/net/Client.java +1 -1
  68. data/src/main/java/processing/opengl/PGL.java +3884 -3950
  69. data/src/main/java/processing/opengl/PGraphicsOpenGL.java +38 -21
  70. data/src/main/java/processing/opengl/PSurfaceJOGL.java +42 -61
  71. data/test/color_group_test.rb +4 -4
  72. data/test/deglut_spec_test.rb +2 -0
  73. data/test/helper_methods_test.rb +41 -13
  74. data/test/math_tool_test.rb +46 -37
  75. data/test/respond_to_test.rb +5 -3
  76. data/test/sketches/key_event.rb +2 -2
  77. data/test/sketches/library/my_library/my_library.rb +3 -0
  78. data/test/test_helper.rb +2 -0
  79. data/test/vecmath_spec_test.rb +30 -19
  80. data/vendors/Rakefile +2 -2
  81. metadata +29 -17
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 674b5526a2444390b3230e1d751b737c6dd45b9d411956a1f2911f8c79c0bf18
4
- data.tar.gz: 178aee951ab71107cb59981a6e2edea6952a80067dccb1431879edff8eb7aa32
3
+ metadata.gz: 6bd1310336366a9a78bccd5489b2ea6e261e9259c38aff780118310645b89e23
4
+ data.tar.gz: 4931647144b1e80b289ffb2e6712ad58ea272f5537b557ca24ade8ecdf6d513b
5
5
  SHA512:
6
- metadata.gz: 3f78af9e8a537e7a28f0e4cd31d44457566eecfee63ad97434c6e33dd70e7b29baa824c628e0f72ba50d3f0ffc77827c70923a443417cdfc5d46b1ecc76012b5
7
- data.tar.gz: 0aae76990d4ef5a801d20f22fc177de3f4319e16e45ce426adf1bfaf6d6eb57e20287c7558fbeb2221fe8b1d3ddcb0cb11f8a60a7e535236e78d52df95a7c612
6
+ metadata.gz: 416492b1f440ed69fcfb8e655a2e8fdac18a9e37510f2edbe446017b065316b83cccc2673d61030d2046869d34d9326e9e8c174cedc8f93b82e612ceafd59aa8
7
+ data.tar.gz: 1338e25d304f32f43e06d3ce73c9c64c23d2bc4a98c4913b18685c513442511e18f38beee0daf4cad1cd21ddbb58247e30e2da2f2ab8b131c6c5048b1eaf9d7c
@@ -3,7 +3,7 @@
3
3
  <extension>
4
4
  <groupId>io.takari.polyglot</groupId>
5
5
  <artifactId>polyglot-ruby</artifactId>
6
- <version>0.4.5
6
+ <version>0.4.3
7
7
  </version>
8
8
  </extension>
9
9
  </extensions>
@@ -1,2 +1,2 @@
1
- distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip
2
- wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar
1
+ distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.1/apache-maven-3.6.1-bin.zip
2
+ wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.5/maven-wrapper-0.5.5.jar
@@ -1,6 +1,7 @@
1
- v1.3.0 Last version for jdk8. But should run OK jdk11 with JRuby-9.2.11.0 and with included jogl-2.4.0-rc.
1
+ v2.0.0 Use JDK11+ update to processing-3.5.4 suggest jruby-9.2.11.0
2
2
 
3
3
  v1.2.4 Extract picrate examples to ~/projects/examples instead of ~/picrate_samples for tighter integration with geany editor. Remove non-functioning sound library as an install option (direct toward minim as option).
4
+
4
5
  v1.2.3 Favor latest beta Video2 library over GLVideo.
5
6
 
6
7
  v1.2.2 Removed landscape from example as too taxing for raspberryPI. Improved geany tools.
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
- ruby '2.5.7', :engine => 'jruby', :engine_version => '9.2.11.0'
4
+ ruby '2.5.7', engine: 'jruby', engine_version: '9.2.11.0'
3
5
  gemspec
data/README.md CHANGED
@@ -1,7 +1,8 @@
1
1
  __C6H3N3O7__ [![Gem Version](https://badge.fury.io/rb/picrate.svg)](https://badge.fury.io/rb/picrate)![Travis CI](https://travis-ci.org/ruby-processing/PiCrate.svg)
2
2
 
3
3
  # PiCrate
4
- Version for RaspberryPI `Stretch` and `Oracle JDK8`, will probably also work on `OpenJDK11+`. For latest version see auto-install script for [PiCrate-2.0][buster] on Buster (tested on RaspberryPI4). Create processing sketches in ruby on raspberry-pi and linux (this project is a parallel development of [propane][propane] targetting the raspberry-pi, but will initially be developed on a regular linux box). The aim is to produce a gem installable app that can be run with jruby, with minimal dependencies. Drop the `C` and you get pirate, or and an `e` and get `PiCreate`, a happy coincidence?
4
+ New version for `Buster` on raspberryPI 3B+ assumes self installed jdk11 or greater.
5
+ Create processing sketches in ruby on raspberry-pi and linux (this project is a parallel development of [propane][propane] targetting the raspberry-pi, but will initially be developed on a regular linux box). The aim is to produce a gem installable app that can be run with jruby, with minimal dependencies. Drop the `C` and you get pirate, or and an `e` and get `PiCreate`, a happy coincidence?
5
6
 
6
7
  ### To install from rubygems ###
7
8
 
@@ -54,5 +55,6 @@ MySketch.new
54
55
  jruby --dev my_sketch.rb # --dev flag speeds start-up
55
56
  ```
56
57
 
57
- [buster]:https://gist.github.com/monkstone/6ae9840d7b7008c177b4a9f589d14ec6
58
+
58
59
  [propane]:https://ruby-processing.github.io/propane/
60
+ [oracle]:http://www.rpiblog.com/2014/03/installing-oracle-jdk-8-on-raspberry-pi.html
data/Rakefile CHANGED
@@ -9,11 +9,15 @@ task default: %i[init compile install test gem]
9
9
  # depends on installed processing, with processing on path
10
10
  desc 'Copy Jars'
11
11
  task :init do
12
- jogl24 = File.join(HOME_DIR, 'jogl24')
13
- opengl = Dir.entries(jogl24).grep(/amd64|armv6hf/).select { |jar| jar =~ /linux/ }
12
+ # for Archlinux etc
13
+ # processing_root = File.dirname(`readlink -f $(which processing)`)
14
+ # alternative for debian linux etc
15
+ processing_root = File.join(HOME_DIR, 'processing-3.5.4')
16
+ jar_dir = File.join(processing_root, 'core', 'library')
17
+ opengl = Dir.entries(jar_dir).grep(/amd64|armv6hf/).select { |jar| jar =~ /linux/ }
14
18
  opengl.concat %w[jogl-all.jar gluegen-rt.jar]
15
19
  opengl.each do |gl|
16
- FileUtils.cp(File.join(jogl24, gl), File.join('.', 'lib'))
20
+ FileUtils.cp(File.join(jar_dir, gl), File.join('.', 'lib'))
17
21
  end
18
22
  end
19
23
 
@@ -24,7 +28,7 @@ end
24
28
 
25
29
  desc 'Gem'
26
30
  task :gem do
27
- system 'gem build picrate.gemspec'
31
+ system 'jruby -S gem build picrate.gemspec'
28
32
  end
29
33
 
30
34
  desc 'Document'
@@ -1,6 +1,8 @@
1
1
  #!/usr/bin/env jruby
2
+ # frozen_string_literal: true
3
+
2
4
  unless defined? PICRATE_ROOT
3
- $LOAD_PATH << File.expand_path(File.dirname(__FILE__))
5
+ $LOAD_PATH << __dir__
4
6
  PICRATE_ROOT = File.expand_path(File.dirname(__FILE__) + '/../')
5
7
  end
6
8
 
@@ -59,7 +59,7 @@ picrate --install # no args, install samples and geany config
59
59
  picrate -i Samples # to omit geany config
60
60
  ```
61
61
 
62
- This installs example sketches in `~/projects/examples` and ties them into a `geany` project `examples.geany`. It should also be possible to run sketches from the `geany` ide.
62
+ This installs example sketches in `~/sample_sketches` and ties them into a `geany` project `picrate.geany`. It should also be possible to run sketches from the `geany` ide.
63
63
 
64
64
  To create a template sketch from the command line:-
65
65
 
@@ -6,7 +6,7 @@ unless defined? PICRATE_ROOT
6
6
  PICRATE_ROOT = File.dirname(__dir__)
7
7
  end
8
8
 
9
- Dir["#{PICRATE_ROOT}/lib/*.jar"].each do |jar|
9
+ Dir["#{PICRATE_ROOT}/lib/*.jar"].sort.each do |jar|
10
10
  require jar
11
11
  end
12
12
  require_relative 'picrate/app'
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: false
2
+
2
3
  require_relative 'helper_methods'
3
4
  require_relative 'library_loader'
4
5
  # A wrapper module for the processing App
@@ -49,7 +50,10 @@ module Processing
49
50
 
50
51
  # All sketches extend this class
51
52
  class App < PApplet
52
- include Math, MathTool, HelperMethods, Render
53
+ include Render
54
+ include HelperMethods
55
+ include MathTool
56
+ include Math
53
57
  # Alias some methods for familiarity for Shoes coders.
54
58
  alias oval ellipse
55
59
  alias stroke_width stroke_weight
@@ -101,6 +105,7 @@ module Processing
101
105
  # Processing call them by their expected Java names.
102
106
  def method_added(method_name) #:nodoc:
103
107
  return unless METHODS_TO_ALIAS.key?(method_name)
108
+
104
109
  alias_method METHODS_TO_ALIAS[method_name], method_name
105
110
  end
106
111
  end
@@ -113,6 +118,7 @@ module Processing
113
118
  # Guard against invalid input.
114
119
  proxy_java_fields
115
120
  raise TypeError unless options.is_a?(Hash) && arguments.is_a?(Array)
121
+
116
122
  # Set up the sketch.
117
123
  super()
118
124
  post_initialize(options)
@@ -132,8 +138,7 @@ module Processing
132
138
  super(*args)
133
139
  end
134
140
 
135
- def post_initialize(_args)
136
- end
141
+ def post_initialize(_args); end
137
142
 
138
143
  def data_path(dat)
139
144
  dat_root = File.join(SKETCH_ROOT, 'data')
@@ -162,6 +167,7 @@ module Processing
162
167
  # Processing call them by their expected Java names.
163
168
  def method_added(method_name) #:nodoc:
164
169
  return unless METHODS_TO_ALIAS.key?(method_name)
170
+
165
171
  alias_method METHODS_TO_ALIAS[method_name], method_name
166
172
  end
167
173
  end
@@ -179,6 +185,7 @@ module Processing
179
185
 
180
186
  def method_missing(name, *args, &block)
181
187
  return Processing.app.send(name, *args) if Processing.app.respond_to? name
188
+
182
189
  super
183
190
  end
184
191
  end # Processing::Proxy
@@ -11,13 +11,13 @@ module Parameters
11
11
  PARAM = { 'sketch' =>
12
12
  { 'width' => 640, 'height' => 480, 'mode' => 'P2D' } }.freeze
13
13
 
14
- def self.write
15
- FileUtils.mkdir_p PATH
16
- File.write(FILE, PARAM.to_yaml)
17
- end
14
+ def self.write
15
+ FileUtils.mkdir_p PATH
16
+ File.write(FILE, PARAM.to_yaml)
17
+ end
18
18
 
19
- def self.read
20
- write unless File.exist?(FILE)
21
- YAML.load_file(FILE)
22
- end
19
+ def self.read
20
+ write unless File.exist?(FILE)
21
+ YAML.load_file(FILE)
23
22
  end
23
+ end
@@ -1,8 +1,10 @@
1
- require_relative 'sketch_writer'
1
+ # frozen_string_literal: true
2
2
 
3
+ require_relative 'sketch_writer'
4
+ # Sketch Factory
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')).write
8
10
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: false
2
+
2
3
  # processing module wrapper
3
4
  require_relative 'helpers/numeric'
4
5
  module Processing
@@ -52,6 +53,7 @@ module Processing
52
53
 
53
54
  def color(*args)
54
55
  return super(*args) unless args.length == 1
56
+
55
57
  super(hex_color(args[0]))
56
58
  end
57
59
 
@@ -66,11 +68,8 @@ module Processing
66
68
  # Overrides Processing convenience function thread, which takes a String
67
69
  # arg (for a function) to more rubylike version, takes a block...
68
70
  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
71
+ warn 'you must provide a block' unless block_given?
72
+ Java::JavaLang::Thread.new(&block).start
74
73
  end
75
74
 
76
75
  # explicitly provide 'processing.org' min instance method
@@ -94,9 +93,9 @@ module Processing
94
93
  def dist(*args)
95
94
  case args.length
96
95
  when 4
97
- return dist2d(*args)
96
+ dist2d(*args)
98
97
  when 6
99
- return dist3d(*args)
98
+ dist3d(*args)
100
99
  else
101
100
  raise ArgumentError, 'takes 4 or 6 parameters'
102
101
  end
@@ -111,13 +110,13 @@ module Processing
111
110
  # Here's a convenient way to look for them.
112
111
  def find_method(method_name)
113
112
  reg = Regexp.new(method_name.to_s, true)
114
- methods.sort.select { |meth| reg.match(meth) }
113
+ methods.sort.select { |meth| reg.match?(meth) }
115
114
  end
116
115
 
117
116
  # Proxy over a list of Java declared fields that have the same name as
118
117
  # some methods. Add to this list as needed.
119
118
  def proxy_java_fields
120
- fields = %w(key frameRate mousePressed keyPressed)
119
+ fields = %w[key frameRate mousePressed keyPressed]
121
120
  methods = fields.map { |field| java_class.declared_field(field) }
122
121
  @declared_fields = Hash[fields.zip(methods)]
123
122
  end
@@ -163,6 +162,7 @@ module Processing
163
162
  # frame_rate needs to support reading and writing
164
163
  def frame_rate(fps = nil)
165
164
  return @declared_fields['frameRate'].value(java_self) unless fps
165
+
166
166
  super(fps)
167
167
  end
168
168
 
@@ -178,19 +178,17 @@ module Processing
178
178
 
179
179
  private
180
180
 
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
181
  # 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)
182
+ def hex_color(arg)
183
+ case arg
184
+ when Integer
185
+ Java::Monkstone::ColorUtil.colorLong(arg)
186
+ when String
187
+ raise StandardError, 'Dodgy Hexstring' unless arg.match(/#\h{6}$/)
188
+
189
+ Java::Monkstone::ColorUtil.colorString(arg)
190
+ when Float
191
+ Java::Monkstone::ColorUtil.colorDouble(arg)
194
192
  else
195
193
  raise StandardError, 'Dodgy Color Conversion'
196
194
  end
@@ -200,6 +198,7 @@ module Processing
200
198
  dx = args[0] - args[2]
201
199
  dy = args[1] - args[3]
202
200
  return 0 if dx.abs < EPSILON && dy.abs < EPSILON
201
+
203
202
  Math.hypot(dx, dy)
204
203
  end
205
204
 
@@ -208,6 +207,7 @@ module Processing
208
207
  dy = args[1] - args[4]
209
208
  dz = args[2] - args[5]
210
209
  return 0 if dx.abs < EPSILON && dy.abs < EPSILON && dz.abs < EPSILON
210
+
211
211
  Math.sqrt(dx * dx + dy * dy + dz * dz)
212
212
  end
213
213
  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,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(PICRATE_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 Processing
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,12 +1,14 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rbconfig'
2
4
 
3
5
  # Utility to load native binaries on Java CLASSPATH
4
- #HACK until jruby returns a more specific 'host_os' than 'linux'
6
+ # HACK until jruby returns a more specific 'host_os' than 'linux'
5
7
  class NativeFolder
6
8
  attr_reader :os, :bit
7
9
 
8
- LINUX_FORMAT = 'linux%s'.freeze
9
- ARM32 = '-armv6hf'.freeze
10
+ LINUX_FORMAT = 'linux%s'
11
+ ARM32 = '-armv6hf'
10
12
  # ARM64 = '-aarch64'.freeze
11
13
 
12
14
  def initialize
@@ -19,7 +21,7 @@ class NativeFolder
19
21
  return format(LINUX_FORMAT, '64') if /amd64/.match?(bit)
20
22
  return format(LINUX_FORMAT, ARM32) if /arm/.match?(bit)
21
23
  end
22
- raise RuntimeError, "Unsupported Architecture"
24
+ raise 'Unsupported Architecture'
23
25
  end
24
26
 
25
27
  def extension
@@ -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
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PiCrate
4
- VERSION = '1.3.0'
4
+ VERSION = '2.0.0.pre'
5
5
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  # Boids -- after Tom de Smedt.
3
4
  # See his Python version: http://nodebox.net/code/index.php/Boids
4
5
  # This is an example of how a pure-Ruby library can work. Original for
@@ -8,7 +9,8 @@ class Boid
8
9
  attr_reader :boids
9
10
  attr_accessor :vel, :pos, :is_perching, :perch_time
10
11
  def initialize(boids, pos)
11
- @boids, @flock = boids, boids
12
+ @boids = boids
13
+ @flock = boids
12
14
  @pos = pos
13
15
  @vel = Vec2D.new
14
16
  @is_perching = false
@@ -54,6 +56,7 @@ class Boid
54
56
  # Tweet, Tweet! The boid police will bust you for breaking the speed limit.
55
57
  most = [vel.x.abs, vel.y.abs].max
56
58
  return if most < max
59
+
57
60
  scale = max / most.to_f
58
61
  @vel *= scale
59
62
  end
@@ -76,7 +79,7 @@ class Boids
76
79
  extend Forwardable
77
80
  def_delegators(:@boids, :reject, :<<, :each, :shuffle!, :length, :next)
78
81
 
79
- attr_reader :has_goal, :perch, :perch_tm, :perch_y
82
+ attr_reader :has_goal, :perchance, :perch_tm, :perch_y
80
83
 
81
84
  def initialize
82
85
  @boids = []
@@ -89,15 +92,19 @@ class Boids
89
92
 
90
93
  def setup(n, x, y, w, h)
91
94
  n.times do
92
- dx, dy = rand(w), rand(h)
95
+ dx = rand(w)
96
+ dy = rand(h)
93
97
  self << Boid.new(self, Vec2D.new(x + dx, y + dy))
94
98
  end
95
- @x, @y, @w, @h = x, y, w, h
99
+ @x = x
100
+ @y = y
101
+ @w = w
102
+ @h = h
96
103
  @scattered = false
97
104
  @scatter = 0.005
98
105
  @scatter_time = 50.0
99
106
  @scatter_i = 0.0
100
- @perch = 1.0 # Lower this number to divebomb.
107
+ @perchance = 1.0 # Lower this number to divebomb.
101
108
  @perch_y = h
102
109
  @perch_tm = -> { 25.0 + rand(50.0) }
103
110
  @has_goal = false
@@ -118,11 +125,11 @@ class Boids
118
125
  def perch(ground = nil, chance = 1.0, frames = nil)
119
126
  @perch_tm = frames.nil? ? -> { 25.0 + rand(50.0) } : frames
120
127
  @perch_y = ground.nil? ? @h : ground
121
- @perch = chance
128
+ @perchance = chance
122
129
  end
123
130
 
124
131
  def no_perch
125
- @perch = 0.0
132
+ @perchance= 0.0
126
133
  end
127
134
 
128
135
  def reset_goal(target)
@@ -145,13 +152,15 @@ class Boids
145
152
 
146
153
  def constrain
147
154
  # Put them boids in a cage.
148
- dx, dy = @w * 0.1, @h * 0.1
155
+ dx = @w * 0.1
156
+ dy = @h * 0.1
149
157
  each do |b|
150
158
  b.vel.x += rand(dx) if b.pos.x < @x - dx
151
159
  b.vel.y += rand(dy) if b.pos.y < @y - dy
152
160
  b.vel.x -= rand(dx) if b.pos.x > @x + @w + dx
153
161
  b.vel.y -= rand(dy) if b.pos.y > @y + @h + dy
154
162
  next unless b.pos.y > perch_y && rand < perch
163
+
155
164
  b.pos.y = perch_y
156
165
  b.vel.y = b.vel.y.abs * -0.2
157
166
  b.is_perching = true