jruby_art 0.2.6.pre → 0.3.0.pre
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.
- checksums.yaml +4 -4
- data/bin/k9 +2 -2
- data/lib/jruby_art.rb +18 -23
- data/lib/jruby_art/app.rb +118 -130
- data/lib/jruby_art/config.rb +7 -9
- data/lib/jruby_art/creators/creator.rb +189 -0
- data/lib/jruby_art/helper_methods.rb +41 -31
- data/lib/jruby_art/helpers/camel_string.rb +2 -1
- data/lib/jruby_art/helpers/numeric.rb +1 -2
- data/lib/jruby_art/helpers/range.rb +3 -7
- data/lib/jruby_art/helpers/string_extra.rb +1 -1
- data/lib/jruby_art/library_loader.rb +127 -96
- data/lib/jruby_art/runner.rb +208 -63
- data/lib/jruby_art/runners/base.rb +51 -0
- data/lib/jruby_art/runners/run.rb +6 -0
- data/lib/jruby_art/runners/watch.rb +59 -0
- data/lib/jruby_art/version.rb +1 -2
- data/lib/rpextras.jar +0 -0
- data/library/library_proxy/README.md +97 -0
- data/library/library_proxy/library_proxy.rb +8 -1
- data/library/video_event/video_event.rb +4 -0
- data/vendors/Rakefile +33 -78
- metadata +54 -60
- data/CHANGELOG.md +0 -60
- data/LICENSE.md +0 -39
- data/README.md +0 -91
- data/Rakefile +0 -85
- data/lib/core.jar +0 -0
- data/lib/gluegen-rt-natives-linux-amd64.jar +0 -0
- data/lib/gluegen-rt-natives-linux-armv6hf.jar +0 -0
- data/lib/gluegen-rt-natives-linux-i586.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-natives-windows-i586.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-linux-armv6hf.jar +0 -0
- data/lib/jogl-all-natives-linux-i586.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-natives-windows-i586.jar +0 -0
- data/lib/jogl-all.jar +0 -0
- data/lib/jruby_art/creator.rb +0 -100
- data/lib/jruby_art/parse.rb +0 -59
- data/lib/jruby_art/writer.rb +0 -40
- data/library/file_chooser/file_chooser.rb +0 -82
- data/library/grammar/grammar.rb +0 -31
- data/library/video/lib/export.txt +0 -1
- data/library/video/lib/macosx64.txt +0 -1
- data/library/video/lib/windows.txt +0 -3
- data/library/video/video.rb +0 -12
- data/spec/app_spec.rb +0 -208
- data/spec/deglut_spec.rb +0 -25
- data/spec/library_loader_spec.rb +0 -23
- data/spec/spec_helper.rb +0 -96
- data/spec/vecmath_spec.rb +0 -483
- data/vendors/config.tar.gz +0 -0
@@ -1,5 +1,6 @@
|
|
1
|
+
# processing module wrapper
|
1
2
|
module Processing
|
2
|
-
#
|
3
|
+
# Provides some convenience methods
|
3
4
|
module HelperMethods
|
4
5
|
# processings epsilon may not be defined yet
|
5
6
|
EPSILON ||= 1.0e-04
|
@@ -60,7 +61,7 @@ module Processing
|
|
60
61
|
# function
|
61
62
|
# @param [float] value input
|
62
63
|
# @param [range] start1, stop1
|
63
|
-
# @param [range]
|
64
|
+
# @param [range] start2, stop2
|
64
65
|
# @return [float] mapped value
|
65
66
|
def map(value, start1, stop1, start2, stop2)
|
66
67
|
start2 + (stop2 - start2) * ((value - start1).to_f / (stop1 - start1))
|
@@ -73,6 +74,23 @@ module Processing
|
|
73
74
|
((val - r_in.begin).to_f / (r_in.end - r_in.begin))
|
74
75
|
end
|
75
76
|
|
77
|
+
# Explicitly provides 'processing.org' map instance method, where
|
78
|
+
# value is mapped from range 1 to range 2 where values are clamped to
|
79
|
+
# range 2.
|
80
|
+
# @param val input
|
81
|
+
# @param [r_in] start1, stop1
|
82
|
+
# @param [r_out] start2, stop2
|
83
|
+
# @return mapped value
|
84
|
+
def constrained_map(val, r_in, r_out)
|
85
|
+
unless r_in.include? val
|
86
|
+
return r_out.begin if (val < r_in.begin && r_in.begin < r_in.end) ||
|
87
|
+
(val > r_in.begin && r_in.begin > r_in.end)
|
88
|
+
return r_out.end
|
89
|
+
end
|
90
|
+
r_out.begin + (r_out.end - r_out.begin) *
|
91
|
+
((val - r_in.begin).to_f / (r_in.end - r_in.begin))
|
92
|
+
end
|
93
|
+
|
76
94
|
# explicitly provide 'processing.org' norm instance method
|
77
95
|
def norm(value, start, stop)
|
78
96
|
(value - start).to_f / (stop - start)
|
@@ -101,25 +119,11 @@ module Processing
|
|
101
119
|
def dist(*args)
|
102
120
|
len = args.length
|
103
121
|
if len == 4
|
104
|
-
|
105
|
-
|
106
|
-
return
|
107
|
-
return Math.hypot(dx, dy)
|
108
|
-
end
|
109
|
-
fail ArgumentError, 'takes 4 parameters'
|
110
|
-
end
|
111
|
-
|
112
|
-
# dist_squared only makes sense with 3D distance
|
113
|
-
def dist_squared(*args)
|
114
|
-
len = args.length
|
115
|
-
if len == 6
|
116
|
-
dx = args[0] - args[3]
|
117
|
-
dy = args[1] - args[4]
|
118
|
-
dz = args[2] - args[5]
|
119
|
-
return 0 if dx.abs < EPSILON && dy.abs < EPSILON && dz.abs < EPSILON
|
120
|
-
return dx * dx + dy * dy + dz * dz
|
122
|
+
return dist2d(*args)
|
123
|
+
elsif len == 6
|
124
|
+
return dist3d(*args)
|
121
125
|
end
|
122
|
-
fail ArgumentError, 'takes 6 parameters'
|
126
|
+
fail ArgumentError, 'takes 4 or 6 parameters'
|
123
127
|
end
|
124
128
|
|
125
129
|
# explicitly provide 'processing.org' constrain instance method
|
@@ -148,13 +152,6 @@ module Processing
|
|
148
152
|
@declared_fields = Hash[fields.zip(methods)]
|
149
153
|
end
|
150
154
|
|
151
|
-
# By default, your sketch path is the folder that your sketch is in.
|
152
|
-
# If you'd like to do something fancy, feel free.
|
153
|
-
def set_sketch_path(spath = nil)
|
154
|
-
field = @declared_fields['sketchPath']
|
155
|
-
field.set_value(java_self, spath || SKETCH_ROOT)
|
156
|
-
end
|
157
|
-
|
158
155
|
# Fix java conversion problems getting the last key
|
159
156
|
# If it's ASCII, return the character, otherwise the integer
|
160
157
|
def key
|
@@ -187,10 +184,6 @@ module Processing
|
|
187
184
|
|
188
185
|
define_method(:key_code) { keyCode }
|
189
186
|
|
190
|
-
define_method(:display_height) { displayHeight }
|
191
|
-
|
192
|
-
define_method(:display_width) { displayWidth }
|
193
|
-
|
194
187
|
# Ensure that load_strings returns a real Ruby array
|
195
188
|
def load_strings(file_or_url)
|
196
189
|
loadStrings(file_or_url).to_a
|
@@ -217,5 +210,22 @@ module Processing
|
|
217
210
|
def key_pressed?
|
218
211
|
@declared_fields['keyPressed'].value(java_self)
|
219
212
|
end
|
213
|
+
|
214
|
+
private
|
215
|
+
|
216
|
+
def dist2d(*args)
|
217
|
+
dx = args[0] - args[2]
|
218
|
+
dy = args[1] - args[3]
|
219
|
+
return 0 if dx.abs < EPSILON && dy.abs < EPSILON
|
220
|
+
Math.hypot(dx, dy)
|
221
|
+
end
|
222
|
+
|
223
|
+
def dist3d(*args)
|
224
|
+
dx = args[0] - args[3]
|
225
|
+
dy = args[1] - args[4]
|
226
|
+
dz = args[2] - args[5]
|
227
|
+
return 0 if dx.abs < EPSILON && dy.abs < EPSILON && dz.abs < EPSILON
|
228
|
+
Math.sqrt(dx * dx + dy * dy + dz * dz)
|
229
|
+
end
|
220
230
|
end
|
221
231
|
end
|
@@ -10,7 +10,8 @@ class CamelString
|
|
10
10
|
|
11
11
|
def camelize(first_letter_in_uppercase = true)
|
12
12
|
if first_letter_in_uppercase
|
13
|
-
@string.gsub(
|
13
|
+
@string.gsub(%r{/(.?)}) { '::' + Regexp.last_match[1].upcase }
|
14
|
+
.gsub(/(^|_)(.)/) { Regexp.last_match[2].upcase }
|
14
15
|
else
|
15
16
|
@string[0] + camelize[1..-1]
|
16
17
|
end
|
@@ -1,104 +1,135 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
@installed = File.absolute_path("#{K9_ROOT}/library/")
|
12
|
-
end
|
13
|
-
|
14
|
-
# Load a list of Java libraries or ruby libraries
|
15
|
-
# Usage: load_libraries :boids, :control_panel, :video
|
16
|
-
#
|
17
|
-
# If a library is put into a 'library' folder next to the sketch it will
|
18
|
-
# be used instead of the library that ships with JRubyArt.
|
19
|
-
def load_libraries(*args)
|
20
|
-
args.each do |arg|
|
21
|
-
next if loaded_libraries.include? arg
|
22
|
-
local_ruby_lib(arg)
|
23
|
-
local_java_lib(arg)
|
24
|
-
installed_ruby_lib(arg)
|
25
|
-
installed_java_lib(arg)
|
1
|
+
# Then processing wrapper module
|
2
|
+
module Processing
|
3
|
+
|
4
|
+
# Encapsulate library loader functionality as a class
|
5
|
+
class LibraryLoader
|
6
|
+
attr_reader :sketchbook_library_path
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@sketchbook_library_path = File.join(find_sketchbook_path, 'libraries')
|
10
|
+
@loaded_libraries = Hash.new(false)
|
26
11
|
end
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
end
|
32
|
-
|
33
|
-
def installed_java_lib(arg)
|
34
|
-
java_lib(libraries_path, arg)
|
35
|
-
end
|
36
|
-
|
37
|
-
def installed_ruby_lib(arg)
|
38
|
-
ruby_file = File.join(installed, format('%s/%s.rb', arg, arg))
|
39
|
-
return unless FileTest.exist?(ruby_file)
|
40
|
-
require ruby_file
|
41
|
-
loaded_libraries << arg
|
42
|
-
end
|
43
|
-
|
44
|
-
def local_ruby_lib(arg)
|
45
|
-
ruby_file = File.join(local, format('%s.rb', arg))
|
46
|
-
return unless FileTest.exist? ruby_file
|
47
|
-
require ruby_file
|
48
|
-
loaded_libraries << arg
|
49
|
-
end
|
50
|
-
|
51
|
-
# HACK: For pure java libraries, such as the ones that are available
|
52
|
-
# on this page: http://processing.org/reference/libraries/index.html
|
53
|
-
# that include native code, we mess with the 'Java ClassLoader', so that
|
54
|
-
# you don't have to futz with your PATH. But it's probably bad juju.
|
55
|
-
def java_lib(path, library_name)
|
56
|
-
library_name = library_name.to_sym
|
57
|
-
jars = get_library_paths(path, library_name)
|
58
|
-
jpath = format("%s/%s/library", path, library_name.to_s )
|
59
|
-
return false if jars.empty?
|
60
|
-
jars.each { |jar| require jar }
|
61
|
-
platform_specific_library_paths = get_platform_specific_library_paths(jpath)
|
62
|
-
platform_specific_library_paths = platform_specific_library_paths.select do |ppath|
|
63
|
-
test(?d, ppath) && !Dir.glob(File.join(ppath, '*.{so,dll,jnilib}')).empty?
|
12
|
+
|
13
|
+
# Detect if a library has been loaded (for conditional loading)
|
14
|
+
def library_loaded?(library_name)
|
15
|
+
@loaded_libraries[library_name.to_sym]
|
64
16
|
end
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
17
|
+
|
18
|
+
# Load a list of Ruby or Java libraries (in that order)
|
19
|
+
# Usage: load_libraries :opengl, :boids
|
20
|
+
#
|
21
|
+
# If a library is put into a 'library' folder next to the sketch it will
|
22
|
+
# be used instead of the library that ships with Ruby-Processing.
|
23
|
+
def load_libraries(*args)
|
24
|
+
message = 'no such file to load -- %s'
|
25
|
+
args.each do |lib|
|
26
|
+
loaded = load_ruby_library(lib) || load_java_library(lib)
|
27
|
+
fail(LoadError.new, format(message, lib)) unless loaded
|
73
28
|
end
|
74
29
|
end
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
30
|
+
alias_method :load_library, :load_libraries
|
31
|
+
|
32
|
+
# For pure ruby libraries.
|
33
|
+
# The library should have an initialization ruby file
|
34
|
+
# of the same name as the library folder.
|
35
|
+
def load_ruby_library(library_name)
|
36
|
+
library_name = library_name.to_sym
|
37
|
+
return true if @loaded_libraries.include?(library_name)
|
38
|
+
path = get_library_paths(library_name, 'rb').first
|
39
|
+
return false unless path
|
40
|
+
@loaded_libraries[library_name] = (require path)
|
81
41
|
end
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
42
|
+
|
43
|
+
# HACK: For pure java libraries, such as the ones that are available
|
44
|
+
# on this page: http://processing.org/reference/libraries/index.html
|
45
|
+
# that include native code, we mess with the 'Java ClassLoader', so that
|
46
|
+
# you don't have to futz with your PATH. But it's probably bad juju.
|
47
|
+
def load_java_library(library_name)
|
48
|
+
library_name = library_name.to_sym
|
49
|
+
return true if @loaded_libraries.include?(library_name)
|
50
|
+
jpath = get_library_directory_path(library_name, 'jar')
|
51
|
+
jars = get_library_paths(library_name, 'jar')
|
52
|
+
return false if jars.empty?
|
53
|
+
jars.each { |jar| require jar }
|
54
|
+
platform_specific_library_paths = get_platform_specific_library_paths(jpath)
|
55
|
+
platform_specific_library_paths = platform_specific_library_paths.select do |ppath|
|
56
|
+
FileTest.directory?(ppath) && !Dir.glob(File.join(ppath, '*.{so,dll,jnilib}')).empty?
|
57
|
+
end
|
58
|
+
unless platform_specific_library_paths.empty?
|
59
|
+
platform_specific_library_paths << java.lang.System.getProperty('java.library.path')
|
60
|
+
new_library_path = platform_specific_library_paths.join(java.io.File.pathSeparator)
|
61
|
+
java.lang.System.setProperty('java.library.path', new_library_path)
|
62
|
+
field = java.lang.Class.for_name('java.lang.ClassLoader').get_declared_field('sys_paths')
|
63
|
+
if field
|
64
|
+
field.accessible = true
|
65
|
+
field.set(java.lang.Class.for_name('java.lang.System').get_class_loader, nil)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
@loaded_libraries[library_name] = true
|
69
|
+
end
|
70
|
+
|
71
|
+
def platform
|
72
|
+
match = %w(mac linux windows).find do |os|
|
73
|
+
java.lang.System.getProperty('os.name').downcase.index(os)
|
74
|
+
end
|
75
|
+
return 'other' unless match
|
76
|
+
return match unless match =~ /mac/
|
77
|
+
'macosx'
|
78
|
+
end
|
79
|
+
|
80
|
+
def get_platform_specific_library_paths(basename)
|
81
|
+
bits = 'universal' # for MacOSX, but does this even work, or does Mac return '64'?
|
82
|
+
if java.lang.System.getProperty('sun.arch.data.model') == '32' ||
|
83
|
+
java.lang.System.getProperty('java.vm.name').index('32')
|
84
|
+
bits = '32'
|
85
|
+
elsif java.lang.System.getProperty('sun.arch.data.model') == '64' ||
|
86
|
+
java.lang.System.getProperty('java.vm.name').index('64')
|
87
|
+
bits = '64' unless platform =~ /macosx/
|
88
|
+
end
|
89
|
+
[platform, platform + bits].map { |p| File.join(basename, p) }
|
90
|
+
end
|
91
|
+
|
92
|
+
def get_library_paths(library_name, extension = nil)
|
93
|
+
dir = get_library_directory_path(library_name, extension)
|
94
|
+
Dir.glob("#{dir}/*.{rb,jar}")
|
95
|
+
end
|
96
|
+
|
97
|
+
protected
|
98
|
+
|
99
|
+
def get_library_directory_path(library_name, extension = nil)
|
100
|
+
extensions = extension ? [extension] : %w(jar rb)
|
101
|
+
extensions.each do |ext|
|
102
|
+
["#{SKETCH_ROOT}/library/#{library_name}",
|
103
|
+
"#{Processing::RP_CONFIG['PROCESSING_ROOT']}/modes/java/libraries/#{library_name}/library",
|
104
|
+
"#{RP5_ROOT}/library/#{library_name}/library",
|
105
|
+
"#{RP5_ROOT}/library/#{library_name}",
|
106
|
+
"#{@sketchbook_library_path}/#{library_name}/library"
|
107
|
+
].each do |jpath|
|
108
|
+
if File.exist?(jpath) && !Dir.glob(format('%s/*.%s', jpath, ext)).empty?
|
109
|
+
return jpath
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
nil
|
114
|
+
end
|
115
|
+
|
116
|
+
def find_sketchbook_path
|
117
|
+
preferences_paths = []
|
118
|
+
sketchbook_paths = []
|
119
|
+
sketchbook_path = Processing::RP_CONFIG.fetch('sketchbook_path', false)
|
120
|
+
return sketchbook_path if sketchbook_path
|
121
|
+
["'Application Data/Processing'", 'AppData/Roaming/Processing',
|
122
|
+
'Library/Processing', 'Documents/Processing',
|
123
|
+
'.processing', 'sketchbook'].each do |prefix|
|
124
|
+
spath = format('%s/%s', ENV['HOME'], prefix)
|
125
|
+
pref_path = format('%s/preferences.txt', spath)
|
126
|
+
preferences_paths << pref_path if FileTest.file?(pref_path)
|
127
|
+
sketchbook_paths << spath if FileTest.directory?(spath)
|
128
|
+
end
|
129
|
+
return sketchbook_paths.first if preferences_paths.empty?
|
130
|
+
lines = IO.readlines(preferences_paths.first)
|
131
|
+
matchedline = lines.grep(/^sketchbook/).first
|
132
|
+
matchedline[/=(.+)/].gsub('=', '')
|
95
133
|
end
|
96
|
-
[platform, platform + bits].map { |p| File.join(basename, p) }
|
97
|
-
end
|
98
|
-
|
99
|
-
def get_library_paths(path, library_name)
|
100
|
-
lib = File.join(path, library_name.to_s)
|
101
|
-
jar_files = File.join(lib, '**', '*.jar')
|
102
|
-
Dir.glob(jar_files)
|
103
134
|
end
|
104
135
|
end
|
data/lib/jruby_art/runner.rb
CHANGED
@@ -4,52 +4,66 @@ require 'rbconfig'
|
|
4
4
|
require_relative '../jruby_art/config'
|
5
5
|
require_relative '../jruby_art/version'
|
6
6
|
|
7
|
-
|
7
|
+
# processing wrapper module
|
8
8
|
module Processing
|
9
|
-
|
10
|
-
# Utility class to handle the different commands that the 'rp5' command
|
9
|
+
# Utility class to handle the different commands that the 'k9' command
|
11
10
|
# offers. Able to run, watch, live, create, app, and unpack
|
12
11
|
class Runner
|
13
|
-
HELP_MESSAGE
|
14
|
-
|
15
|
-
|
16
|
-
|
12
|
+
HELP_MESSAGE ||= <<-EOS
|
13
|
+
Version: #{JRubyArt::VERSION}
|
14
|
+
|
15
|
+
Ruby-Processing is a little shim between Processing and JRuby that helps
|
17
16
|
you create sketches of code art.
|
18
|
-
|
17
|
+
|
19
18
|
Usage:
|
20
|
-
k9
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
19
|
+
k9 [choice] sketch
|
20
|
+
|
21
|
+
choice:-
|
22
|
+
run: run sketch once
|
23
|
+
watch: watch for changes on the file and relaunch it on the fly
|
24
|
+
create [width height][mode][flag]: create a new sketch.
|
25
|
+
setup: check setup, install jruby-complete, unpack samples
|
26
|
+
|
27
|
+
Common options:
|
28
|
+
--nojruby: use jruby-complete in place of an installed version of jruby
|
29
|
+
(Set [JRUBY: 'false'] in .k9rc to make using jruby-complete default)
|
30
|
+
|
31
|
+
Examples:
|
32
|
+
k9 setup unpack_samples
|
33
|
+
k9 run rp_samples/samples/contributed/jwishy.rb
|
34
|
+
k9 create some_new_sketch 640 480 p3d (P3D mode example)
|
35
|
+
k9 create some_new_sketch 640 480 --wrap (a class wrapped default sketch)
|
36
|
+
k9 watch some_new_sketch.rb
|
37
|
+
|
38
|
+
Everything Else:
|
39
|
+
http://wiki.github.com/monkstone/jruby_art-3.0
|
40
|
+
|
25
41
|
EOS
|
26
|
-
|
42
|
+
|
27
43
|
WIN_PATTERNS = [
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
44
|
+
/bccwin/i,
|
45
|
+
/cygwin/i,
|
46
|
+
/djgpp/i,
|
47
|
+
/ming/i,
|
48
|
+
/mswin/i,
|
49
|
+
/wince/i
|
34
50
|
]
|
35
|
-
|
51
|
+
|
36
52
|
attr_reader :os
|
37
|
-
|
38
|
-
# Start running a
|
53
|
+
|
54
|
+
# Start running a jruby_art sketch from the passed-in arguments
|
39
55
|
def self.execute
|
40
56
|
runner = new
|
41
57
|
runner.parse_options(ARGV)
|
42
58
|
runner.execute!
|
43
59
|
end
|
44
|
-
|
60
|
+
|
45
61
|
# Dispatch central.
|
46
62
|
def execute!
|
47
63
|
case @options.action
|
48
64
|
when 'run' then run(@options.path, @options.args)
|
49
|
-
|
50
|
-
when 'wrap' then wrap(@options.path, @options.args)
|
65
|
+
when 'watch' then watch(@options.path, @options.args)
|
51
66
|
when 'create' then create(@options.path, @options.args)
|
52
|
-
# when 'app' then app(@options.path)
|
53
67
|
when 'setup' then setup(@options.path)
|
54
68
|
when /-v/ then show_version
|
55
69
|
when /-h/ then show_help
|
@@ -57,66 +71,197 @@ module Processing
|
|
57
71
|
show_help
|
58
72
|
end
|
59
73
|
end
|
60
|
-
|
74
|
+
|
61
75
|
# Parse the command-line options. Keep it simple.
|
62
76
|
def parse_options(args)
|
63
77
|
@options = OpenStruct.new
|
64
78
|
@options.wrap = !args.delete('--wrap').nil?
|
79
|
+
@options.inner = !args.delete('--inner').nil?
|
80
|
+
@options.jruby = !args.delete('--jruby').nil?
|
81
|
+
@options.nojruby = !args.delete('--nojruby').nil?
|
65
82
|
@options.action = args[0] || nil
|
66
83
|
@options.path = args[1] || File.basename(Dir.pwd + '.rb')
|
67
84
|
@options.args = args[2..-1] || []
|
68
85
|
end
|
69
|
-
|
70
|
-
# Create a fresh
|
86
|
+
|
87
|
+
# Create a fresh JRubyArt sketch, with the necessary
|
71
88
|
# boilerplate filled out.
|
72
89
|
def create(sketch, args)
|
73
|
-
require_relative 'creator'
|
74
|
-
Processing::
|
90
|
+
require_relative '../jruby_art/creators/creator'
|
91
|
+
return Processing::Inner.new.create!(sketch, args) if @options.inner
|
92
|
+
return Processing::ClassSketch.new.create!(sketch, args) if @options.wrap
|
93
|
+
Processing::BasicSketch.new.create!(sketch, args)
|
75
94
|
end
|
76
|
-
|
77
|
-
|
78
|
-
require_relative 'writer'
|
79
|
-
writer = Processing::Writer.new
|
80
|
-
writer.read(sketch)
|
81
|
-
writer.write
|
82
|
-
end
|
83
|
-
|
95
|
+
|
96
|
+
# Just simply run a JRubyArt sketch.
|
84
97
|
def run(sketch, args)
|
85
|
-
|
86
|
-
|
87
|
-
end
|
88
|
-
|
89
|
-
def jruby_complete
|
90
|
-
rcomplete = File.join(K9_ROOT, '/lib/ruby/jruby-complete.jar')
|
91
|
-
return rcomplete if FileTest.exist?(rcomplete)
|
92
|
-
warn "#{rcomplete} does not exist\nTry running `k9 setup install`"
|
98
|
+
ensure_exists(sketch)
|
99
|
+
spin_up('run.rb', sketch, args)
|
93
100
|
end
|
94
101
|
|
95
|
-
|
96
|
-
|
102
|
+
# Run a sketch, keeping an eye on it's file, and reloading
|
103
|
+
# whenever it changes.
|
104
|
+
def watch(sketch, args)
|
105
|
+
ensure_exists(sketch)
|
106
|
+
spin_up('watch.rb', sketch, args)
|
97
107
|
end
|
98
|
-
|
108
|
+
|
99
109
|
def setup(choice)
|
100
|
-
usage = 'Usage: k9 setup [install]'
|
101
|
-
installed = FileTest.exist?(File.join(K9_ROOT, '/lib/ruby/jruby-complete.jar'))
|
102
110
|
proc_root = FileTest.exist?("#{ENV['HOME']}/.jruby_art/config.yml")
|
103
111
|
case choice
|
104
|
-
when /
|
105
|
-
|
112
|
+
when /check/
|
113
|
+
check(proc_root, FileTest.exist?("#{RP5_ROOT}/lib/ruby/jruby-complete.jar"))
|
114
|
+
when /install/
|
115
|
+
install(proc_root)
|
116
|
+
when /unpack_samples/
|
117
|
+
system "cd #{RP5_ROOT}/vendors && rake unpack_samples"
|
106
118
|
else
|
107
|
-
puts
|
119
|
+
puts 'Usage: k9 setup [check | install | unpack_samples]'
|
108
120
|
end
|
109
121
|
end
|
110
|
-
|
122
|
+
|
123
|
+
def install(root_exist)
|
124
|
+
system "cd #{RP5_ROOT}/vendors && rake"
|
125
|
+
return if root_exist
|
126
|
+
set_processing_root
|
127
|
+
warn 'PROCESSING_ROOT set optimistically, run check to confirm'
|
128
|
+
end
|
129
|
+
|
130
|
+
def check(root_exist, installed)
|
131
|
+
show_version
|
132
|
+
root = ' PROCESSING_ROOT = Not Set!!!' unless root_exist
|
133
|
+
root ||= " PROCESSING_ROOT = #{Processing::RP_CONFIG['PROCESSING_ROOT']}"
|
134
|
+
jruby = Processing::RP_CONFIG['JRUBY']
|
135
|
+
x_off = Processing::RP_CONFIG['X_OFF']
|
136
|
+
y_off = Processing::RP_CONFIG['Y_OFF']
|
137
|
+
puts root
|
138
|
+
puts " JRUBY = #{jruby}" unless jruby.nil?
|
139
|
+
puts " X_OFF = #{x_off}" unless x_off.nil?
|
140
|
+
puts " Y_OFF = #{y_off}" unless y_off.nil?
|
141
|
+
puts " jruby-complete installed = #{installed}"
|
142
|
+
end
|
143
|
+
|
144
|
+
# Display the current version of Ruby-Processing.
|
145
|
+
def show_version
|
146
|
+
puts format('JRubyArt version %s', JRubyArt::VERSION)
|
147
|
+
end
|
148
|
+
|
111
149
|
# Show the standard help/usage message.
|
112
150
|
def show_help
|
113
151
|
puts HELP_MESSAGE
|
114
152
|
end
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
153
|
+
|
154
|
+
private
|
155
|
+
|
156
|
+
def core_classpath
|
157
|
+
Dir["#{Processing::RP_CONFIG['PROCESSING_ROOT']}/core/library/\*.jar"]
|
158
|
+
end
|
159
|
+
|
160
|
+
# Trade in this Ruby instance for a JRuby instance, loading in a starter
|
161
|
+
# script and passing it some arguments.Unless '--nojruby' is passed, the
|
162
|
+
# installed version of jruby is used instead of our vendored jarred one
|
163
|
+
# (which is required for some sketches eg shaders). To use
|
164
|
+
# jruby-complete by default set JRUBY: false in ~/.k9rc config
|
165
|
+
# (but that will make using other gems in your sketches hard....)
|
166
|
+
def spin_up(starter_script, sketch, args)
|
167
|
+
runner = "#{RP5_ROOT}/lib/jruby_art/runners/#{starter_script}"
|
168
|
+
warn('The --jruby flag is no longer required') if @options.jruby
|
169
|
+
@options.nojruby = true if Processing::RP_CONFIG['JRUBY'] == 'false'
|
170
|
+
java_args = discover_java_args(sketch)
|
171
|
+
if @options.nojruby
|
172
|
+
classpath = jruby_complete + core_classpath
|
173
|
+
command = ['java',
|
174
|
+
java_args,
|
175
|
+
'-cp',
|
176
|
+
classpath.join(path_separator),
|
177
|
+
'org.jruby.Main',
|
178
|
+
runner,
|
179
|
+
sketch,
|
180
|
+
args].flatten
|
181
|
+
else
|
182
|
+
command = ['jruby',
|
183
|
+
java_args,
|
184
|
+
'-J-cp',
|
185
|
+
core_classpath.join(path_separator),
|
186
|
+
runner,
|
187
|
+
sketch,
|
188
|
+
args].flatten
|
189
|
+
end
|
190
|
+
exec(*command)
|
191
|
+
# exec replaces the Ruby process with the JRuby one.
|
192
|
+
end
|
193
|
+
|
194
|
+
def path_separator
|
195
|
+
(host_os == :windows) ? ';' : ':'
|
196
|
+
end
|
197
|
+
|
198
|
+
# If you need to pass in arguments to Java, such as the ones on this page:
|
199
|
+
# http://docs.oracle.com/javase/1.5.0/docs/tooldocs/windows/java.html
|
200
|
+
# add them to a java_args.txt in your data directory next to your sketch.
|
201
|
+
def discover_java_args(sketch)
|
202
|
+
arg_file = "#{File.dirname(sketch)}/data/java_args.txt"
|
203
|
+
args = []
|
204
|
+
args += dock_icon
|
205
|
+
if FileTest.exist?(arg_file)
|
206
|
+
args += File.read(arg_file).split(/\s+/)
|
207
|
+
elsif Processing::RP_CONFIG['java_args']
|
208
|
+
args += Processing::RP_CONFIG['java_args'].split(/\s+/)
|
209
|
+
end
|
210
|
+
args.map! { |arg| "-J#{arg}" } unless @options.nojruby
|
211
|
+
args
|
212
|
+
end
|
213
|
+
|
214
|
+
# NB: We really do mean to use 'and' not '&&' for flow control purposes
|
215
|
+
|
216
|
+
def ensure_exists(sketch)
|
217
|
+
puts "Couldn't find: #{sketch}" and exit unless FileTest.exist?(sketch)
|
218
|
+
end
|
219
|
+
|
220
|
+
def jruby_complete
|
221
|
+
rcomplete = File.join(RP5_ROOT, 'lib/ruby/jruby-complete.jar')
|
222
|
+
return [rcomplete] if FileTest.exist?(rcomplete)
|
223
|
+
warn "#{rcomplete} does not exist\nTry running `k9 setup install`"
|
224
|
+
exit
|
119
225
|
end
|
120
|
-
end
|
121
|
-
end
|
122
226
|
|
227
|
+
def host_os
|
228
|
+
detect_os = RbConfig::CONFIG['host_os']
|
229
|
+
case detect_os
|
230
|
+
when /mac|darwin/ then :mac
|
231
|
+
when /linux/ then :linux
|
232
|
+
when /solaris|bsd/ then :unix
|
233
|
+
else
|
234
|
+
WIN_PATTERNS.find { |r| detect_os =~ r }
|
235
|
+
fail "unknown os: #{detect_os.inspect}" if Regexp.last_match.nil?
|
236
|
+
:windows
|
237
|
+
end
|
238
|
+
end
|
239
|
+
|
240
|
+
# Optimistically set processing root
|
241
|
+
def set_processing_root
|
242
|
+
require 'psych'
|
243
|
+
@os ||= host_os
|
244
|
+
data = {}
|
245
|
+
path = File.expand_path("#{ENV['HOME']}/.jruby_art/config.yml")
|
246
|
+
if os == :mac
|
247
|
+
data['PROCESSING_ROOT'] = '/Applications/Processing.app/Contents/Java'
|
248
|
+
else
|
249
|
+
root = "#{ENV['HOME']}/processing-3.0a10"
|
250
|
+
data['PROCESSING_ROOT'] = root
|
251
|
+
end
|
252
|
+
data['JRUBY'] = 'true'
|
253
|
+
open(path, 'w:UTF-8') { |f| f.write(data.to_yaml) }
|
254
|
+
end
|
255
|
+
|
256
|
+
# On the Mac, we can display a fat, shiny ruby in the Dock.
|
257
|
+
def dock_icon
|
258
|
+
@os ||= host_os
|
259
|
+
icon = []
|
260
|
+
if os == :mac
|
261
|
+
icon << '-Xdock:name=Ruby-Processing'
|
262
|
+
icon << "-Xdock:icon=#{RP5_ROOT}/lib/templates/application/Contents/Resources/sketch.icns"
|
263
|
+
end
|
264
|
+
icon
|
265
|
+
end
|
266
|
+
end # class Runner
|
267
|
+
end # module Processing
|