jruby_art 2.2.2 → 2.3.0

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.
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: false
2
+
2
3
  # The processing wrapper module
3
4
  module Processing
4
5
  require_relative 'library'
@@ -19,7 +20,7 @@ module Processing
19
20
  # Load a list of Ruby or Java libraries (in that order)
20
21
  # Usage: load_libraries :video, :video_event
21
22
  #
22
- # If a library is put into a 'library' folder next to the sketch it will be used
23
+ # If a library is put into a 'library' folder next to the sketch it will be used
23
24
  # instead of the library that ships with vanilla processing (or ide installed), or JRubyArt.
24
25
  def load_libraries(*args)
25
26
  message = 'no such file to load -- %s'
@@ -32,10 +33,12 @@ module Processing
32
33
 
33
34
  def loader(name)
34
35
  return true if @loaded_libraries.include?(name)
36
+
35
37
  fname = name.to_s
36
38
  library = Library.new(fname)
37
39
  library.locate
38
40
  return require_library(library, name) if library.ruby?
41
+
39
42
  warn("Not found library: #{fname}") unless library.exist?
40
43
  load_jars(library, name)
41
44
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rbconfig'
2
4
 
3
5
  # Utility to load native binaries on Java CLASSPATH
@@ -5,10 +7,9 @@ require 'rbconfig'
5
7
  class NativeFolder
6
8
  attr_reader :os, :bit
7
9
 
8
- LINUX_FORMAT = 'linux%s'.freeze
9
- ARM32 = '-armv6hf'.freeze
10
- # ARM64 = '-aarch64'.freeze
11
- WIN_FORMAT = 'windows%d'.freeze
10
+ LINUX_FORMAT = 'linux%<bit>d'
11
+ # ARM64 = '-aarch64'
12
+ WIN_FORMAT = 'windows%<bit>d'
12
13
  WIN_PATTERNS = [
13
14
  /bccwin/i,
14
15
  /cygwin/i,
@@ -20,25 +21,26 @@ class NativeFolder
20
21
 
21
22
  def initialize
22
23
  @os = RbConfig::CONFIG['host_os'].downcase
23
- @bit = java.lang.System.get_property('os.arch')
24
+ @bit = /64/.match?(java.lang.System.get_property('os.arch')) ? 64 : 32
24
25
  end
25
26
 
26
27
  def name
27
28
  return 'macosx' if /darwin|mac/.match?(os)
28
- if /linux/.match?(os)
29
- return format(LINUX_FORMAT, '64') if /amd64/.match?(bit)
30
- return format(LINUX_FORMAT, ARM32) if /arm/.match?(bit)
31
- end
32
- if WIN_PATTERNS.any? { |pat| pat =~ os }
33
- return format(WIN_FORMAT, '64') if /64/.match?(bit)
34
- return format(WIN_FORMAT, '32') if /32/.match?(bit)
29
+
30
+ return format(LINUX_FORMAT, bit: bit) if /linux/.match?(os)
31
+
32
+ unless WIN_PATTERNS.any? { |pat| pat.match?(os) }
33
+ raise StandardError, 'Unsupported Architecture'
35
34
  end
36
- raise 'Unsupported Architecture'
35
+
36
+ format(WIN_FORMAT, bit: bit)
37
37
  end
38
38
 
39
39
  def extension
40
40
  return '*.so' if /linux/.match?(os)
41
- return '*.dll' if WIN_PATTERNS.any? { |pat| pat =~ os }
41
+
42
+ return '*.dll' if WIN_PATTERNS.any? { |pat| pat.match?(os) }
43
+
42
44
  '*.dylib' # MacOS
43
45
  end
44
46
  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
@@ -20,6 +22,7 @@ class NativeLoader
20
22
  field = JC::Class.for_name('java.lang.ClassLoader')
21
23
  .get_declared_field('sys_paths')
22
24
  return unless field
25
+
23
26
  field.accessible = true # some jruby magic
24
27
  field.set(JC::Class.for_name('java.lang.System').get_class_loader, nil)
25
28
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # detects processing preferences.txt, extracts sketchbook_path
2
4
  class ProcessingIde
3
5
  attr_reader :preferences
@@ -12,7 +14,9 @@ class ProcessingIde
12
14
  def sketchbook_path
13
15
  File.open(preferences, 'r') do |file|
14
16
  file.each_line do |line|
15
- return line.tap { |sli| sli.slice!('sketchbook.path.three=') }.chomp if line =~ /sketchbook/
17
+ if /sketchbook/.match?(line)
18
+ return line.tap { |sli| sli.slice!('sketchbook.path.three=') }.chomp
19
+ end
16
20
  end
17
21
  end
18
22
  end
@@ -23,11 +23,11 @@ module Processing
23
23
  /ming/i,
24
24
  /mswin/i,
25
25
  /wince/i
26
- ]
26
+ ].freeze
27
27
 
