jruby_art 2.2.1 → 2.4.2
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/gluegen-rt-natives-linux-amd64.jar +0 -0
- data/lib/gluegen-rt-natives-macosx-universal.jar +0 -0
- data/lib/gluegen-rt-natives-windows-amd64.jar +0 -0
- data/lib/gluegen-rt.jar +0 -0
- data/lib/jogl-all-natives-linux-amd64.jar +0 -0
- data/lib/jogl-all-natives-macosx-universal.jar +0 -0
- data/lib/jogl-all-natives-windows-amd64.jar +0 -0
- data/lib/jogl-all.jar +0 -0
- data/lib/jruby_art-2.4.2.jar +0 -0
- data/lib/jruby_art/app.rb +8 -7
- 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 +10 -9
- 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 +13 -13
- data/lib/jruby_art-2.2.1.jar +0 -0
data/lib/jruby_art/library.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require_relative 'native_folder'
|
2
4
|
require_relative 'native_loader'
|
3
5
|
|
@@ -17,71 +19,69 @@ class Library
|
|
17
19
|
def locate
|
18
20
|
return if (@path = Pathname.new(
|
19
21
|
File.join(SKETCH_ROOT, 'library', name, "#{name}.rb")
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
Dir.glob("#{dir}/*.jar").each do |jar|
|
68
|
-
require jar
|
69
|
-
end
|
70
|
-
return unless native_binaries?
|
71
|
-
|
72
|
-
add_binaries_to_classpath
|
73
|
-
end
|
74
|
-
|
75
|
-
def native_binaries?
|
76
|
-
native_folder = NativeFolder.new
|
77
|
-
native = native_folder.name
|
78
|
-
@ppath = File.join(dir, native)
|
79
|
-
File.directory?(ppath) &&
|
80
|
-
!Dir.glob(File.join(ppath, native_folder.extension)).empty?
|
81
|
-
end
|
82
|
-
|
83
|
-
def add_binaries_to_classpath
|
84
|
-
native_loader = NativeLoader.new
|
85
|
-
native_loader.add_native_path(ppath)
|
86
|
-
end
|
22
|
+
)).exist?
|
23
|
+
return if (@path = Pathname.new(
|
24
|
+
File.join(K9_ROOT, 'library', name, "#{name}.rb")
|
25
|
+
)).exist?
|
26
|
+
|
27
|
+
locate_java
|
28
|
+
end
|
29
|
+
|
30
|
+
def locate_java
|
31
|
+
@dir = Pathname.new(
|
32
|
+
File.join(SKETCH_ROOT, 'library', name)
|
33
|
+
)
|
34
|
+
return @path = dir.join(Pathname.new("#{name}.jar")) if dir.directory?
|
35
|
+
|
36
|
+
locate_installed_java
|
37
|
+
end
|
38
|
+
|
39
|
+
def locate_installed_java
|
40
|
+
return if dir.directory?
|
41
|
+
|
42
|
+
if Processing::RP_CONFIG.fetch('processing_ide', false)
|
43
|
+
prefix = library_path
|
44
|
+
@dir = Pathname.new(File.join(prefix, 'libraries', name, 'library'))
|
45
|
+
@path = dir.join(Pathname.new("#{name}.jar"))
|
46
|
+
else
|
47
|
+
@dir = Pathname.new(
|
48
|
+
File.join(ENV['HOME'], '.jruby_art', 'libraries', name, 'library')
|
49
|
+
)
|
50
|
+
end
|
51
|
+
@path = dir.join(Pathname.new("#{name}.jar"))
|
52
|
+
end
|
53
|
+
|
54
|
+
def library_path
|
55
|
+
Processing::RP_CONFIG.fetch('library_path', "#{ENV['HOME']}/.jruby_art")
|
56
|
+
end
|
57
|
+
|
58
|
+
def ruby?
|
59
|
+
path.extname == '.rb'
|
60
|
+
end
|
61
|
+
|
62
|
+
def exist?
|
63
|
+
path.exist?
|
64
|
+
end
|
65
|
+
|
66
|
+
def load_jars
|
67
|
+
Dir.glob("#{dir}/*.jar").sort.each do |jar|
|
68
|
+
require jar
|
87
69
|
end
|
70
|
+
return unless native_binaries?
|
71
|
+
|
72
|
+
add_binaries_to_classpath
|
73
|
+
end
|
74
|
+
|
75
|
+
def native_binaries?
|
76
|
+
native_folder = NativeFolder.new
|
77
|
+
native = native_folder.name
|
78
|
+
@ppath = File.join(dir, native)
|
79
|
+
File.directory?(ppath) &&
|
80
|
+
!Dir.glob(File.join(ppath, native_folder.extension)).empty?
|
81
|
+
end
|
82
|
+
|
83
|
+
def add_binaries_to_classpath
|
84
|
+
native_loader = NativeLoader.new
|
85
|
+
native_loader.add_native_path(ppath)
|
86
|
+
end
|
87
|
+
end
|
@@ -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(WINDOWS_FORMAT, '64') if /64/.match?(bit)
|
34
|
-
return format(WINDOWS_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
|
@@ -145,7 +145,7 @@ module Processing
|
|
145
145
|
when /sound|video/
|
146
146
|
system "cd #{K9_ROOT}/vendors && rake download_and_copy_#{choice}"
|
147
147
|
when /samples/
|
148
|
-
system "cd #{K9_ROOT}/vendors && rake
|
148
|
+
system "cd #{K9_ROOT}/vendors && rake install_samples"
|
149
149
|
when /jruby/
|
150
150
|
system "cd #{K9_ROOT}/vendors && rake"
|
151
151
|
when /config/
|
@@ -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
|