jruby_art 2.2.2 → 2.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/k9 +4 -3
- data/lib/jruby_art-2.3.0.jar +0 -0
- data/lib/jruby_art/app.rb +7 -6
- data/lib/jruby_art/config.rb +2 -0
- data/lib/jruby_art/creators/sketch_writer.rb +31 -13
- data/lib/jruby_art/default_config.rb +2 -0
- data/lib/jruby_art/helper_methods.rb +22 -22
- data/lib/jruby_art/helpers/aabb.rb +3 -0
- data/lib/jruby_art/helpers/numeric.rb +1 -0
- data/lib/jruby_art/installer.rb +10 -7
- data/lib/jruby_art/java_opts.rb +2 -0
- data/lib/jruby_art/jruby_complete.rb +2 -0
- data/lib/jruby_art/launcher.rb +8 -3
- data/lib/jruby_art/library.rb +67 -67
- data/lib/jruby_art/library_loader.rb +4 -1
- data/lib/jruby_art/native_folder.rb +16 -14
- data/lib/jruby_art/native_loader.rb +3 -0
- data/lib/jruby_art/processing_ide.rb +5 -1
- data/lib/jruby_art/runner.rb +9 -8
- data/lib/jruby_art/runners/base.rb +1 -0
- data/lib/jruby_art/runners/live.rb +10 -7
- data/lib/jruby_art/runners/run.rb +1 -0
- data/lib/jruby_art/runners/watch.rb +6 -4
- data/lib/jruby_art/version.rb +2 -1
- data/library/boids/boids.rb +19 -10
- data/library/chooser/chooser.rb +10 -9
- data/library/color_group/color_group.rb +2 -0
- data/library/control_panel/control_panel.rb +8 -5
- data/library/dxf/dxf.rb +2 -0
- data/library/library_proxy/library_proxy.rb +2 -0
- data/library/net/net.rb +2 -0
- data/library/slider/slider.rb +24 -23
- data/library/vector_utils/vector_utils.rb +5 -1
- data/library/video_event/video_event.rb +3 -0
- data/vendors/Rakefile +13 -7
- metadata +10 -10
- data/lib/jruby_art-2.2.2.jar +0 -0
@@ -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
|
9
|
-
|
10
|
-
|
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
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
data/lib/jruby_art/runner.rb
CHANGED
@@ -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
|
-
|
30
|
-
|
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
|
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
|
-
|
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(
|
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,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
|
-
|
17
|
+
raise PryException unless Gem::Specification.find_all_by_name('pry').any?
|
11
18
|
|
12
|
-
|
13
|
-
|
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: 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[
|
25
|
+
count = Dir['**.*rb'].length
|
25
26
|
max_watch = RP_CONFIG.fetch('MAX_WATCH', 20)
|
26
|
-
|
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
|
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
|
71
|
+
@runner.kill if @runner&.alive?
|
70
72
|
@runner.join
|
71
73
|
@runner = nil
|
72
74
|
start_original
|
data/lib/jruby_art/version.rb
CHANGED
data/library/boids/boids.rb
CHANGED
@@ -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
|
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, :
|
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
|
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
|
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
|
-
@
|
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
|
-
@
|
129
|
+
@perchance = chance
|
123
130
|
end
|
124
131
|
|
125
132
|
def no_perch
|
126
|
-
@
|
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
|
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 <
|
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
|
data/library/chooser/chooser.rb
CHANGED
@@ -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
|
-
|
7
|
-
|
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
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
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
|
# 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
|
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
|
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
|
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
|
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
|
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
|
data/library/dxf/dxf.rb
CHANGED