28
- INSTALL = <<~MSG
29
- <Config|JRuby-Complete|Samples>
30
- or <Sound|Video> library
28
+ INSTALL = <<~MSG.freeze
29
+ <Config|JRuby-Complete|Samples>
30
+ or <Sound|Video> library
31
31
  MSG
32
32
 
33
33
  attr_reader :options, :argc, :filename, :os
@@ -156,11 +156,10 @@ module Processing
156
156
  system "cd #{K9_ROOT}/vendors && rake"
157
157
  Installer.new.install
158
158
  else
159
- warn format('No installer for %s', library)
159
+ warn format('No installer for %<library>s', library: library)
160
160
  end
161
161
  end
162
162
 
163
-
164
163
  def check
165
164
  require_relative '../jruby_art/config'
166
165
  Config.new.check
@@ -201,7 +200,9 @@ module Processing
201
200
 
202
201
  # NB: We really do mean to use 'and' not '&&' for flow control purposes
203
202
  def ensure_exists(filename)
204
- puts("Couldn't find: #{filename}") and exit unless FileTest.exist?(filename)
203
+ return if FileTest.exist?(filename)
204
+
205
+ puts("Couldn't find: #{filename}") and exit
205
206
  end
206
207
 
207
208
  def jruby_complete
@@ -213,7 +214,7 @@ module Processing
213
214
  end
214
215
 
215
216
  def remove_old_config
216
- old_config = File.join("#{ENV['HOME']}", '.jruby_art', 'config.yml')
217
+ old_config = File.join((ENV['HOME']).to_s, '.jruby_art', 'config.yml')
217
218
  puts "Removing #{old_config}"
218
219
  system "rm #{old_config}"
219
220
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  SKETCH_PATH ||= ARGV.shift
3
4
  SKETCH_ROOT ||= File.absolute_path(File.dirname(SKETCH_PATH))
4
5
 
@@ -1,17 +1,20 @@
1
1
  # frozen_string_literal: false
2
+
2
3
  # A pry shell for live coding.
3
4
  # Will start with your sketch.
4
5
  require_relative 'base'
5
6
  Processing.load_and_run_sketch
6
7
 
8
+ # Custom Exception
7
9
  class PryException < StandardError
10
+ MESSAGE = "You need to 'jruby -S gem install pry' for 'live' mode".freeze
11
+
12
+ def initialize(msg = MESSAGE)
13
+ super
14
+ end
8
15
  end
9
16
 
10
- MESSAGE = "You need to 'jruby -S gem install pry' for 'live' mode".freeze
17
+ raise PryException unless Gem::Specification.find_all_by_name('pry').any?
11
18
 
12
- if Gem::Specification.find_all_by_name('pry').any?
13
- require 'pry'
14
- Processing.app.pry
15
- else
16
- raise(PryException.new, MESSAGE)
17
- end
19
+ require 'pry'
20
+ Processing.app.pry
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require_relative 'base'
3
4
 
4
5
  Processing.load_and_run_sketch
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: false
2
+
2
3
  require_relative 'base'
3
4
  require_relative '../config'
4
5
 
@@ -21,9 +22,10 @@ module Processing
21
22
  EOS
