jruby_art 0.2.2.pre → 0.2.3.pre
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +45 -0
- data/README.md +3 -2
- data/Rakefile +26 -34
- data/lib/jruby_art/app.rb +47 -25
- data/lib/jruby_art/config.rb +2 -2
- data/lib/jruby_art/creator.rb +1 -1
- data/lib/jruby_art/helper_methods.rb +2 -1
- data/lib/jruby_art/helpers/numeric.rb +2 -1
- data/lib/jruby_art/library_loader.rb +104 -0
- data/lib/jruby_art/parse.rb +5 -6
- data/lib/jruby_art/runner.rb +10 -10
- data/lib/jruby_art/version.rb +2 -1
- data/lib/jruby_art.rb +1 -12
- data/lib/rpextras.jar +0 -0
- data/library/boids/boids.rb +217 -0
- data/library/control_panel/control_panel.rb +172 -0
- data/library/file_chooser/file_chooser.rb +82 -0
- data/spec/app_spec.rb +4 -4
- data/spec/library_loader_spec.rb +23 -0
- data/vendors/Rakefile +1 -1
- metadata +14 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6583235100be711a51d787b016db40e373f058bb
|
4
|
+
data.tar.gz: 3e12254c7ba77564a7a43899e09b142a4add57f2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 98e5d4dc74ed309290100e96f2d42fcfab4eb3346e46b86a8129f107fcabecea90cd63a5e557f87f1e3e08389c84115d491e98195392842dc0d0eb5e2df790a7
|
7
|
+
data.tar.gz: 39dbad9dbf14b0520dd8c9b0c350a1e200741e1bee9f9796474e466de41ed49006dc9828f09e390a9dec59db1731e9de2a8c6511318fbbcaff2786c3bd41a9cc
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
## JRubyArt CHANGELOG
|
2
|
+
|
3
|
+
It might seem a little of that this log starts at version 0.1.2, the reason for this is that previous version relate to earlier versions which were essentially a clone of ruby-processing.
|
4
|
+
|
5
|
+
### Version 0.2.3
|
6
|
+
|
7
|
+
Now using curl instead of wget "following the path of least resistance for enfeebled Mac users" and also there might be better Windows support for curl vs wget. Now includes a library loader for jars (supports video and sound library etc), added control_panel and boids library.
|
8
|
+
|
9
|
+
### Version 0.2.2
|
10
|
+
This was meant to be the pre-jruby-9000 version, but is now the pre library_loader
|
11
|
+
version
|
12
|
+
|
13
|
+
### Version 0.2.1
|
14
|
+
|
15
|
+
Features jruby-complete-1.7.19 and filtered native jars (attempt at load according to OS and Arch) works linux64
|
16
|
+
|
17
|
+
### Version 0.2.0
|
18
|
+
|
19
|
+
First pre release version features jruby-complete-1.7.18
|
20
|
+
|
21
|
+
### Version 0.1.7
|
22
|
+
|
23
|
+
Now installs jruby-complete-1.7.17 (which is a good deal smaller), also includes experimental Proxy extension to access draw, pre and post loops by reflection
|
24
|
+
|
25
|
+
### Version 0.1.6
|
26
|
+
|
27
|
+
Vec2D and Vec3D get `:to_curve_vertex`, see included example. Also new in examples is how to use jar libraries (toxiclibs) with JRubyArt.
|
28
|
+
|
29
|
+
### Version 0.1.5
|
30
|
+
|
31
|
+
Now you can wrap a bare sketch with `k9 wrap sketch.rb` sensibly wraps bare P2D, P3D and default processing mode sketches. The runner now laso makes a similar check.
|
32
|
+
|
33
|
+
### Version 0.1.4
|
34
|
+
|
35
|
+
Now with k9 you can run `bare` sketches, like original ruby-processing but with less sugar. So instead of `cos` use `Math,cos` etc, further no attempt has been made to mimic processing inner-class behaviour (bad OO practice).
|
36
|
+
|
37
|
+
|
38
|
+
### Version 0.1.3
|
39
|
+
|
40
|
+
Move config file from ~/.k9rc to ~/.jruby_art/config.yml, created installer for jruby-complete.jar. For sketches needing to be run with jruby-complete use `k9 run sketch.rb` (this includes shader sketches with `load_image`) or use netbeans with jruby-plugin to develop your sketches. For 3D sketches (or to use P2D) inherit from AppGL, both AppGL and App inherit directly from PApplet. Examples have been moved to there own repo `k9 setup install` downloads and install jruby-complete and downloads and extracts sample to users HOME directory.
|
41
|
+
|
42
|
+
|
43
|
+
### Version 0.1.2
|
44
|
+
|
45
|
+
First point release, requires user build, supports 2D and opengl sketches, but no library support. Sketches will only run with jruby (jruby-complete is not included). To run sketches with load_image jruby-complete is required, so either provide that or use netbeans as your ide (with jruby plugin).
|
data/README.md
CHANGED
@@ -10,7 +10,7 @@ Java runtime 7+, and ruby (can be MRI ruby), curl (to download jruby-complete an
|
|
10
10
|
### Getting Started
|
11
11
|
|
12
12
|
```bash
|
13
|
-
gem install jruby-art --
|
13
|
+
gem install jruby-art --pre
|
14
14
|
k9 setup install # uses curl to to download jruby-complete and examples
|
15
15
|
cd examples/contributed
|
16
16
|
k9 run clock.rb # if you've got jruby on your machine `jruby clock.rb` also works
|
@@ -53,7 +53,7 @@ However such sketches must be run with `k9 run sketch.rb`, however you can do 'k
|
|
53
53
|
|
54
54
|
jruby-1.7.19 (when sketches run with jruby command)
|
55
55
|
|
56
|
-
jruby-9.0.0.0.pre1 also seems to work (the next pre-release will target jruby-9.0.0.0-
|
56
|
+
jruby-9.0.0.0.pre1 also seems to work (the next pre-release will target jruby-9.0.0.0-pre2)
|
57
57
|
|
58
58
|
or
|
59
59
|
|
@@ -73,6 +73,7 @@ See [netbeans][]
|
|
73
73
|
|
74
74
|
[CHANGELOG][]
|
75
75
|
|
76
|
+
[Building latest gem](https://github.com/ruby-processing/JRubyArt/wiki/Building-latest-gem/)
|
76
77
|
[Acknowledgements]:ACKNOWLEDGEMENTS.md
|
77
78
|
[CHANGELOG]:CHANGELOG.md
|
78
79
|
[Contributing]:CONTRIBUTING.md
|
data/Rakefile
CHANGED
@@ -4,26 +4,29 @@ require 'rake/clean'
|
|
4
4
|
require 'rubygems/package_task'
|
5
5
|
require 'rdoc/task'
|
6
6
|
require 'rake/testtask'
|
7
|
-
require 'rspec/core/rake_task'
|
8
7
|
require_relative 'lib/jruby_art/version'
|
9
8
|
|
9
|
+
CLEAN.include('tmp')
|
10
|
+
CLOBBER.include(Rake::FileList.new('lib/*.jar'))
|
11
|
+
|
10
12
|
spec = Gem::Specification.new do |s|
|
11
13
|
s.name = 'jruby_art'
|
12
14
|
s.version = JRubyArt::VERSION
|
13
15
|
s.has_rdoc = true
|
14
|
-
s.extra_rdoc_files = ['README.md', 'LICENSE.md']
|
16
|
+
s.extra_rdoc_files = ['README.md', 'LICENSE.md', 'CHANGELOG.md']
|
15
17
|
s.summary = 'Ruby processing development branch'
|
16
|
-
s.description =
|
18
|
+
s.description = "A ruby wrapper for processing, that doesn't require a separate install of processing"
|
17
19
|
s.license = 'MIT'
|
18
20
|
s.author = 'Martin Prout'
|
19
21
|
s.email = 'martin_p@lineone.net'
|
20
22
|
s.homepage = 'https://github.com/ruby-processing/JRubyArt'
|
21
23
|
s.executables << 'k9'
|
22
|
-
s.files = %w(LICENSE.md README.md Rakefile) + Dir.glob(
|
24
|
+
s.files = %w(LICENSE.md README.md Rakefile CHANGELOG.md) + Dir.glob('{bin,lib,library,spec,vendors}/**/*')
|
23
25
|
s.require_path = 'lib'
|
24
|
-
s.
|
25
|
-
s.add_development_dependency
|
26
|
-
s.add_development_dependency
|
26
|
+
s.required_ruby_version = '~> 2.0'
|
27
|
+
s.add_development_dependency 'rake', '~> 10.4'
|
28
|
+
s.add_development_dependency 'rspec', '~> 3.2'
|
29
|
+
s.add_development_dependency 'rake-compiler', '~> 0.9'
|
27
30
|
s.requirements << 'A decent graphics card'
|
28
31
|
s.requirements << 'java runtime >= 1.7+'
|
29
32
|
end
|
@@ -41,53 +44,42 @@ def copy_jars(name, dest)
|
|
41
44
|
begin
|
42
45
|
path = File.expand_path(conf)
|
43
46
|
rp_config = (Psych.load_file(path))
|
44
|
-
source= "#{rp_config[
|
47
|
+
source = "#{rp_config['PROCESSING_ROOT']}/core/library/"
|
45
48
|
rescue
|
46
49
|
raise "WARNING: you must set PROCESSING_ROOT in #{conf} compile"
|
47
50
|
end
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
51
|
+
body = proc {
|
52
|
+
Dir["#{source}/*.jar"].each do |f|
|
53
|
+
puts "Copying #{f} To #{dest}"
|
54
|
+
FileUtils.cp f, dest
|
55
|
+
end
|
56
|
+
}
|
57
|
+
Rake::Task.define_task(name, &body)
|
55
58
|
end
|
56
59
|
|
57
60
|
copy_jars(:processing_jars, 'lib')
|
58
61
|
|
59
62
|
Rake::JavaExtensionTask.new('processing') do |ext|
|
60
63
|
jars = FileList['lib/*.jar']
|
61
|
-
ext.classpath = jars.map { |x| File.expand_path x}.join ':'
|
64
|
+
ext.classpath = jars.map { |x| File.expand_path x }.join ':'
|
62
65
|
ext.name = 'rpextras'
|
63
66
|
ext.debug = true
|
64
67
|
ext.lib_dir = 'lib'
|
65
|
-
ext.source_version='1.7'
|
66
|
-
ext.target_version='1.7'
|
68
|
+
ext.source_version = '1.7'
|
69
|
+
ext.target_version = '1.7'
|
67
70
|
end
|
68
71
|
|
69
72
|
Gem::PackageTask.new(spec) do |p|
|
70
73
|
p.gem_spec = spec
|
71
|
-
p.need_tar =
|
72
|
-
p.need_zip =
|
74
|
+
p.need_tar = false
|
75
|
+
p.need_zip = false
|
73
76
|
end
|
74
77
|
|
75
78
|
Rake::RDocTask.new do |rdoc|
|
76
|
-
files =['README.md', 'LICENSE.md', 'lib/**/*.rb']
|
79
|
+
files = ['README.md', 'LICENSE.md', 'lib/**/*.rb', 'library']
|
77
80
|
rdoc.rdoc_files.add(files)
|
78
|
-
rdoc.main =
|
79
|
-
rdoc.title =
|
81
|
+
rdoc.main = 'README.md' # page to start on
|
82
|
+
rdoc.title = 'JRubyArt Docs'
|
80
83
|
rdoc.rdoc_dir = 'doc/rdoc' # rdoc output folder
|
81
84
|
rdoc.options << '--line-numbers'
|
82
85
|
end
|
83
|
-
|
84
|
-
Rake::TestTask.new do |t|
|
85
|
-
t.test_files = FileList['test/**/*.rb']
|
86
|
-
end
|
87
|
-
|
88
|
-
RSpec::Core::RakeTask.new do |spec|
|
89
|
-
spec.pattern = 'spec/*_spec.rb'
|
90
|
-
spec.rspec_opts = [Dir["lib"].to_a.join(':')]
|
91
|
-
end
|
92
|
-
|
93
|
-
|
data/lib/jruby_art/app.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require_relative 'helper_methods'
|
2
|
+
require_relative 'library_loader'
|
2
3
|
|
3
4
|
# The Processing module is a wrapper for JRubyArt
|
4
5
|
# Author:: Martin Prout (extends / re-implements ruby-processing)
|
@@ -25,14 +26,14 @@ module Processing
|
|
25
26
|
def post_initialize(_opts = {})
|
26
27
|
nil
|
27
28
|
end
|
28
|
-
|
29
|
+
|
29
30
|
# This method configures the sketch title and and presentation mode.
|
30
31
|
#
|
31
32
|
def configure_sketch
|
32
33
|
presentation_mode
|
33
34
|
sketch_title
|
34
35
|
end
|
35
|
-
|
36
|
+
|
36
37
|
# This method sets the sketch presentation mode.
|
37
38
|
#
|
38
39
|
def presentation_mode
|
@@ -40,20 +41,20 @@ module Processing
|
|
40
41
|
args << '--full-screen'
|
41
42
|
args << "--bgcolor=#{opts[:bgcolor]}" if opts[:bgcolor]
|
42
43
|
end
|
43
|
-
|
44
|
+
|
44
45
|
# This method is the main draw loop of the sketch. This is usually
|
45
46
|
# overridden by the user.
|
46
47
|
#
|
47
48
|
def draw
|
48
49
|
nil
|
49
50
|
end
|
50
|
-
|
51
|
+
|
51
52
|
# This method runs the processing sketch.
|
52
53
|
#
|
53
54
|
def run_sketch
|
54
55
|
PApplet.run_sketch(args.to_java(:string), self)
|
55
56
|
end
|
56
|
-
|
57
|
+
|
57
58
|
# This method sets the sketch title.
|
58
59
|
#
|
59
60
|
def sketch_title
|
@@ -72,13 +73,34 @@ module Processing
|
|
72
73
|
key_released: :keyReleased,
|
73
74
|
key_typed: :keyTyped
|
74
75
|
}
|
75
|
-
|
76
|
+
|
76
77
|
# This class is for default (Java2D) sketches only
|
77
78
|
class App < PApplet
|
78
|
-
include Common, HelperMethods
|
79
|
-
Java::ProcessingVecmathArcball::ArcballLibrary.new.load(JRuby.runtime, false)
|
79
|
+
include Math, Common, HelperMethods
|
80
80
|
attr_reader :title, :args, :opts
|
81
|
-
|
81
|
+
|
82
|
+
class << self
|
83
|
+
# Handy getters and setters on the class go here:
|
84
|
+
attr_accessor :sketch_class, :library_loader
|
85
|
+
|
86
|
+
def load_libraries(*args)
|
87
|
+
library_loader ||= LibraryLoader.new
|
88
|
+
library_loader.load_libraries(*args)
|
89
|
+
end
|
90
|
+
alias_method :load_library, :load_libraries
|
91
|
+
|
92
|
+
# When certain special methods get added to the sketch, we need to let
|
93
|
+
# Processing call them by their expected Java names.
|
94
|
+
def method_added(method_name) #:nodoc:
|
95
|
+
return unless METHODS_TO_ALIAS.key?(method_name)
|
96
|
+
alias_method METHODS_TO_ALIAS[method_name], method_name
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def sketch_class
|
101
|
+
self.class.sketch_class
|
102
|
+
end
|
103
|
+
|
82
104
|
# App should be instantiated with an optional list of opts
|
83
105
|
# and array of args.
|
84
106
|
#
|
@@ -90,35 +112,27 @@ module Processing
|
|
90
112
|
post_initialize(opts)
|
91
113
|
@args = args
|
92
114
|
@opts = opts
|
115
|
+
$app = self
|
93
116
|
configure_sketch
|
94
117
|
run_sketch
|
95
118
|
end
|
96
|
-
|
119
|
+
|
97
120
|
# This method provides the default setup for the sketch. It can
|
98
121
|
# be overridden by the user for finer grained control.
|
99
122
|
#
|
100
123
|
def setup
|
101
124
|
size(width, height)
|
102
125
|
end
|
103
|
-
|
104
|
-
# When certain special methods get added to the sketch, we need to let
|
105
|
-
# Processing call them by their expected Java names.
|
106
|
-
def self.method_added(method_name) # :nodoc:
|
107
|
-
# Watch the definition of these methods, to make sure
|
108
|
-
# that Processing is able to call them during events.
|
109
|
-
if METHODS_TO_ALIAS.key?(method_name)
|
110
|
-
alias_method METHODS_TO_ALIAS[method_name], method_name
|
111
|
-
end
|
112
|
-
end
|
113
126
|
end
|
114
|
-
|
127
|
+
|
115
128
|
# This class is for opengl sketches (P2D and P3D)
|
116
129
|
class AppGL < PApplet
|
117
|
-
include Processing, Common
|
130
|
+
include Math, Processing, Common
|
118
131
|
include_package 'processing.opengl' # imports the processing.opengl package.
|
119
132
|
include HelperMethods
|
133
|
+
Java::ProcessingVecmathArcball::ArcballLibrary.new.load(JRuby.runtime, false)
|
120
134
|
attr_reader :title, :args, :opts
|
121
|
-
|
135
|
+
|
122
136
|
# App should be instantiated with an optional list of opts
|
123
137
|
# and array of args.
|
124
138
|
#
|
@@ -130,10 +144,11 @@ module Processing
|
|
130
144
|
post_initialize(opts)
|
131
145
|
@args = args
|
132
146
|
@opts = opts
|
147
|
+
$app = self
|
133
148
|
configure_sketch
|
134
149
|
run_sketch
|
135
150
|
end
|
136
|
-
|
151
|
+
|
137
152
|
# This method provides the default setup for the sketch. It can
|
138
153
|
# be overridden by the user for finer grained control.
|
139
154
|
#
|
@@ -141,7 +156,13 @@ module Processing
|
|
141
156
|
size(width, height, mode = P3D)
|
142
157
|
fail unless /opengl/ =~ mode
|
143
158
|
end
|
144
|
-
|
159
|
+
|
160
|
+
def load_libraries(*args)
|
161
|
+
library_loader ||= LibraryLoader.new
|
162
|
+
library_loader.load_libraries(*args)
|
163
|
+
end
|
164
|
+
alias_method :load_library, :load_libraries
|
165
|
+
|
145
166
|
# When certain special methods get added to the sketch, we need to let
|
146
167
|
# Processing call them by their expected Java names.
|
147
168
|
def self.method_added(method_name) #:nodoc:
|
@@ -151,3 +172,4 @@ module Processing
|
|
151
172
|
end
|
152
173
|
end
|
153
174
|
end
|
175
|
+
|
data/lib/jruby_art/config.rb
CHANGED
data/lib/jruby_art/creator.rb
CHANGED
@@ -55,7 +55,7 @@ module Processing
|
|
55
55
|
def already_exist(path)
|
56
56
|
underscore = StringExtra.new(path).underscore
|
57
57
|
new_file = "#{File.dirname(path)}/#{underscore}.rb"
|
58
|
-
return if !
|
58
|
+
return if !FileTest.exist?(path) && !FileTest.exist?(new_file)
|
59
59
|
puts 'That file already exists!'
|
60
60
|
exit
|
61
61
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
module Processing
|
2
|
+
# Useful methods, not otherwise available
|
2
3
|
module HelperMethods
|
3
4
|
# processings epsilon may not be defined yet
|
4
5
|
EPSILON ||= 1.0e-04
|
@@ -107,7 +108,7 @@ module Processing
|
|
107
108
|
end
|
108
109
|
fail ArgumentError, 'takes 4 parameters'
|
109
110
|
end
|
110
|
-
|
111
|
+
|
111
112
|
# dist_squared only makes sense with 3D distance
|
112
113
|
def dist_squared(*args)
|
113
114
|
len = args.length
|
@@ -0,0 +1,104 @@
|
|
1
|
+
# The LibraryLoader class adds some logic for loading library jars/ruby libraries
|
2
|
+
class LibraryLoader
|
3
|
+
require_relative 'config'
|
4
|
+
attr_reader :installed, :libraries_path, :loaded_libraries, :local
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@libraries_path = Processing::RP_CONFIG.fetch('LIBRARIES_PATH', "#{ENV['HOME']}/.jruby_art/libraries")
|
8
|
+
@loaded_libraries = []
|
9
|
+
sketch_root = defined?(SKETCH_ROOT).nil? ? Dir.pwd : SKETCH_ROOT
|
10
|
+
@local = File.absolute_path("#{sketch_root}/library/")
|
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)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def local_java_lib(arg)
|
30
|
+
java_lib(local, arg)
|
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?
|
64
|
+
end
|
65
|
+
unless platform_specific_library_paths.empty?
|
66
|
+
platform_specific_library_paths << java.lang.System.getProperty('java.library.path')
|
67
|
+
new_library_path = platform_specific_library_paths.join(java.io.File.pathSeparator)
|
68
|
+
java.lang.System.setProperty('java.library.path', new_library_path)
|
69
|
+
field = java.lang.Class.for_name('java.lang.ClassLoader').get_declared_field('sys_paths')
|
70
|
+
if field
|
71
|
+
field.accessible = true
|
72
|
+
field.set(java.lang.Class.for_name('java.lang.System').get_class_loader, nil)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
loaded_libraries << library_name
|
76
|
+
end
|
77
|
+
|
78
|
+
def platform
|
79
|
+
match = %w(Mac Linux Windows).find do |os|
|
80
|
+
java.lang.System.getProperty('os.name').index(os)
|
81
|
+
end
|
82
|
+
return 'other' unless match
|
83
|
+
return match.downcase unless match =~ /Mac/
|
84
|
+
'macosx'
|
85
|
+
end
|
86
|
+
|
87
|
+
def get_platform_specific_library_paths(basename)
|
88
|
+
bits = 'universal' # for MacOSX, but does this even work, or does Mac return '64'?
|
89
|
+
if java.lang.System.getProperty('sun.arch.data.model') == '32' ||
|
90
|
+
java.lang.System.getProperty('java.vm.name').index('32')
|
91
|
+
bits = '32'
|
92
|
+
elsif java.lang.System.getProperty('sun.arch.data.model') == '64' ||
|
93
|
+
java.lang.System.getProperty('java.vm.name').index('64')
|
94
|
+
bits = '64' unless platform =~ /macosx/
|
95
|
+
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
|
+
end
|
104
|
+
end
|
data/lib/jruby_art/parse.rb
CHANGED
@@ -6,7 +6,7 @@ SKETCH_ROOT ||= File.dirname(SKETCH_PATH)
|
|
6
6
|
require_relative '../jruby_art'
|
7
7
|
require_relative '../jruby_art/'
|
8
8
|
require_relative '../jruby_art/helpers/string_extra'
|
9
|
-
|
9
|
+
# The top level module
|
10
10
|
module Processing
|
11
11
|
# For use with "bare" sketches that don't want to define a class or methods
|
12
12
|
BARE_TEMPLATE = <<-EOS
|
@@ -18,7 +18,7 @@ module Processing
|
|
18
18
|
|
19
19
|
Sketch.new(title: '%s')
|
20
20
|
EOS
|
21
|
-
|
21
|
+
|
22
22
|
NAKED_TEMPLATE = <<-EOS
|
23
23
|
require 'jruby_art'
|
24
24
|
|
@@ -37,14 +37,14 @@ module Processing
|
|
37
37
|
def self.load_and_run_sketch
|
38
38
|
source = read_sketch_source
|
39
39
|
has_sketch = !source.match(/^[^#]*< Processing::App/).nil?
|
40
|
-
has_methods = !source.match(/^[^#]*(def\s+setup|def\s+draw)/).nil?
|
40
|
+
has_methods = !source.match(/^[^#]*(def\s+setup|def\s+draw)/).nil?
|
41
41
|
return load File.join(SKETCH_ROOT, SKETCH_PATH) if has_sketch
|
42
42
|
title = StringExtra.new(File.basename(SKETCH_PATH).sub(/(\.rb)$/, '')).titleize
|
43
43
|
if has_methods
|
44
|
-
default = source.match(/P(2|3)D/)
|
44
|
+
default = source.match(/P(2|3)D/)
|
45
45
|
mode = default ? 'Processing::App' : 'Processing::AppGL'
|
46
46
|
code = format(BARE_TEMPLATE, mode, source, title)
|
47
|
-
else
|
47
|
+
else
|
48
48
|
code = format(NAKED_TEMPLATE, source, title)
|
49
49
|
end
|
50
50
|
Object.class_eval code, SKETCH_PATH, -1
|
@@ -57,4 +57,3 @@ module Processing
|
|
57
57
|
end
|
58
58
|
|
59
59
|
Processing.load_and_run_sketch
|
60
|
-
|
data/lib/jruby_art/runner.rb
CHANGED
@@ -25,12 +25,12 @@ module Processing
|
|
25
25
|
EOS
|
26
26
|
|
27
27
|
WIN_PATTERNS = [
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
28
|
+
/bccwin/i,
|
29
|
+
/cygwin/i,
|
30
|
+
/djgpp/i,
|
31
|
+
/mingw/i,
|
32
|
+
/mswin/i,
|
33
|
+
/wince/i
|
34
34
|
]
|
35
35
|
|
36
36
|
attr_reader :os
|
@@ -80,7 +80,7 @@ module Processing
|
|
80
80
|
writer.read(sketch)
|
81
81
|
writer.write
|
82
82
|
end
|
83
|
-
|
83
|
+
|
84
84
|
def run(sketch, args)
|
85
85
|
command = ['java', '-jar', jruby_complete, parse, sketch, args].flatten
|
86
86
|
exec(*command)
|
@@ -88,7 +88,7 @@ module Processing
|
|
88
88
|
|
89
89
|
def jruby_complete
|
90
90
|
rcomplete = File.join(K9_ROOT, '/lib/ruby/jruby-complete.jar')
|
91
|
-
return rcomplete if
|
91
|
+
return rcomplete if FileTest.exist?(rcomplete)
|
92
92
|
warn "#{rcomplete} does not exist\nTry running `k9 setup install`"
|
93
93
|
end
|
94
94
|
|
@@ -98,8 +98,8 @@ module Processing
|
|
98
98
|
|
99
99
|
def setup(choice)
|
100
100
|
usage = 'Usage: k9 setup [install]'
|
101
|
-
installed =
|
102
|
-
proc_root =
|
101
|
+
installed = FileTest.exist?(File.join(K9_ROOT, '/lib/ruby/jruby-complete.jar'))
|
102
|
+
proc_root = FileTest.exist?("#{ENV['HOME']}/.jruby_art/config.yml")
|
103
103
|
case choice
|
104
104
|
when /install/ # download and install jruby-complete and unpack examples to user home
|
105
105
|
system "cd #{K9_ROOT}/vendors && rake"
|
data/lib/jruby_art/version.rb
CHANGED
data/lib/jruby_art.rb
CHANGED
@@ -9,18 +9,6 @@ end
|
|
9
9
|
|
10
10
|
# guard prevents issues with mri ruby when using creator
|
11
11
|
if RUBY_PLATFORM == 'java'
|
12
|
-
#def platform
|
13
|
-
# host_os = RbConfig::CONFIG['host_os']
|
14
|
-
# return '*mac-universal.jar' if host_os =~ /mac|darwin/
|
15
|
-
# bit = ENV_JAVA['sun.arch.data.model']
|
16
|
-
# if host_os =~ /linux/
|
17
|
-
# bit.eql?('32') ? '*linux-i586.jar' : '*linux-amd64.jar'
|
18
|
-
# elsif host_os =~ /cygwin|windows/
|
19
|
-
# bit.eql?('32') ? '*windows-i586.jar' : '*windows-amd64.jar'
|
20
|
-
# else
|
21
|
-
# '*armv6hf.jar'
|
22
|
-
# end
|
23
|
-
#end
|
24
12
|
working_directory = File.join(File.dirname(__FILE__))
|
25
13
|
$LOAD_PATH << working_directory unless $LOAD_PATH.include?(working_directory)
|
26
14
|
Dir[File.join(working_directory, '*.jar')].each do |jar|
|
@@ -34,6 +22,7 @@ if RUBY_PLATFORM == 'java'
|
|
34
22
|
Java::ProcessingFastmath::DeglutLibrary.new.load(JRuby.runtime, false)
|
35
23
|
Java::ProcessingVecmathVec2::Vec2Library.new.load(JRuby.runtime, false)
|
36
24
|
Java::ProcessingVecmathVec3::Vec3Library.new.load(JRuby.runtime, false)
|
25
|
+
|
37
26
|
AppRender = Java::ProcessingVecmath::AppRender
|
38
27
|
ShapeRender = Java::ProcessingVecmath::ShapeRender
|
39
28
|
require 'jruby_art/app'
|
data/lib/rpextras.jar
CHANGED
Binary file
|
@@ -0,0 +1,217 @@
|
|
1
|
+
# Boids -- after Tom de Smedt.
|
2
|
+
# See his Python version: http://nodebox.net/code/index.php/Boids
|
3
|
+
# This is an example of how a pure-Ruby library can work.
|
4
|
+
# -- omygawshkenas
|
5
|
+
|
6
|
+
class Boid
|
7
|
+
attr_accessor :boids, :x, :y, :z, :vx, :vy, :vz, :is_perching, :perch_time
|
8
|
+
|
9
|
+
def initialize(boids, x, y, z)
|
10
|
+
@boids, @flock = boids, boids
|
11
|
+
@x, @y, @z = x, y, z
|
12
|
+
@vx, @vy, @vz = 0.0, 0.0, 0.0
|
13
|
+
@is_perching = false
|
14
|
+
@perch_time = 0.0
|
15
|
+
end
|
16
|
+
|
17
|
+
def cohesion(d = 100.0)
|
18
|
+
# Boids gravitate towards the center of the flock,
|
19
|
+
# Which is the averaged position of the rest of the boids.
|
20
|
+
cvx, cvy, cvz = 0.0, 0.0, 0.0
|
21
|
+
boids.reject { |bd| bd.equal? self }.each do |boid|
|
22
|
+
cvx, cvy, cvz = cvx + boid.x, cvy + boid.y, cvz + boid.z
|
23
|
+
end
|
24
|
+
count = boids.length - 1.0
|
25
|
+
cvx, cvy, cvz = cvx / count, cvy / count, cvz / count
|
26
|
+
[(cvx - x) / d, (cvy - y) / d, (cvz - z) / d]
|
27
|
+
end
|
28
|
+
|
29
|
+
def separation(radius = 10.0)
|
30
|
+
# Boids don't like to cuddle.
|
31
|
+
svx, svy, svz = 0.0, 0.0, 0.0
|
32
|
+
boids.reject { |bd| bd.equal? self }.each do |boid|
|
33
|
+
dvx, dvy, dvz = x - boid.x, y - boid.y, z - boid.z
|
34
|
+
svx += dvx if dvx.abs < radius
|
35
|
+
svy += dvy if dvy.abs < radius
|
36
|
+
svz += dvz if dvz.abs < radius
|
37
|
+
end
|
38
|
+
[svx, svy, svz]
|
39
|
+
end
|
40
|
+
|
41
|
+
def alignment(d = 5.0)
|
42
|
+
# Boids like to fly at the speed of traffic.
|
43
|
+
avx, avy, avz = 0.0, 0.0, 0.0
|
44
|
+
boids.reject { |bd| bd.equal? self }.each do |boid|
|
45
|
+
avx, avy, avz = avx + boid.vx, avy + boid.vy, avz + boid.vz
|
46
|
+
end
|
47
|
+
count = boids.length - 1.0
|
48
|
+
avx, avy, avz = avx / count, avy / count, avz / count
|
49
|
+
[(avx - vx) / d, (avy - vy) / d, (avz - vz) / d]
|
50
|
+
end
|
51
|
+
|
52
|
+
def limit(max = 30.0)
|
53
|
+
# Tweet, Tweet! The boid police will bust you for breaking the speed limit.
|
54
|
+
most = [@vx.abs, @vy.abs, @vz.abs].max
|
55
|
+
return if most < max
|
56
|
+
scale = max / most.to_f
|
57
|
+
@vx *= scale
|
58
|
+
@vy *= scale
|
59
|
+
@vz *= scale
|
60
|
+
end
|
61
|
+
|
62
|
+
def angle
|
63
|
+
a = (Math.atan(@vy / @vx) * (180.0 / Math::PI)) + 360.0
|
64
|
+
a += 180.0 if @vx < 0.0
|
65
|
+
a
|
66
|
+
end
|
67
|
+
|
68
|
+
def goal(gx, gy, gz, d = 50.0)
|
69
|
+
# Them boids is hungry.
|
70
|
+
[(gx - x) / d, (gy - y) / d, (gz - z) / d]
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
require 'forwardable'
|
75
|
+
|
76
|
+
class Boids
|
77
|
+
include Enumerable
|
78
|
+
extend Forwardable
|
79
|
+
def_delegators(:@boids, :reject, :<<, :each, :shuffle!, :length, :next)
|
80
|
+
|
81
|
+
attr_accessor :boids, :x, :y, :w, :h,
|
82
|
+
:scattered, :has_goal, :flee
|
83
|
+
|
84
|
+
attr_reader :scatter, :scatter_time, :scatter_i,
|
85
|
+
:perch, :perch_y, :perch_t, :boids,
|
86
|
+
:goal_x, :goal_y, :goal_z
|
87
|
+
|
88
|
+
def initialize
|
89
|
+
@boids = []
|
90
|
+
end
|
91
|
+
|
92
|
+
def self.flock(n, x, y, w, h)
|
93
|
+
Boids.new.setup(n, x, y, w, h)
|
94
|
+
end
|
95
|
+
|
96
|
+
def setup(n, x, y, w, h)
|
97
|
+
n.times do
|
98
|
+
dx, dy = rand(w), rand(h)
|
99
|
+
z = rand(200.0)
|
100
|
+
self << Boid.new(self, x + dx, y + dy, z)
|
101
|
+
end
|
102
|
+
@x, @y, @w, @h = x, y, w, h
|
103
|
+
init
|
104
|
+
self
|
105
|
+
end
|
106
|
+
|
107
|
+
def init
|
108
|
+
@scattered = false
|
109
|
+
@scatter = 0.005
|
110
|
+
@scatter_time = 50.0
|
111
|
+
@scatter_i = 0.0
|
112
|
+
@perch = 1.0 # Lower this number to divebomb.
|
113
|
+
@perch_y = h
|
114
|
+
@perch_t = -> { rand(25..75.0) }
|
115
|
+
@has_goal = false
|
116
|
+
@flee = false
|
117
|
+
@goal_x = @goal_y = @goal_z = 0.0
|
118
|
+
end
|
119
|
+
|
120
|
+
def scatter(chance = 0.005, frames = 50.0)
|
121
|
+
@scatter = chance
|
122
|
+
@scatter_time = frames
|
123
|
+
end
|
124
|
+
|
125
|
+
def no_scatter
|
126
|
+
@scatter = 0.0
|
127
|
+
end
|
128
|
+
|
129
|
+
def perch(ground = nil, chance = 1.0, frames = nil)
|
130
|
+
frames ||= -> { rand(25..75.0) }
|
131
|
+
ground ||= h
|
132
|
+
@perch, @perch_y, @perch_t = chance, ground, frames
|
133
|
+
end
|
134
|
+
|
135
|
+
def no_perch
|
136
|
+
@perch = 0.0
|
137
|
+
end
|
138
|
+
|
139
|
+
def goal(gx, gy, gz, flee = false)
|
140
|
+
@has_goal = true
|
141
|
+
@flee = flee
|
142
|
+
@goal_x, @goal_y, @goal_z = gx, gy, gz
|
143
|
+
end
|
144
|
+
|
145
|
+
def no_goal
|
146
|
+
@has_goal = false
|
147
|
+
end
|
148
|
+
|
149
|
+
def constrain
|
150
|
+
# Put them boids in a cage.
|
151
|
+
dx, dy = w * 0.1, h * 0.1
|
152
|
+
each do |b|
|
153
|
+
b.vx += rand(dx) if b.x < x - dx
|
154
|
+
b.vx += rand(dy) if b.y < y - dy
|
155
|
+
b.vx -= rand(dx) if b.x > x + w + dx
|
156
|
+
b.vy -= rand(dy) if b.y > y + h + dy
|
157
|
+
b.vz += 10.0 if b.z < 0.0
|
158
|
+
b.vz -= 10.0 if b.z > 100.0
|
159
|
+
next unless b.y > @perch_y && rand < @perch
|
160
|
+
b.y = @perch_y
|
161
|
+
b.vy = -(b.vy.abs) * 0.2
|
162
|
+
b.is_perching = true
|
163
|
+
@perch_t.respond_to?(:call) ? b.perch_time = @perch_t.call : b.perch_time = @perch_t
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
def update(opts = {}) # Just flutter, little boids ... just flutter away.
|
168
|
+
options = {
|
169
|
+
shuffled: true, # Shuffling keeps things flowing smooth.
|
170
|
+
cohesion: 100.0,
|
171
|
+
separation: 10.0,
|
172
|
+
alignment: 5.0,
|
173
|
+
goal: 20.0,
|
174
|
+
limit: 30.0
|
175
|
+
}
|
176
|
+
options.merge! opts
|
177
|
+
shuffle! if options[:shuffled]
|
178
|
+
m1 = 1.0 # cohesion
|
179
|
+
m2 = 1.0 # separation
|
180
|
+
m3 = 1.0 # alignment
|
181
|
+
m4 = 1.0 # goal
|
182
|
+
@scattered = true if !(@scattered) && rand < @scatter
|
183
|
+
if @scattered
|
184
|
+
m1 = -m1
|
185
|
+
m3 *= 0.25
|
186
|
+
@scatter_i += 1.0
|
187
|
+
end
|
188
|
+
if @scatter_i >= @scatter_time
|
189
|
+
@scattered = false
|
190
|
+
@scatter_i = 0.0
|
191
|
+
end
|
192
|
+
m4 = 0.0 unless @has_goal
|
193
|
+
m4 = -m4 if @flee
|
194
|
+
each do |b|
|
195
|
+
if b.is_perching
|
196
|
+
if b.perch_time > 0.0
|
197
|
+
b.perch_time -= 1.0
|
198
|
+
next
|
199
|
+
else
|
200
|
+
b.is_perching = false
|
201
|
+
end
|
202
|
+
end
|
203
|
+
vx1, vy1, vz1 = *b.cohesion(options[:cohesion])
|
204
|
+
vx2, vy2, vz2 = *b.separation(options[:separation])
|
205
|
+
vx3, vy3, vz3 = *b.alignment(options[:alignment])
|
206
|
+
vx4, vy4, vz4 = b.goal(@goal_x, @goal_y, @goal_z, options[:goal])
|
207
|
+
b.vx += m1 * vx1 + m2 * vx2 + m3 * vx3 + m4 * vx4
|
208
|
+
b.vy += m1 * vy1 + m2 * vy2 + m3 * vy3 + m4 * vy4
|
209
|
+
b.vz += m1 * vz1 + m2 * vz2 + m3 * vz3 + m4 * vz4
|
210
|
+
b.limit(options[:limit])
|
211
|
+
b.x += b.vx
|
212
|
+
b.y += b.vy
|
213
|
+
b.z += b.vz
|
214
|
+
end
|
215
|
+
constrain
|
216
|
+
end
|
217
|
+
end
|
@@ -0,0 +1,172 @@
|
|
1
|
+
# Here's a little library for quickly hooking up controls to sketches.
|
2
|
+
# For messing with the parameters and such.
|
3
|
+
# These controls will set instance variables on the sketches.
|
4
|
+
|
5
|
+
# You can make sliders, checkboxes, buttons, and drop-down menus.
|
6
|
+
# (optionally) pass the range and default value.
|
7
|
+
|
8
|
+
module ControlPanel
|
9
|
+
# class used to create slider elements for control_panel
|
10
|
+
class Slider < javax.swing.JSlider
|
11
|
+
def initialize(control_panel, name, range, initial_value, proc = nil)
|
12
|
+
min = range.begin * 100
|
13
|
+
max = (
|
14
|
+
(range.exclude_end? && range.begin.respond_to?(:succ)) ?
|
15
|
+
range.max : range.end) * 100
|
16
|
+
super(min, max)
|
17
|
+
set_minor_tick_spacing((max - min).abs / 10)
|
18
|
+
set_paint_ticks true
|
19
|
+
# paint_labels = true
|
20
|
+
set_preferred_size(java.awt.Dimension.new(190, 30))
|
21
|
+
label = control_panel.add_element(self, name)
|
22
|
+
add_change_listener do
|
23
|
+
update_label(label, name, value)
|
24
|
+
$app.instance_variable_set("@#{name}", value) unless value.nil?
|
25
|
+
proc.call(value) if proc
|
26
|
+
end
|
27
|
+
set_value(initial_value ? initial_value * 100 : min)
|
28
|
+
fire_state_changed
|
29
|
+
end
|
30
|
+
|
31
|
+
def value
|
32
|
+
get_value / 100.0
|
33
|
+
end
|
34
|
+
|
35
|
+
def update_label(label, name, value)
|
36
|
+
value = value.to_s
|
37
|
+
value << '0' if value.length < 4
|
38
|
+
label.set_text "<html><br><b>#{name}: #{value}</b></html>"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
# class used to combo_box menu elements for control_panel
|
43
|
+
class Menu < javax.swing.JComboBox
|
44
|
+
def initialize(control_panel, name, elements, initial_value, proc = nil)
|
45
|
+
super(elements.to_java(:String))
|
46
|
+
set_preferred_size(java.awt.Dimension.new(190, 30))
|
47
|
+
control_panel.add_element(self, name)
|
48
|
+
add_action_listener do
|
49
|
+
$app.instance_variable_set("@#{name}", value) unless value.nil?
|
50
|
+
proc.call(value) if proc
|
51
|
+
end
|
52
|
+
set_selected_index(initial_value ? elements.index(initial_value) : 0)
|
53
|
+
end
|
54
|
+
|
55
|
+
def value
|
56
|
+
get_selected_item
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
# Creates check-box elements for control_panel
|
61
|
+
class Checkbox < javax.swing.JCheckBox
|
62
|
+
def initialize(control_panel, name, proc = nil)
|
63
|
+
@control_panel = control_panel
|
64
|
+
super(name.to_s)
|
65
|
+
set_preferred_size(java.awt.Dimension.new(190, 64))
|
66
|
+
set_horizontal_alignment javax.swing.SwingConstants::CENTER
|
67
|
+
control_panel.add_element(self, name, false)
|
68
|
+
add_action_listener do
|
69
|
+
$app.instance_variable_set("@#{name}", value) unless value.nil?
|
70
|
+
proc.call(value) if proc
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def value
|
75
|
+
is_selected
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
# Creates button elements for control_panel
|
80
|
+
class Button < javax.swing.JButton
|
81
|
+
def initialize(control_panel, name, proc = nil)
|
82
|
+
super(name.to_s)
|
83
|
+
set_preferred_size(java.awt.Dimension.new(170, 64))
|
84
|
+
control_panel.add_element(self, name, false, true)
|
85
|
+
add_action_listener do
|
86
|
+
$app.send(name.to_s)
|
87
|
+
proc.call(value) if proc
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
# class used to contain control_panel elements
|
93
|
+
class Panel < javax.swing.JFrame
|
94
|
+
java_import javax.swing.UIManager
|
95
|
+
|
96
|
+
attr_accessor :elements, :panel
|
97
|
+
|
98
|
+
def initialize
|
99
|
+
super()
|
100
|
+
@elements = []
|
101
|
+
@panel = javax.swing.JPanel.new(java.awt.FlowLayout.new(1, 0, 0))
|
102
|
+
set_feel
|
103
|
+
end
|
104
|
+
|
105
|
+
def display
|
106
|
+
add panel
|
107
|
+
set_size 200, 30 + (64 * elements.size)
|
108
|
+
set_default_close_operation javax.swing.JFrame::HIDE_ON_CLOSE
|
109
|
+
set_resizable false
|
110
|
+
set_location($app.width + 10, 0) unless $app.width + 10 > $app.displayWidth
|
111
|
+
panel.visible = true
|
112
|
+
end
|
113
|
+
|
114
|
+
def add_element(element, name, has_label = true, _button_ = false)
|
115
|
+
if has_label
|
116
|
+
label = javax.swing.JLabel.new("<html><br><b>#{name}</b></html>")
|
117
|
+
panel.add label
|
118
|
+
end
|
119
|
+
elements << element
|
120
|
+
panel.add element
|
121
|
+
has_label ? label : nil
|
122
|
+
end
|
123
|
+
|
124
|
+
def remove
|
125
|
+
remove_all
|
126
|
+
dispose
|
127
|
+
end
|
128
|
+
|
129
|
+
def slider(name, range = 0..100, initial_value = nil, &block)
|
130
|
+
Slider.new(self, name, range, initial_value, block || nil)
|
131
|
+
end
|
132
|
+
|
133
|
+
def menu(name, elements, initial_value = nil, &block)
|
134
|
+
Menu.new(self, name, elements, initial_value, block || nil)
|
135
|
+
end
|
136
|
+
|
137
|
+
def checkbox(name, initial_value = nil, &block)
|
138
|
+
checkbox = Checkbox.new(self, name, block || nil)
|
139
|
+
checkbox.do_click if initial_value == true
|
140
|
+
end
|
141
|
+
|
142
|
+
def button(name, &block)
|
143
|
+
Button.new(self, name, block || nil)
|
144
|
+
end
|
145
|
+
|
146
|
+
def look_feel(lf)
|
147
|
+
set_feel(lf)
|
148
|
+
end
|
149
|
+
|
150
|
+
private
|
151
|
+
|
152
|
+
def set_feel(lf = 'metal')
|
153
|
+
lafinfo = javax.swing.UIManager.getInstalledLookAndFeels
|
154
|
+
laf = lafinfo.select do |info|
|
155
|
+
info.getName.eql? lf.capitalize
|
156
|
+
end
|
157
|
+
javax.swing.UIManager.setLookAndFeel(laf[0].getClassName)
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
# instance methods module
|
162
|
+
module InstanceMethods
|
163
|
+
def control_panel
|
164
|
+
@control_panel = ControlPanel::Panel.new unless @control_panel
|
165
|
+
return @control_panel unless block_given?
|
166
|
+
yield(@control_panel)
|
167
|
+
@control_panel.display
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
Processing::App.send :include, ControlPanel::InstanceMethods
|
@@ -0,0 +1,82 @@
|
|
1
|
+
# Here's a little library for using swing JFileChooser.
|
2
|
+
# in ruby-processing, borrows heavily from control_panel
|
3
|
+
|
4
|
+
module FileChooser
|
5
|
+
##
|
6
|
+
# FileFilter is abstract, requires accept and getDescription
|
7
|
+
##
|
8
|
+
|
9
|
+
require 'pathname'
|
10
|
+
JXChooser = Java::javax::swing::JFileChooser
|
11
|
+
JFile = Java::java::io::File
|
12
|
+
System = Java::JavaLang::System
|
13
|
+
|
14
|
+
class Filter < Java::javax::swing::filechooser::FileFilter
|
15
|
+
attr_reader :description, :extensions
|
16
|
+
def define(description, extensions)
|
17
|
+
@description, @extensions = description, extensions
|
18
|
+
end
|
19
|
+
|
20
|
+
def accept(fobj)
|
21
|
+
return true if extensions.include? File.extname(fobj.to_s).downcase
|
22
|
+
return true if fobj.isDirectory
|
23
|
+
end
|
24
|
+
|
25
|
+
def getDescription
|
26
|
+
description
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
class RXChooser
|
31
|
+
java_import javax.swing.UIManager
|
32
|
+
require 'rbconfig'
|
33
|
+
HOST = 'host_os'
|
34
|
+
UHOME = 'user.home'
|
35
|
+
UDIR = 'user.dir'
|
36
|
+
OS = :unix
|
37
|
+
case RbConfig::CONFIG[HOST]
|
38
|
+
when /darwin/ then OS = :mac
|
39
|
+
when /mswin|mingw/ then OS = :windows
|
40
|
+
end
|
41
|
+
|
42
|
+
def initialize
|
43
|
+
javax.swing.UIManager.setLookAndFeel(
|
44
|
+
javax.swing.UIManager.getSystemLookAndFeelClassName)
|
45
|
+
@chooser = JXChooser.new
|
46
|
+
end
|
47
|
+
|
48
|
+
def set_filter(description, extensions)
|
49
|
+
filter = FileChooser::Filter.new
|
50
|
+
filter.define(description, extensions)
|
51
|
+
@chooser.setFileFilter(filter)
|
52
|
+
end
|
53
|
+
|
54
|
+
def display
|
55
|
+
if :windows == OS
|
56
|
+
@chooser.setCurrentDirectory(JFile.new(System.getProperty(UDIR)))
|
57
|
+
else
|
58
|
+
@chooser.setCurrentDirectory(JFile.new(System.getProperty(UHOME)))
|
59
|
+
end
|
60
|
+
success = @chooser.show_open_dialog($app)
|
61
|
+
if success == JXChooser::APPROVE_OPTION
|
62
|
+
return Pathname.new(@chooser.get_selected_file.get_absolute_path).to_s
|
63
|
+
else
|
64
|
+
nil
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def dispose
|
69
|
+
@chooser = nil
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
module InstanceMethods
|
74
|
+
def file_chooser
|
75
|
+
@chooser = RXChooser.new
|
76
|
+
return @chooser unless block_given?
|
77
|
+
yield(@chooser)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
Processing::App.send :include, FileChooser::InstanceMethods
|
data/spec/app_spec.rb
CHANGED
@@ -13,7 +13,7 @@ describe Processing::App do
|
|
13
13
|
@processing_sketch = TestSketch.new title: 'sketch'
|
14
14
|
end
|
15
15
|
|
16
|
-
METHODS = %
|
16
|
+
METHODS = %i(
|
17
17
|
alpha
|
18
18
|
ambient
|
19
19
|
ambient_light
|
@@ -196,13 +196,13 @@ describe Processing::App do
|
|
196
196
|
)
|
197
197
|
|
198
198
|
METHODS.each { |method_string|
|
199
|
-
it "method:
|
200
|
-
@processing_sketch.
|
199
|
+
it "method: .#{method_string}" do
|
200
|
+
expect(@processing_sketch).to respond_to(method_string)
|
201
201
|
end
|
202
202
|
}
|
203
203
|
|
204
204
|
after :all do
|
205
|
-
|
205
|
+
@processing_sketch.exit
|
206
206
|
end
|
207
207
|
|
208
208
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require_relative '../lib/jruby_art/library_loader'
|
2
|
+
require_relative '../lib/jruby_art/config'
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe LibraryLoader do
|
6
|
+
|
7
|
+
before :all do
|
8
|
+
K9_ROOT = "../"
|
9
|
+
@library_loader = LibraryLoader.new
|
10
|
+
end
|
11
|
+
|
12
|
+
METHODS = %i(local_java_lib local_ruby_lib installed_java_lib installed_java_lib load_libraries)
|
13
|
+
|
14
|
+
METHODS.each { |method_string|
|
15
|
+
it "method: .#{method_string}" do
|
16
|
+
expect(@library_loader).to respond_to(method_string)
|
17
|
+
end
|
18
|
+
}
|
19
|
+
|
20
|
+
after :all do
|
21
|
+
@library_loader = nil
|
22
|
+
end
|
23
|
+
end
|
data/vendors/Rakefile
CHANGED
@@ -10,7 +10,7 @@ WARNING = <<-EOS
|
|
10
10
|
EOS
|
11
11
|
|
12
12
|
JRUBYC_VERSION = '1.7.19'
|
13
|
-
EXAMPLES = '0.0.
|
13
|
+
EXAMPLES = '0.0.5'
|
14
14
|
HOME_DIR = ENV['HOME']
|
15
15
|
MAC_OR_LINUX = /linux|mac|darwin/ =~ RbConfig::CONFIG['host_os']
|
16
16
|
CLOBBER.include("jruby-complete-#{JRUBYC_VERSION}.jar", "#{EXAMPLES}.tar.gz")
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jruby_art
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3.pre
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Martin Prout
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-02-
|
11
|
+
date: 2015-02-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|
@@ -29,7 +29,7 @@ dependencies:
|
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: '3.
|
32
|
+
version: '3.2'
|
33
33
|
name: rspec
|
34
34
|
prerelease: false
|
35
35
|
type: :development
|
@@ -37,7 +37,7 @@ dependencies:
|
|
37
37
|
requirements:
|
38
38
|
- - ~>
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '3.
|
40
|
+
version: '3.2'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
requirement: !ruby/object:Gem::Requirement
|
43
43
|
requirements:
|
@@ -52,7 +52,7 @@ dependencies:
|
|
52
52
|
- - ~>
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0.9'
|
55
|
-
description: A
|
55
|
+
description: A ruby wrapper for processing, that doesn't require a separate install of processing
|
56
56
|
email: martin_p@lineone.net
|
57
57
|
executables:
|
58
58
|
- k9
|
@@ -60,10 +60,12 @@ extensions: []
|
|
60
60
|
extra_rdoc_files:
|
61
61
|
- README.md
|
62
62
|
- LICENSE.md
|
63
|
+
- CHANGELOG.md
|
63
64
|
files:
|
64
65
|
- LICENSE.md
|
65
66
|
- README.md
|
66
67
|
- Rakefile
|
68
|
+
- CHANGELOG.md
|
67
69
|
- bin/k9
|
68
70
|
- lib/gluegen-rt.jar
|
69
71
|
- lib/rpextras.jar
|
@@ -83,6 +85,7 @@ files:
|
|
83
85
|
- lib/core.jar
|
84
86
|
- lib/jogl-all-natives-linux-i586.jar
|
85
87
|
- lib/jruby_art/creator.rb
|
88
|
+
- lib/jruby_art/library_loader.rb
|
86
89
|
- lib/jruby_art/writer.rb
|
87
90
|
- lib/jruby_art/config.rb
|
88
91
|
- lib/jruby_art/runner.rb
|
@@ -94,6 +97,10 @@ files:
|
|
94
97
|
- lib/jruby_art/helpers/camel_string.rb
|
95
98
|
- lib/jruby_art/helpers/numeric.rb
|
96
99
|
- lib/jruby_art/helpers/range.rb
|
100
|
+
- library/control_panel/control_panel.rb
|
101
|
+
- library/boids/boids.rb
|
102
|
+
- library/file_chooser/file_chooser.rb
|
103
|
+
- spec/library_loader_spec.rb
|
97
104
|
- spec/vecmath_spec.rb
|
98
105
|
- spec/spec_helper.rb
|
99
106
|
- spec/app_spec.rb
|
@@ -109,9 +116,9 @@ require_paths:
|
|
109
116
|
- lib
|
110
117
|
required_ruby_version: !ruby/object:Gem::Requirement
|
111
118
|
requirements:
|
112
|
-
- -
|
119
|
+
- - ~>
|
113
120
|
- !ruby/object:Gem::Version
|
114
|
-
version: '0'
|
121
|
+
version: '2.0'
|
115
122
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
123
|
requirements:
|
117
124
|
- - '>'
|