jruby_art 0.2.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 +7 -0
- data/LICENSE.md +39 -0
- data/README.md +88 -0
- data/Rakefile +93 -0
- data/bin/k9 +10 -0
- data/lib/core.jar +0 -0
- data/lib/export.txt +10 -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.rb +27 -0
- data/lib/jruby_art/app.rb +153 -0
- data/lib/jruby_art/config.rb +18 -0
- data/lib/jruby_art/creator.rb +100 -0
- data/lib/jruby_art/helper_methods.rb +220 -0
- data/lib/jruby_art/helpers/camel_string.rb +18 -0
- data/lib/jruby_art/helpers/numeric.rb +9 -0
- data/lib/jruby_art/helpers/range.rb +11 -0
- data/lib/jruby_art/helpers/string_extra.rb +33 -0
- data/lib/jruby_art/parse.rb +60 -0
- data/lib/jruby_art/runner.rb +142 -0
- data/lib/jruby_art/version.rb +3 -0
- data/lib/jruby_art/writer.rb +40 -0
- data/lib/rpextras.jar +0 -0
- data/spec/app_spec.rb +208 -0
- data/spec/deglut_spec.rb +25 -0
- data/spec/spec_helper.rb +96 -0
- data/spec/vecmath_spec.rb +277 -0
- data/vendors/Rakefile +95 -0
- metadata +116 -0
@@ -0,0 +1,142 @@
|
|
1
|
+
require 'ostruct'
|
2
|
+
require 'fileutils'
|
3
|
+
require 'rbconfig'
|
4
|
+
require_relative '../jruby_art/config'
|
5
|
+
require_relative '../jruby_art/version'
|
6
|
+
|
7
|
+
|
8
|
+
module Processing
|
9
|
+
|
10
|
+
# Utility class to handle the different commands that the 'rp5' command
|
11
|
+
# offers. Able to run, watch, live, create, app, and unpack
|
12
|
+
class Runner
|
13
|
+
HELP_MESSAGE = <<-EOS
|
14
|
+
JRubyArt Version: #{JRubyArt::VERSION}
|
15
|
+
|
16
|
+
JRubyArt is a little shim between Processing and JRuby that helps
|
17
|
+
you create sketches of code art.
|
18
|
+
|
19
|
+
Usage:
|
20
|
+
k9 create some_new_sketch 640 480
|
21
|
+
jruby some_new_sketch.rb
|
22
|
+
|
23
|
+
k9 run sketch.rb
|
24
|
+
|
25
|
+
EOS
|
26
|
+
|
27
|
+
WIN_PATTERNS = [
|
28
|
+
/bccwin/i,
|
29
|
+
/cygwin/i,
|
30
|
+
/djgpp/i,
|
31
|
+
/mingw/i,
|
32
|
+
/mswin/i,
|
33
|
+
/wince/i
|
34
|
+
]
|
35
|
+
|
36
|
+
attr_reader :os
|
37
|
+
|
38
|
+
# Start running a ruby-processing sketch from the passed-in arguments
|
39
|
+
def self.execute
|
40
|
+
runner = new
|
41
|
+
runner.parse_options(ARGV)
|
42
|
+
runner.execute!
|
43
|
+
end
|
44
|
+
|
45
|
+
# Dispatch central.
|
46
|
+
def execute!
|
47
|
+
case @options.action
|
48
|
+
when 'run' then run(@options.path, @options.args)
|
49
|
+
# when 'watch' then watch(@options.path, @options.args)
|
50
|
+
when 'wrap' then wrap(@options.path, @options.args)
|
51
|
+
when 'create' then create(@options.path, @options.args)
|
52
|
+
# when 'app' then app(@options.path)
|
53
|
+
when 'setup' then setup(@options.path)
|
54
|
+
when /-v/ then show_version
|
55
|
+
when /-h/ then show_help
|
56
|
+
else
|
57
|
+
show_help
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
# Parse the command-line options. Keep it simple.
|
62
|
+
def parse_options(args)
|
63
|
+
@options = OpenStruct.new
|
64
|
+
@options.wrap = !args.delete('--wrap').nil?
|
65
|
+
@options.action = args[0] || nil
|
66
|
+
@options.path = args[1] || File.basename(Dir.pwd + '.rb')
|
67
|
+
@options.args = args[2..-1] || []
|
68
|
+
end
|
69
|
+
|
70
|
+
# Create a fresh Ruby-Processing sketch, with the necessary
|
71
|
+
# boilerplate filled out.
|
72
|
+
def create(sketch, args)
|
73
|
+
require_relative 'creator'
|
74
|
+
Processing::ClassSketch.new.create!(sketch, args)
|
75
|
+
end
|
76
|
+
|
77
|
+
def wrap(sketch, args)
|
78
|
+
require_relative 'writer'
|
79
|
+
writer = Processing::Writer.new
|
80
|
+
writer.read(sketch)
|
81
|
+
writer.write
|
82
|
+
end
|
83
|
+
|
84
|
+
def run(sketch, args)
|
85
|
+
command = ['java', '-jar', jruby_complete, parse, sketch, args].flatten
|
86
|
+
exec(*command)
|
87
|
+
end
|
88
|
+
|
89
|
+
def jruby_complete
|
90
|
+
rcomplete = File.join(K9_ROOT, '/lib/ruby/jruby-complete.jar')
|
91
|
+
return rcomplete if File.exist?(rcomplete)
|
92
|
+
warn "#{rcomplete} does not exist\nTry running `k9 setup install`"
|
93
|
+
end
|
94
|
+
|
95
|
+
def parse
|
96
|
+
File.join(K9_ROOT, 'lib/jruby_art/parse.rb')
|
97
|
+
end
|
98
|
+
|
99
|
+
def setup(choice)
|
100
|
+
usage = 'Usage: k9 setup [install]'
|
101
|
+
installed = File.exist?(File.join(K9_ROOT, '/lib/ruby/jruby-complete.jar'))
|
102
|
+
proc_root = File.exist?("#{ENV['HOME']}/.jruby_art/config.yml")
|
103
|
+
case choice
|
104
|
+
when /install/ # download and install jruby-complete and unpack examples to user home
|
105
|
+
system "cd #{K9_ROOT}/vendors && rake"
|
106
|
+
unless proc_root
|
107
|
+
set_processing_root
|
108
|
+
warn 'PROCESSING_ROOT set optimistically, run check to confirm'
|
109
|
+
end
|
110
|
+
else
|
111
|
+
puts usage
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
# Optimistically set processing root
|
116
|
+
def set_processing_root
|
117
|
+
require 'psych'
|
118
|
+
@os ||= host_os
|
119
|
+
data = {}
|
120
|
+
path = File.expand_path("#{ENV['HOME']}/.jruby_art/config.yml")
|
121
|
+
if os == :mac
|
122
|
+
data['PROCESSING_ROOT'] = '/Applications/Processing.app/Contents/Java'
|
123
|
+
else
|
124
|
+
root = "#{ENV['HOME']}/processing-2.2.1"
|
125
|
+
data['PROCESSING_ROOT'] = root
|
126
|
+
end
|
127
|
+
data['JRUBY'] = true
|
128
|
+
open(path, 'w:UTF-8') { |f| f.write(data.to_yaml) }
|
129
|
+
end
|
130
|
+
|
131
|
+
# Show the standard help/usage message.
|
132
|
+
def show_help
|
133
|
+
puts HELP_MESSAGE
|
134
|
+
end
|
135
|
+
|
136
|
+
# Display the current version of Ruby-Processing.
|
137
|
+
def show_version
|
138
|
+
puts "JRubyArt version #{JRubyArt::VERSION}"
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require_relative './helpers/camel_string'
|
2
|
+
require_relative './helpers/string_extra'
|
3
|
+
|
4
|
+
module Processing
|
5
|
+
# Wraps bare sketch with class wrapper etc
|
6
|
+
class Writer
|
7
|
+
attr_reader :code, :file
|
8
|
+
REQ = "require 'jruby_art'\n\n"
|
9
|
+
KLASS = "class %s < %s \n\n"
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
@code = []
|
13
|
+
code << REQ
|
14
|
+
end
|
15
|
+
|
16
|
+
def read(input)
|
17
|
+
@file = input
|
18
|
+
source = File.read(input)
|
19
|
+
default = source.match(/P(2|3)D/).nil?
|
20
|
+
name = File.basename(input).sub(/(\.rb)$/, '')
|
21
|
+
mode = default ? 'Processing::App' : 'Processing::AppGL'
|
22
|
+
camel_name = CamelString.new(name).camelize
|
23
|
+
code << format(KLASS, camel_name, mode)
|
24
|
+
IO.foreach(input) do |line|
|
25
|
+
code << format(' %s', line)
|
26
|
+
end
|
27
|
+
code << "end\n\n"
|
28
|
+
title = StringExtra.new(name).titleize
|
29
|
+
code << "#{camel_name}.new(title: \"#{title}\")"
|
30
|
+
end
|
31
|
+
|
32
|
+
def write
|
33
|
+
File.open(file, 'w:UTF-8') do |out|
|
34
|
+
code.each do |line|
|
35
|
+
out.write(line)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/lib/rpextras.jar
ADDED
Binary file
|
data/spec/app_spec.rb
ADDED
@@ -0,0 +1,208 @@
|
|
1
|
+
require_relative '../lib/jruby_art'
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe Processing::App do
|
5
|
+
|
6
|
+
class TestSketch < Processing::App
|
7
|
+
def draw
|
8
|
+
# nothing to see here...
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
before :all do
|
13
|
+
@processing_sketch = TestSketch.new title: 'sketch'
|
14
|
+
end
|
15
|
+
|
16
|
+
METHODS = %w(
|
17
|
+
alpha
|
18
|
+
ambient
|
19
|
+
ambient_light
|
20
|
+
apply_matrix
|
21
|
+
arc
|
22
|
+
background
|
23
|
+
begin_camera
|
24
|
+
begin_contour
|
25
|
+
begin_raw
|
26
|
+
begin_record
|
27
|
+
begin_shape
|
28
|
+
bezier
|
29
|
+
bezier_detail
|
30
|
+
bezier_point
|
31
|
+
bezier_tangent
|
32
|
+
bezier_vertex
|
33
|
+
blend
|
34
|
+
blend_mode
|
35
|
+
blue
|
36
|
+
box
|
37
|
+
brightness
|
38
|
+
camera
|
39
|
+
color
|
40
|
+
color_mode
|
41
|
+
copy
|
42
|
+
create_font
|
43
|
+
create_graphics
|
44
|
+
create_image
|
45
|
+
create_input
|
46
|
+
create_output
|
47
|
+
create_reader
|
48
|
+
create_shape
|
49
|
+
create_writer
|
50
|
+
cursor
|
51
|
+
curve
|
52
|
+
curve_detail
|
53
|
+
curve_point
|
54
|
+
curve_tangent
|
55
|
+
curve_tightness
|
56
|
+
curve_vertex
|
57
|
+
directional_light
|
58
|
+
display_height
|
59
|
+
display_width
|
60
|
+
ellipse
|
61
|
+
ellipse_mode
|
62
|
+
emissive
|
63
|
+
end_camera
|
64
|
+
end_contour
|
65
|
+
end_raw
|
66
|
+
end_record
|
67
|
+
end_shape
|
68
|
+
fill
|
69
|
+
filter
|
70
|
+
focused
|
71
|
+
frame_count
|
72
|
+
frame_rate
|
73
|
+
frame_rate
|
74
|
+
frustum
|
75
|
+
get
|
76
|
+
green
|
77
|
+
height
|
78
|
+
hue
|
79
|
+
image
|
80
|
+
image_mode
|
81
|
+
key
|
82
|
+
key_code
|
83
|
+
key_pressed
|
84
|
+
key_pressed?
|
85
|
+
key_released
|
86
|
+
key_typed
|
87
|
+
lerp_color
|
88
|
+
light_falloff
|
89
|
+
light_specular
|
90
|
+
lights
|
91
|
+
line
|
92
|
+
load_bytes
|
93
|
+
load_font
|
94
|
+
load_image
|
95
|
+
load_pixels
|
96
|
+
load_shader
|
97
|
+
load_shape
|
98
|
+
load_strings
|
99
|
+
load_table
|
100
|
+
load_xml
|
101
|
+
model_x
|
102
|
+
model_y
|
103
|
+
model_z
|
104
|
+
mouse_button
|
105
|
+
mouse_clicked
|
106
|
+
mouse_dragged
|
107
|
+
mouse_moved
|
108
|
+
mouse_pressed
|
109
|
+
mouse_pressed?
|
110
|
+
mouse_released
|
111
|
+
mouse_x
|
112
|
+
mouse_y
|
113
|
+
no_cursor
|
114
|
+
no_fill
|
115
|
+
no_lights
|
116
|
+
no_smooth
|
117
|
+
no_stroke
|
118
|
+
no_tint
|
119
|
+
noise
|
120
|
+
noise_detail
|
121
|
+
noise_seed
|
122
|
+
normal
|
123
|
+
ortho
|
124
|
+
perspective
|
125
|
+
pixels
|
126
|
+
pmouse_x
|
127
|
+
pmouse_y
|
128
|
+
point
|
129
|
+
point_light
|
130
|
+
pop_matrix
|
131
|
+
print_camera
|
132
|
+
print_matrix
|
133
|
+
print_projection
|
134
|
+
push_matrix
|
135
|
+
quad
|
136
|
+
quadratic_vertex
|
137
|
+
random
|
138
|
+
random_seed
|
139
|
+
rect
|
140
|
+
rect_mode
|
141
|
+
red
|
142
|
+
request_image
|
143
|
+
reset_matrix
|
144
|
+
reset_shader
|
145
|
+
rotate
|
146
|
+
rotate_x
|
147
|
+
rotate_y
|
148
|
+
rotate_z
|
149
|
+
saturation
|
150
|
+
save
|
151
|
+
save_bytes
|
152
|
+
save_frame
|
153
|
+
save_stream
|
154
|
+
save_strings
|
155
|
+
scale
|
156
|
+
screen_x
|
157
|
+
screen_y
|
158
|
+
screen_z
|
159
|
+
select_folder
|
160
|
+
select_input
|
161
|
+
select_output
|
162
|
+
set
|
163
|
+
shader
|
164
|
+
shape
|
165
|
+
shape_mode
|
166
|
+
shear_x
|
167
|
+
shear_y
|
168
|
+
shininess
|
169
|
+
size
|
170
|
+
smooth
|
171
|
+
specular
|
172
|
+
sphere
|
173
|
+
sphere_detail
|
174
|
+
spot_light
|
175
|
+
stroke
|
176
|
+
stroke_cap
|
177
|
+
stroke_join
|
178
|
+
stroke_weight
|
179
|
+
text_align
|
180
|
+
text_ascent
|
181
|
+
text_descent
|
182
|
+
text_font
|
183
|
+
text_leading
|
184
|
+
text_mode
|
185
|
+
text_size
|
186
|
+
text_width
|
187
|
+
texture
|
188
|
+
texture_mode
|
189
|
+
texture_wrap
|
190
|
+
tint
|
191
|
+
translate
|
192
|
+
triangle
|
193
|
+
update_pixels
|
194
|
+
vertex
|
195
|
+
width
|
196
|
+
)
|
197
|
+
|
198
|
+
METHODS.each { |method_string|
|
199
|
+
it "method: #{method_string}" do
|
200
|
+
@processing_sketch.should respond_to(method_string)
|
201
|
+
end
|
202
|
+
}
|
203
|
+
|
204
|
+
after :all do
|
205
|
+
java.lang.System.exit 0
|
206
|
+
end
|
207
|
+
|
208
|
+
end
|
data/spec/deglut_spec.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require_relative '../lib/jruby_art'
|
2
|
+
|
3
|
+
Java::ProcessingFastmath::DeglutLibrary.new.load(JRuby.runtime, false)
|
4
|
+
|
5
|
+
EPSILON = 1.0e-04
|
6
|
+
TO_RADIAN = Math::PI / 180
|
7
|
+
|
8
|
+
describe '#DegLut.sin(-720 .. 720) test' do
|
9
|
+
(-720 .. 720).step(1) do |deg|
|
10
|
+
it "should work #{deg}" do
|
11
|
+
sine = DegLut.sin(deg)
|
12
|
+
expect(sine).to be_within(EPSILON).of(Math.sin(deg * TO_RADIAN))
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
describe '#DegLut.cos(-720 .. 720) test' do
|
19
|
+
(-720 .. 720).step(1) do |deg|
|
20
|
+
it "should work #{deg}" do
|
21
|
+
cosine = DegLut.cos(deg)
|
22
|
+
expect(cosine).to be_within(EPSILON).of(Math.cos(deg * TO_RADIAN))
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# The generated `.rspec` file contains `--require spec_helper` which will cause this
|
4
|
+
# file to always be loaded, without a need to explicitly require it in any files.
|
5
|
+
#
|
6
|
+
# Given that it is always loaded, you are encouraged to keep this file as
|
7
|
+
# light-weight as possible. Requiring heavyweight dependencies from this file
|
8
|
+
# will add to the boot time of your test suite on EVERY test run, even for an
|
9
|
+
# individual file that may not need all of that loaded. Instead, consider making
|
10
|
+
# a separate helper file that requires the additional dependencies and performs
|
11
|
+
# the additional setup, and require it from the spec files that actually need it.
|
12
|
+
#
|
13
|
+
# The `.rspec` file also contains a few flags that are not defaults but that
|
14
|
+
# users commonly want.
|
15
|
+
#
|
16
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
17
|
+
RSpec.configure do |config|
|
18
|
+
# rspec-expectations config goes here. You can use an alternate
|
19
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
20
|
+
# assertions if you prefer.
|
21
|
+
config.expect_with :rspec do |expectations|
|
22
|
+
# This option will default to `true` in RSpec 4. It makes the `description`
|
23
|
+
# and `failure_message` of custom matchers include text for helper methods
|
24
|
+
# defined using `chain`, e.g.:
|
25
|
+
# be_bigger_than(2).and_smaller_than(4).description
|
26
|
+
# # => "be bigger than 2 and smaller than 4"
|
27
|
+
# ...rather than:
|
28
|
+
# # => "be bigger than 2"
|
29
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
30
|
+
end
|
31
|
+
|
32
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
33
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
34
|
+
config.mock_with :rspec do |mocks|
|
35
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
36
|
+
# a real object. This is generally recommended, and will default to
|
37
|
+
# `true` in RSpec 4.
|
38
|
+
mocks.verify_partial_doubles = true
|
39
|
+
end
|
40
|
+
|
41
|
+
# The settings below are suggested to provide a good initial experience
|
42
|
+
# with RSpec, but feel free to customize to your heart's content.
|
43
|
+
=begin
|
44
|
+
# These two settings work together to allow you to limit a spec run
|
45
|
+
# to individual examples or groups you care about by tagging them with
|
46
|
+
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
|
47
|
+
# get run.
|
48
|
+
config.filter_run :focus
|
49
|
+
config.run_all_when_everything_filtered = true
|
50
|
+
|
51
|
+
# Limits the available syntax to the non-monkey patched syntax that is recommended.
|
52
|
+
# For more details, see:
|
53
|
+
# - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
|
54
|
+
# - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
55
|
+
# - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
|
56
|
+
config.disable_monkey_patching!
|
57
|
+
|
58
|
+
# This setting enables warnings. It's recommended, but in some cases may
|
59
|
+
# be too noisy due to issues in dependencies.
|
60
|
+
config.warnings = true
|
61
|
+
|
62
|
+
# Many RSpec users commonly either run the entire suite or an individual
|
63
|
+
# file, and it's useful to allow more verbose output when running an
|
64
|
+
# individual spec file.
|
65
|
+
if config.files_to_run.one?
|
66
|
+
# Use the documentation formatter for detailed output,
|
67
|
+
# unless a formatter has already been configured
|
68
|
+
# (e.g. via a command-line flag).
|
69
|
+
config.default_formatter = 'doc'
|
70
|
+
end
|
71
|
+
|
72
|
+
# Print the 10 slowest examples and example groups at the
|
73
|
+
# end of the spec run, to help surface which specs are running
|
74
|
+
# particularly slow.
|
75
|
+
config.profile_examples = 10
|
76
|
+
|
77
|
+
# Run specs in random order to surface order dependencies. If you find an
|
78
|
+
# order dependency and want to debug it, you can fix the order by providing
|
79
|
+
# the seed, which is printed after each run.
|
80
|
+
# --seed 1234
|
81
|
+
config.order = :random
|
82
|
+
|
83
|
+
# Seed global randomization in this process using the `--seed` CLI option.
|
84
|
+
# Setting this allows you to use `--seed` to deterministically reproduce
|
85
|
+
# test failures related to randomization by passing the same `--seed` value
|
86
|
+
# as the one that triggered the failure.
|
87
|
+
Kernel.srand config.seed
|
88
|
+
=end
|
89
|
+
|
90
|
+
if config.files_to_run.one?
|
91
|
+
# Use the documentation formatter for detailed output,
|
92
|
+
# unless a formatter has already been configured
|
93
|
+
# (e.g. via a command-line flag).
|
94
|
+
config.default_formatter = 'doc'
|
95
|
+
end
|
96
|
+
end
|