22
23
  SLEEP_TIME = 0.2
23
24
  def initialize
24
- count = Dir["**.*rb"].length
25
+ count = Dir['**.*rb'].length
25
26
  max_watch = RP_CONFIG.fetch('MAX_WATCH', 20)
26
- return warn format(WATCH_MESSAGE, max_watch, count) if count > max_watch.to_i
27
+ abort format(WATCH_MESSAGE, max_watch, count) if count > max_watch.to_i
28
+
27
29
  reload_files_to_watch
28
30
  @time = Time.now
29
31
  start_watching
@@ -36,7 +38,7 @@ module Processing
36
38
  Kernel.loop do
37
39
  if @files.find { |file| FileTest.exist?(file) && File.stat(file).mtime > @time }
38
40
  puts 'reloading sketch...'
39
- Processing.app && Processing.app.close
41
+ Processing.app&.close
40
42
  java.lang.System.gc
41
43
  @time = Time.now
42
44
  start_runner
@@ -66,7 +68,7 @@ module Processing
66
68
  end
67
69
 
68
70
  def start_runner
69
- @runner.kill if @runner && @runner.alive?
71
+ @runner.kill if @runner&.alive?
70
72
  @runner.join
71
73
  @runner = nil
72
74
  start_original
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  # A wrapper for version
3
4
  module JRubyArt
4
- VERSION = '2.2.2'
5
+ VERSION = '2.3.0'
5
6
  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 = Vec3D.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, vel.z.abs].max
56
58
  return if most < max
59
+
57
60
  scale = max / most.to_f
58
61
  @vel *= scale
59
62
  end
@@ -70,13 +73,13 @@ end
70
73
 
71
74
  require 'forwardable'
72
75
 
73
- # The Boids class
76
+ # The Boids class NB: perchance => perch chance
74
77
  class Boids
75
78
  include Enumerable
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,16 +92,20 @@ 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
  z = rand(200.0)
94
98
  self << Boid.new(self, Vec3D.new(x + dx, y + dy, z))
95
99
  end
96
- @x, @y, @w, @h = x, y, w, h
100
+ @x = x
101
+ @y = y
102
+ @w = w
103
+ @h = h
97
104
  @scattered = false
98
105
  @scatter = 0.005
99
106
  @scatter_time = 50.0
100
107
  @scatter_i = 0.0
101
- @perch = 1.0 # Lower this number to divebomb.
108
+ @perchance = 1.0 # Lower this number to divebomb.
102
109
  @perch_y = h
103
110
  @perch_tm = -> { 25.0 + rand(50.0) }
104
111
  @has_goal = false
@@ -119,11 +126,11 @@ class Boids
119
126
  def perch(ground = nil, chance = 1.0, frames = nil)
120
127
  @perch_tm = frames.nil? ? -> { 25.0 + rand(50.0) } : frames
121
128
  @perch_y = ground.nil? ? @h : ground
122
- @perch = chance
129
+ @perchance = chance
123
130
  end
124
131
 
125
132
  def no_perch
126
- @perch = 0.0
133
+ @perchance = 0.0
127
134
  end
128
135
 
129
136
  def reset_goal(target)
@@ -146,7 +153,8 @@ class Boids
146
153
 
147
154
  def constrain
148
155
  # Put them boids in a cage.
149
- dx, dy = @w * 0.1, @h * 0.1
156
+ dx = @w * 0.1
157
+ dy = @h * 0.1
150
158
  each do |b|
151
159
  b.vel.x += rand(dx) if b.pos.x < @x - dx
152
160
  b.vel.y += rand(dy) if b.pos.y < @y - dy
@@ -154,7 +162,8 @@ class Boids
154
162
  b.vel.y -= rand(dy) if b.pos.y > @y + @h + dy
155
163
  b.vel.z += 10.0 if b.pos.z < 0.0
156
164
  b.vel.z -= 10.0 if b.pos.z > 100.0
157
- next unless b.pos.y > perch_y && rand < perch
165
+ next unless b.pos.y > perch_y && rand < perchance
166
+
158
167
  b.pos.y = perch_y
159
168
  b.vel.y = b.vel.y.abs * -0.2
160
169
  b.is_perching = true
@@ -1,18 +1,19 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  # Usage:
3
4
  # load_library :chooser
4
- #
5
+ #
5
6
  # def setup
6
- # java_signature 'void selectInput(String, String)'
7
- # selectInput('Select a file to process:', 'fileSelected')
7
+ # java_signature 'void selectInput(String, String)'
8
+ # selectInput('Select a file to process:', 'fileSelected')
8
9
  # end
9
- #
10
+ #
10
11
  # def fileSelected(selection)
11
- # if selection.nil?
12
- # puts 'Window was closed or the user hit cancel.'
13
- # else
14
- # puts format('User selected %s', selection.get_absolute_path)
15
- # end
12
+ # if selection.nil?
13
+ # puts 'Window was closed or the user hit cancel.'
14
+ # else
15
+ # puts format('User selected %s', selection.get_absolute_path)
16
+ # end
16
17
  # end
17
18
  class Processing::App
18
19
  include Java::MonkstoneFilechooser::Chooser
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  java_import Java::Monkstone::ColorUtil
2
4
 
3
5
  # class wraps a java color array, supports shuffle!, last and ruby_string
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Here's a little library for quickly hooking up controls to sketches.
2
4
  # For messing with the parameters and such.
3
5
  # These controls will set instance variables on the sketches.
@@ -25,7 +27,7 @@ module ControlPanel
25
27
  add_change_listener do
26
28
  update_label(label, name, value)
27
29
  ControlPanel.app_value(name, value)
28
- proc.call(value) if proc
30
+ proc&.call(value)
29
31
  end
30
32
  ControlPanel.app_value(name, val)
31
33
  end
@@ -49,7 +51,7 @@ module ControlPanel
49
51
  control_panel.add_element(self, name)
50
52
  add_action_listener do
51
53
  ControlPanel.app_value(name, value) unless value.nil?
52
- proc.call(value) if proc
54
+ proc&.call(value)
53
55
  end
54
56
  set_selected_index(initial_value ? elements.index(initial_value) : 0)
55
57
  end
@@ -69,7 +71,7 @@ module ControlPanel
69
71
  control_panel.add_element(self, name, false)
70
72
  add_action_listener do
71
73
  ControlPanel.app_value(name, value)
72
- proc.call(value) if proc
74
+ proc&.call(value)
73
75
  end
74
76
  end
75
77
 
@@ -87,7 +89,7 @@ module ControlPanel
87
89
  control_panel.add_element(self, name, false, true)
88
90
  add_action_listener do
89
91
  Processing.app.send(name)
90
- proc.call(value) if proc
92
+ proc&.call(value)
91
93
  end
92
94
  end
93
95
  end
@@ -160,7 +162,7 @@ module ControlPanel
160
162
  def feel(lf = 'metal')
161
163
  lafinfo = javax.swing.UIManager.getInstalledLookAndFeels
162
164
  laf = lafinfo.to_ary.find do |info|
163
- info.name =~ Regexp.new(Regexp.escape(lf), Regexp::IGNORECASE)
165
+ info.name.match?(Regexp.new(Regexp.escape(lf), Regexp::IGNORECASE))
164
166
  end
165
167
  javax.swing.UIManager.setLookAndFeel(laf.class_name)
166
168
  end
@@ -171,6 +173,7 @@ module ControlPanel
171
173
  def control_panel
172
174
  @control_panel ||= ControlPanel::Panel.new
173
175
  return @control_panel unless block_given?
176
+
174
177
  yield(@control_panel)
175
178
  @control_panel.display
176
179
  @control_panel.set_visible true
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # @TODO usage
2
4
  class Processing::App
3
5
  java_import Java::ProcessingDxf::RawDXF
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  java_import Java::MonkstoneCore::LibraryProxy
2
4
  java_import Java::ProcessingEvent::KeyEvent
3
5
  java_import Java::ProcessingEvent::MouseEvent