ruby-processing 1.0.9 → 1.0.10.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +13 -1
- data/bin/rp5 +8 -2
- data/lib/core/core.jar +0 -0
- data/lib/core/jruby-complete.jar +0 -0
- data/lib/ruby-processing.rb +2 -2
- data/lib/ruby-processing/app.rb +108 -338
- data/lib/ruby-processing/config.rb +6 -0
- data/lib/ruby-processing/helper_methods.rb +120 -0
- data/lib/ruby-processing/library_loader.rb +140 -0
- data/lib/ruby-processing/runner.rb +34 -4
- data/lib/ruby-processing/runners/base.rb +10 -11
- data/lib/ruby-processing/runners/live.rb +1 -1
- data/lib/ruby-processing/runners/run.rb +1 -1
- data/lib/ruby-processing/runners/watch.rb +18 -76
- data/lib/templates/applet/index.html.erb +8 -9
- data/library/control_panel/control_panel.rb +1 -1
- data/library/dxf/library/dxf.jar +0 -0
- data/library/dxf/library/export.txt +1 -0
- data/library/javascript/library/export.txt +3 -1
- data/library/minim/library/export.txt +1 -0
- data/library/minim/library/jl1.0.jar +0 -0
- data/library/minim/library/jsminim.jar +0 -0
- data/library/minim/library/minim-spi.jar +0 -0
- data/library/minim/library/minim.jar +0 -0
- data/library/minim/library/mp3spi1.9.4.jar +0 -0
- data/library/minim/library/tritonus_aos.jar +0 -0
- data/library/minim/library/tritonus_share.jar +0 -0
- data/library/net/library/export.txt +1 -0
- data/library/net/library/net.jar +0 -0
- data/library/opengl/library/export.txt +7 -10
- data/library/opengl/library/gluegen-rt.jar +0 -0
- data/library/opengl/library/jogl.jar +0 -0
- data/library/opengl/library/{libgluegen-rt.so → linux32/libgluegen-rt.so} +0 -0
- data/library/opengl/library/{libjogl.so → linux32/libjogl.so} +0 -0
- data/library/opengl/library/{libjogl_awt.so → linux32/libjogl_awt.so} +0 -0
- data/library/opengl/library/{libjogl_cg.so → linux32/libjogl_cg.so} +0 -0
- data/library/opengl/library/linux64/libgluegen-rt.so +0 -0
- data/library/opengl/library/linux64/libjogl.so +0 -0
- data/library/opengl/library/linux64/libjogl_awt.so +0 -0
- data/library/opengl/library/linux64/libjogl_cg.so +0 -0
- data/library/opengl/library/{libgluegen-rt.jnilib → macosx/libgluegen-rt.jnilib} +0 -0
- data/library/opengl/library/{libjogl.jnilib → macosx/libjogl.jnilib} +0 -0
- data/library/opengl/library/{libjogl_awt.jnilib → macosx/libjogl_awt.jnilib} +0 -0
- data/library/opengl/library/{libjogl_cg.jnilib → macosx/libjogl_cg.jnilib} +0 -0
- data/library/opengl/library/opengl.jar +0 -0
- data/library/opengl/library/{gluegen-rt.dll → windows32/gluegen-rt.dll} +0 -0
- data/library/opengl/library/{jogl.dll → windows32/jogl.dll} +0 -0
- data/library/opengl/library/{jogl_awt.dll → windows32/jogl_awt.dll} +0 -0
- data/library/opengl/library/{jogl_cg.dll → windows32/jogl_cg.dll} +0 -0
- data/library/opengl/library/windows64/gluegen-rt.dll +0 -0
- data/library/opengl/library/windows64/jogl.dll +0 -0
- data/library/opengl/library/windows64/jogl_awt.dll +0 -0
- data/library/opengl/library/windows64/jogl_cg.dll +0 -0
- data/library/pdf/library/export.txt +1 -0
- data/library/pdf/library/itext.jar +0 -0
- data/library/pdf/library/pdf.jar +0 -0
- data/library/serial/library/RXTXcomm.jar +0 -0
- data/library/serial/library/export.txt +1 -3
- data/library/serial/library/linux32/librxtxSerial.so +0 -0
- data/library/serial/library/linux64/librxtxSerial.so +0 -0
- data/library/serial/library/macosx/librxtxSerial.jnilib +0 -0
- data/library/serial/library/serial.jar +0 -0
- data/library/serial/library/windows32/rxtxSerial.dll +0 -0
- data/library/serial/library/windows64/rxtxSerial.dll +0 -0
- data/library/video/library/export.txt +1 -0
- data/library/video/library/video.jar +0 -0
- data/samples/{animator.rb → contributed/animator.rb} +0 -0
- data/samples/{bezier_playground.rb → contributed/bezier_playground.rb} +0 -0
- data/samples/{circle_collision.rb → contributed/circle_collision.rb} +0 -0
- data/samples/contributed/drawolver.rb +182 -0
- data/samples/{empathy.rb → contributed/empathy.rb} +7 -7
- data/samples/{fern.rb → contributed/fern.rb} +0 -0
- data/samples/{flight_patterns.rb → contributed/flight_patterns.rb} +0 -0
- data/samples/{full_screen.rb → contributed/full_screen.rb} +0 -0
- data/samples/{getting_started.rb → contributed/getting_started.rb} +0 -0
- data/samples/{gravity.rb → contributed/gravity.rb} +0 -0
- data/samples/{jwishy.rb → contributed/jwishy.rb} +0 -0
- data/samples/{orbit.rb → contributed/orbit.rb} +0 -0
- data/samples/{pong.rb → contributed/pong.rb} +0 -0
- data/samples/{reflection.rb → contributed/reflection.rb} +0 -0
- data/samples/{simple_buffer.rb → contributed/simple_buffer.rb} +0 -0
- data/samples/{tree.rb → contributed/tree.rb} +0 -0
- data/samples/peasy_cam/library/hilbert/hilbert.rb +11 -10
- data/samples/processing_app/3D/camera/move_eye.rb +29 -0
- data/samples/processing_app/3D/form/brick_tower.rb +11 -11
- data/samples/processing_app/3D/form/cubic_grid.rb +51 -0
- data/samples/processing_app/3D/form/icosahedra/icosahedra.rb +76 -0
- data/samples/processing_app/3D/form/icosahedra/icosahedron.rb +116 -0
- data/samples/processing_app/3D/form/icosahedra/shape_3D.rb +25 -0
- data/samples/processing_app/3D/form/primitives.rb +42 -0
- data/samples/processing_app/3D/form/rgb_cube.rb +88 -0
- data/samples/processing_app/3D/form/shape_transform.rb +94 -0
- data/samples/processing_app/3D/form/toroid.rb +130 -0
- data/samples/processing_app/3D/form/vertices.rb +81 -0
- data/samples/processing_app/3D/image/data/eames.jpg +0 -0
- data/samples/processing_app/3D/image/data/ystone08.jpg +0 -0
- data/samples/processing_app/3D/image/explode.rb +56 -0
- data/samples/processing_app/3D/image/extrusion.rb +49 -0
- data/samples/processing_app/3D/image/zoom.rb +83 -0
- data/samples/processing_app/3D/lights/directional.rb +41 -0
- data/samples/processing_app/3D/lights/lights1.rb +39 -0
- data/samples/processing_app/3D/lights/lights2.rb +42 -0
- data/samples/processing_app/3D/lights/reflection.rb +38 -0
- data/samples/processing_app/3D/lights/spot.rb +39 -0
- data/samples/processing_app/3D/textures/data/berlin-1.jpg +0 -0
- data/samples/processing_app/3D/textures/texture1.rb +41 -0
- data/samples/processing_app/3D/textures/texture2.rb +38 -0
- data/samples/processing_app/3D/textures/texture3.rb +68 -0
- data/samples/processing_app/3D/textures/texture_cube.rb +106 -0
- data/samples/processing_app/3D/transform/bird.rb +61 -0
- data/samples/processing_app/3D/transform/birds/bird.rb +87 -0
- data/samples/processing_app/3D/transform/birds/birds.rb +48 -0
- data/samples/processing_app/3D/transform/cubes_in_cube/cube.rb +57 -0
- data/samples/processing_app/3D/transform/cubes_in_cube/cubes_in_cube.rb +102 -0
- data/samples/processing_app/3D/transform/push_pop_cubes.rb +152 -0
- data/samples/processing_app/3D/transform/rotate1.rb +43 -0
- data/samples/processing_app/3D/transform/rotate2.rb +45 -0
- data/samples/processing_app/3D/typography/data/Univers45.vlw +0 -0
- data/samples/processing_app/3D/typography/letter_k.rb +136 -0
- data/samples/processing_app/3D/typography/typing.rb +77 -0
- data/samples/processing_app/basics/form/triangle_strip.rb +19 -19
- data/samples/processing_app/basics/math/distance1.rb +59 -0
- data/samples/processing_app/basics/math/distance2.rb +38 -0
- data/samples/processing_app/basics/math/double_random.rb +38 -0
- data/samples/processing_app/basics/math/graphing_2_d_equation.rb +53 -0
- data/samples/processing_app/basics/math/increment_decrement.rb +59 -0
- data/samples/processing_app/basics/math/modulo.rb +43 -0
- data/samples/processing_app/basics/math/noise_1_d.rb +37 -0
- data/samples/processing_app/basics/math/noise_2_d.rb +47 -0
- data/samples/processing_app/basics/math/noise_3_d.rb +50 -0
- data/samples/processing_app/basics/math/noise_wave.rb +61 -0
- data/samples/processing_app/basics/math/operator_precedence.rb +70 -0
- data/samples/processing_app/basics/math/polar_to_cartesian.rb +44 -0
- data/samples/processing_app/basics/math/random.rb +35 -0
- data/samples/processing_app/basics/math/sine.rb +49 -0
- data/samples/processing_app/basics/math/sine_cosine.rb +60 -0
- data/samples/processing_app/basics/math/sine_wave.rb +62 -0
- data/samples/processing_app/basics/objects/composite_objects.rb +139 -0
- data/samples/processing_app/basics/objects/inheritance.rb +104 -0
- data/samples/processing_app/basics/objects/multiple_constructors.rb +66 -0
- data/samples/processing_app/basics/objects/objects.rb +72 -0
- data/samples/processing_app/basics/shape/data/bot1.svg +160 -0
- data/samples/processing_app/basics/shape/data/usa-wikipedia.svg +452 -0
- data/samples/processing_app/basics/shape/disable_style.rb +36 -0
- data/samples/processing_app/basics/shape/get_child.rb +43 -0
- data/samples/processing_app/basics/shape/load_display_shape.rb +33 -0
- data/samples/processing_app/basics/shape/scale_shape.rb +33 -0
- data/samples/processing_app/basics/structure/coordinates.rb +55 -0
- data/samples/processing_app/basics/structure/create_graphics.rb +39 -0
- data/samples/processing_app/basics/structure/functions.rb +41 -0
- data/samples/processing_app/basics/structure/loop.rb +39 -0
- data/samples/processing_app/basics/structure/noloop.rb +33 -0
- data/samples/processing_app/basics/structure/recursion1.rb +42 -0
- data/samples/processing_app/basics/structure/recursion2.rb +39 -0
- data/samples/processing_app/basics/structure/redraw.rb +36 -0
- data/samples/processing_app/basics/structure/setup_draw.rb +30 -0
- data/samples/processing_app/basics/structure/statements_comments.rb +32 -0
- data/samples/processing_app/basics/structure/width_height.rb +29 -0
- data/samples/processing_app/basics/transform/arm.rb +47 -0
- data/samples/processing_app/basics/transform/rotate.rb +43 -0
- data/samples/processing_app/basics/transform/scale.rb +45 -0
- data/samples/processing_app/basics/transform/translate.rb +41 -0
- data/samples/processing_app/basics/transform/triangle_flower.rb +69 -0
- data/samples/processing_app/basics/typography/data/CourierNew36.vlw +0 -0
- data/samples/processing_app/basics/typography/data/Ziggurat-HTF-Black-32.vlw +0 -0
- data/samples/processing_app/basics/typography/letters.rb +52 -0
- data/samples/processing_app/basics/typography/words.rb +37 -0
- data/samples/processing_app/basics/web/embedded_links.rb +58 -0
- data/samples/processing_app/basics/web/loading_images.rb +25 -0
- metadata +181 -86
- data/lib/patches/JRubyApplet.diff +0 -24
- data/lib/patches/PATCHES.txt +0 -3
- data/lib/patches/PApplet.diff +0 -27
- data/library/minim/license.txt +0 -339
- data/library/minim/version.txt +0 -1
- data/library/opengl/library/gluegen-rt-natives-linux-amd64.jar +0 -0
- data/library/opengl/library/gluegen-rt-natives-linux-i586.jar +0 -0
- data/library/opengl/library/gluegen-rt-natives-macosx-ppc.jar +0 -0
- data/library/opengl/library/gluegen-rt-natives-macosx-universal.jar +0 -0
- data/library/opengl/library/gluegen-rt-natives-windows-amd64.jar +0 -0
- data/library/opengl/library/gluegen-rt-natives-windows-i586.jar +0 -0
- data/library/opengl/library/gluegen-rt.jar.pack.gz +0 -0
- data/library/opengl/library/jogl-natives-linux-amd64.jar +0 -0
- data/library/opengl/library/jogl-natives-linux-i586.jar +0 -0
- data/library/opengl/library/jogl-natives-macosx-ppc.jar +0 -0
- data/library/opengl/library/jogl-natives-macosx-universal.jar +0 -0
- data/library/opengl/library/jogl-natives-windows-amd64.jar +0 -0
- data/library/opengl/library/jogl-natives-windows-i586.jar +0 -0
- data/library/opengl/library/jogl.jar.pack.gz +0 -0
- data/library/pdf/notes.txt +0 -8
- data/library/serial/library/librxtxSerial.jnilib +0 -0
- data/library/serial/library/librxtxSerial.so +0 -0
- data/library/serial/library/rxtxSerial.dll +0 -0
@@ -0,0 +1,120 @@
|
|
1
|
+
module Processing
|
2
|
+
module HelperMethods
|
3
|
+
|
4
|
+
# Nice block method to draw to a buffer.
|
5
|
+
# You can optionally pass it a width, a height, and a renderer.
|
6
|
+
# Takes care of starting and ending the draw for you.
|
7
|
+
def buffer(buf_width=width, buf_height=height, renderer=@render_mode)
|
8
|
+
buf = create_graphics(buf_width, buf_height, renderer)
|
9
|
+
buf.begin_draw
|
10
|
+
yield buf
|
11
|
+
buf.end_draw
|
12
|
+
buf
|
13
|
+
end
|
14
|
+
|
15
|
+
# A nice method to run a given block for a grid.
|
16
|
+
# Lifted from action_coding/Nodebox.
|
17
|
+
def grid(cols, rows, col_size=1, row_size=1)
|
18
|
+
(0...cols*rows).map do |i|
|
19
|
+
x = col_size * (i % cols)
|
20
|
+
y = row_size * i.div(cols)
|
21
|
+
yield x, y
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
# lerp_color takes three or four arguments, in Java that's two
|
26
|
+
# different methods, one regular and one static, so:
|
27
|
+
def lerp_color(*args)
|
28
|
+
args.length > 3 ? self.class.lerp_color(*args) : super(*args)
|
29
|
+
end
|
30
|
+
|
31
|
+
def color(*args)
|
32
|
+
a = args[0]
|
33
|
+
# convert to signed int
|
34
|
+
if args.length == 1 && a.is_a?(Fixnum) && a >= 2**31
|
35
|
+
args = [ a - 2**32 ]
|
36
|
+
end
|
37
|
+
super(*args)
|
38
|
+
end
|
39
|
+
|
40
|
+
# There's just so many functions in Processing,
|
41
|
+
# Here's a convenient way to look for them.
|
42
|
+
def find_method(method_name)
|
43
|
+
reg = Regexp.new("#{method_name}", true)
|
44
|
+
self.methods.sort.select {|meth| reg.match(meth)}
|
45
|
+
end
|
46
|
+
|
47
|
+
# Proxy over a list of Java declared fields that have the same name as
|
48
|
+
# some methods. Add to this list as needed.
|
49
|
+
def proxy_java_fields
|
50
|
+
@declared_fields = {}
|
51
|
+
fields = %w(sketchPath key frameRate frame)
|
52
|
+
fields.each {|f| @declared_fields[f] = java_class.declared_field(f) }
|
53
|
+
end
|
54
|
+
|
55
|
+
# By default, your sketch path is the folder that your sketch is in.
|
56
|
+
# If you'd like to do something fancy, feel free.
|
57
|
+
def set_sketch_path(path=nil)
|
58
|
+
field = @declared_fields['sketchPath']
|
59
|
+
field.set_value(java_self, path || SKETCH_ROOT)
|
60
|
+
end
|
61
|
+
|
62
|
+
|
63
|
+
|
64
|
+
# Fix java conversion problems getting the last key
|
65
|
+
# If it's ASCII, return the character, otherwise the integer
|
66
|
+
def key
|
67
|
+
int = @declared_fields['key'].value(java_self)
|
68
|
+
int < 256 ? int.chr : int
|
69
|
+
end
|
70
|
+
|
71
|
+
# Provide a convenient handle for the Java-space version of self.
|
72
|
+
def java_self
|
73
|
+
@java_self ||= Java.ruby_to_java self
|
74
|
+
end
|
75
|
+
|
76
|
+
|
77
|
+
# Get the sketch path
|
78
|
+
def sketch_path
|
79
|
+
@declared_fields['sketchPath'].value(java_self)
|
80
|
+
end
|
81
|
+
|
82
|
+
# Fields that should be made accessible as under_scored.
|
83
|
+
def mouse_x; mouseX; end
|
84
|
+
def mouse_y; mouseY; end
|
85
|
+
def pmouse_x; pmouseX; end
|
86
|
+
def pmouse_y; pmouseY; end
|
87
|
+
def frame_count; frameCount; end
|
88
|
+
def mouse_button; mouseButton; end
|
89
|
+
def key_code; keyCode; end
|
90
|
+
|
91
|
+
|
92
|
+
# Ensure that load_strings returns a real Ruby array
|
93
|
+
def load_strings(file_or_url)
|
94
|
+
loadStrings(file_or_url).to_a
|
95
|
+
end
|
96
|
+
|
97
|
+
# Writes an array of strings to a file, one line per string.
|
98
|
+
# This file is saved to the sketch's data folder
|
99
|
+
def save_strings(filename, strings)
|
100
|
+
saveStrings(filename, [strings].flatten.to_java(:String))
|
101
|
+
end
|
102
|
+
|
103
|
+
# frame_rate needs to support reading and writing
|
104
|
+
def frame_rate(fps = nil)
|
105
|
+
return @declared_fields['frameRate'].value(java_self) unless fps
|
106
|
+
super(fps)
|
107
|
+
end
|
108
|
+
|
109
|
+
# Is the mouse pressed for this frame?
|
110
|
+
def mouse_pressed?
|
111
|
+
Java.java_to_primitive(java_class.field("mousePressed").value(java_object))
|
112
|
+
end
|
113
|
+
|
114
|
+
# Is a key pressed for this frame?
|
115
|
+
def key_pressed?
|
116
|
+
Java.java_to_primitive(java_class.field("keyPressed").value(java_object))
|
117
|
+
end
|
118
|
+
|
119
|
+
end
|
120
|
+
end
|
@@ -0,0 +1,140 @@
|
|
1
|
+
module Processing
|
2
|
+
class LibraryLoader
|
3
|
+
attr_reader :sketchbook_library_path
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
@sketchbook_library_path = File.join(find_sketchbook_path || "", "libraries")
|
7
|
+
@loaded_libraries = Hash.new(false)
|
8
|
+
end
|
9
|
+
|
10
|
+
# Detect if a library has been loaded (for conditional loading)
|
11
|
+
def library_loaded?(library_name)
|
12
|
+
@loaded_libraries[library_name.to_sym]
|
13
|
+
end
|
14
|
+
|
15
|
+
# Load a list of Ruby or Java libraries (in that order)
|
16
|
+
# Usage: load_libraries :opengl, :boids
|
17
|
+
#
|
18
|
+
# If a library is put into a 'library' folder next to the sketch it will
|
19
|
+
# be used instead of the library that ships with Ruby-Processing.
|
20
|
+
def load_libraries(*args)
|
21
|
+
args.each do |lib|
|
22
|
+
loaded = load_ruby_library(lib) || load_java_library(lib)
|
23
|
+
raise LoadError.new "no such file to load -- #{lib}" if !loaded
|
24
|
+
end
|
25
|
+
end
|
26
|
+
alias :load_library :load_libraries
|
27
|
+
|
28
|
+
# For pure ruby libraries.
|
29
|
+
# The library should have an initialization ruby file
|
30
|
+
# of the same name as the library folder.
|
31
|
+
def load_ruby_library(library_name)
|
32
|
+
library_name = library_name.to_sym
|
33
|
+
return true if @loaded_libraries[library_name]
|
34
|
+
if Processing.online?
|
35
|
+
begin
|
36
|
+
return @loaded_libraries[library_name] = (require "library/#{library_name}/#{library_name}")
|
37
|
+
rescue LoadError => e
|
38
|
+
return false
|
39
|
+
end
|
40
|
+
else
|
41
|
+
path = get_library_path(library_name, "rb")
|
42
|
+
return false unless path
|
43
|
+
return @loaded_libraries[library_name] = (require "#{path}/#{library_name}")
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
# For pure java libraries, such as the ones that are available
|
49
|
+
# on this page: http://processing.org/reference/libraries/index.html
|
50
|
+
#
|
51
|
+
# P.S. -- Loading libraries which include native code needs to
|
52
|
+
# hack the Java ClassLoader, so that you don't have to
|
53
|
+
# futz with your PATH. But it's probably bad juju.
|
54
|
+
def load_java_library(library_name)
|
55
|
+
library_name = library_name.to_sym
|
56
|
+
return true if @loaded_libraries[library_name]
|
57
|
+
if Processing.online?
|
58
|
+
return @loaded_libraries[library_name] = !!(JRUBY_APPLET.get_parameter("archive").match(%r(#{library_name})))
|
59
|
+
end
|
60
|
+
path = get_library_path(library_name, "jar")
|
61
|
+
jars = Dir["#{path}/*.jar"]
|
62
|
+
return false if jars.empty?
|
63
|
+
jars.each {|jar| require jar }
|
64
|
+
|
65
|
+
platform_specific_library_paths = get_platform_specific_library_paths(path)
|
66
|
+
platform_specific_library_paths = platform_specific_library_paths.select do |path|
|
67
|
+
test(?d, path) && !Dir.glob(File.join(path, "*.{so,dll,jnilib}")).empty?
|
68
|
+
end
|
69
|
+
|
70
|
+
if !platform_specific_library_paths.empty?
|
71
|
+
platform_specific_library_paths << java.lang.System.getProperty("java.library.path")
|
72
|
+
new_library_path = platform_specific_library_paths.join(java.io.File.pathSeparator)
|
73
|
+
|
74
|
+
java.lang.System.setProperty("java.library.path", new_library_path)
|
75
|
+
|
76
|
+
field = java.lang.Class.for_name("java.lang.ClassLoader").get_declared_field("sys_paths")
|
77
|
+
if field
|
78
|
+
field.accessible = true
|
79
|
+
field.set(java.lang.Class.for_name("java.lang.System").get_class_loader, nil)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
return @loaded_libraries[library_name] = true
|
83
|
+
end
|
84
|
+
|
85
|
+
def get_platform_specific_library_paths(basename)
|
86
|
+
bits = "32"
|
87
|
+
if java.lang.System.getProperty("sun.arch.data.model") == "64" ||
|
88
|
+
java.lang.System.getProperty("java.vm.name").index("64")
|
89
|
+
bits = "64"
|
90
|
+
end
|
91
|
+
|
92
|
+
match_string, platform = {"Mac" => "macosx", "Linux" => "linux", "Windows" => "windows" }.detect do |string, platform_|
|
93
|
+
java.lang.System.getProperty("os.name").index(string)
|
94
|
+
end
|
95
|
+
platform ||= "other"
|
96
|
+
[ platform, platform+bits ].collect { |p| File.join(basename, p) }
|
97
|
+
end
|
98
|
+
|
99
|
+
protected
|
100
|
+
|
101
|
+
def find_sketchbook_path
|
102
|
+
preferences_paths = []
|
103
|
+
sketchbook_paths = []
|
104
|
+
if sketchbook_path = CONFIG["sketchbook_path"]
|
105
|
+
return File.expand_path(sketchbook_path)
|
106
|
+
else
|
107
|
+
["Application Data/Processing", "AppData/Roaming/Processing",
|
108
|
+
"Library/Processing", "Documents/Processing",
|
109
|
+
".processing", "sketchbook"].each do |prefix|
|
110
|
+
path = "#{ENV["HOME"]}/#{prefix}"
|
111
|
+
pref_path = path+"/preferences.txt"
|
112
|
+
if test(?f, pref_path)
|
113
|
+
preferences_paths << pref_path
|
114
|
+
end
|
115
|
+
if test(?d, path)
|
116
|
+
sketchbook_paths << path
|
117
|
+
end
|
118
|
+
end
|
119
|
+
if !preferences_paths.empty?
|
120
|
+
matched_lines = File.readlines(preferences_paths.first).grep(/^sketchbook\.path=(.+)/) { $1 }
|
121
|
+
sketchbook_path = matched_lines.first
|
122
|
+
else
|
123
|
+
sketchbook_path = sketchbook_paths.first
|
124
|
+
end
|
125
|
+
return sketchbook_path
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
def get_library_path(library_name, extension)
|
130
|
+
[ "#{SKETCH_ROOT}/library/#{library_name}",
|
131
|
+
"#{RP5_ROOT}/library/#{library_name}/library",
|
132
|
+
"#{RP5_ROOT}/library/#{library_name}",
|
133
|
+
"#{@sketchbook_library_path}/#{library_name}/library",
|
134
|
+
"#{@sketchbook_library_path}/#{library_name}"
|
135
|
+
].detect do |path|
|
136
|
+
File.exists?("#{path}/#{library_name}.#{extension}")
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'ostruct'
|
2
2
|
require 'fileutils'
|
3
|
+
require 'ruby-processing/config'
|
3
4
|
|
4
5
|
module Processing
|
5
6
|
|
@@ -8,16 +9,40 @@ module Processing
|
|
8
9
|
class Runner
|
9
10
|
|
10
11
|
HELP_MESSAGE = <<-EOS
|
12
|
+
Version: #{Processing::VERSION}
|
11
13
|
|
12
14
|
Ruby-Processing is a little shim between Processing and JRuby that helps
|
13
15
|
you create sketches of code art.
|
14
16
|
|
15
17
|
Usage:
|
16
|
-
rp5 [run | watch | live | create | app | applet | unpack] path/to/sketch
|
18
|
+
rp5 [run | watch | live | create [width height] | app | applet | unpack] path/to/sketch
|
19
|
+
|
20
|
+
run: run sketch once
|
21
|
+
watch: watch for changes on the file and relaunch it on the fly
|
22
|
+
live: launch sketch and give an interactive IRB shell
|
23
|
+
create: create new sketch. Use --bare to generate simpler sketches without a class
|
24
|
+
app: create an application version of the sketch
|
25
|
+
applet: create an applet version of the sketch
|
26
|
+
unpack: unpack samples or library
|
27
|
+
|
28
|
+
Common options:
|
29
|
+
--jruby: passed, use the installed version of jruby, instead of
|
30
|
+
our vendored jarred one (useful for gems).
|
31
|
+
|
32
|
+
Configuration file:
|
33
|
+
A YAML configuration file is located at #{Processing::CONFIG_FILE_PATH}
|
34
|
+
|
35
|
+
Possible options are:
|
36
|
+
|
37
|
+
java_args: pass additionnals arguments to Java VM upon launching.
|
38
|
+
Useful for increasing available memory (for example:
|
39
|
+
-Xms256m -Xmx256m) or force 32 bits mode (-d32).
|
40
|
+
sketchbook_path: specify Processing sketchbook path to load additionnal
|
41
|
+
libraries
|
17
42
|
|
18
43
|
Examples:
|
19
44
|
rp5 unpack samples
|
20
|
-
rp5 run samples/jwishy.rb
|
45
|
+
rp5 run samples/contributed/jwishy.rb
|
21
46
|
rp5 create some_new_sketch --bare 640 480
|
22
47
|
rp5 watch some_new_sketch.rb
|
23
48
|
rp5 applet some_new_sketch.rb
|
@@ -137,8 +162,13 @@ module Processing
|
|
137
162
|
# then type them into a java_args.txt in your data directory next to your sketch.
|
138
163
|
def discover_java_args(sketch)
|
139
164
|
arg_file = "#{File.dirname(sketch)}/data/java_args.txt"
|
140
|
-
args =
|
141
|
-
args +=
|
165
|
+
args = []
|
166
|
+
args += dock_icon
|
167
|
+
if File.exists?(arg_file)
|
168
|
+
args += File.read(arg_file).split(/\s+/)
|
169
|
+
elsif CONFIG["java_args"]
|
170
|
+
args += CONFIG["java_args"].split(/\s+/)
|
171
|
+
end
|
142
172
|
args.map! {|arg| "-J#{arg}" } if @options.jruby
|
143
173
|
args
|
144
174
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
$LOAD_PATH << File.expand_path(File.dirname(__FILE__) + "/../../")
|
2
|
-
SKETCH_PATH = ARGV.shift
|
2
|
+
SKETCH_PATH = ARGV.shift unless defined? SKETCH_PATH
|
3
3
|
SKETCH_ROOT = File.dirname(SKETCH_PATH) unless defined? SKETCH_ROOT
|
4
4
|
|
5
5
|
require 'ruby-processing'
|
@@ -7,7 +7,7 @@ require 'ruby-processing/app'
|
|
7
7
|
|
8
8
|
|
9
9
|
module Processing
|
10
|
-
|
10
|
+
|
11
11
|
# For use with "bare" sketches that don't want to define a class or methods
|
12
12
|
SKETCH_TEMPLATE = <<-EOS
|
13
13
|
class Sketch < Processing::App
|
@@ -22,26 +22,25 @@ module Processing
|
|
22
22
|
<% end %>
|
23
23
|
end
|
24
24
|
EOS
|
25
|
-
|
25
|
+
|
26
26
|
# This method is the common entry point to run a sketch, bare or complete.
|
27
27
|
def self.load_and_run_sketch
|
28
28
|
source = self.read_sketch_source
|
29
29
|
has_sketch = !!source.match(/^[^#]*< Processing::App/)
|
30
30
|
has_methods = !!source.match(/^[^#]*(def\s+setup|def\s+draw)/)
|
31
|
-
|
31
|
+
|
32
32
|
if has_sketch
|
33
33
|
load SKETCH_PATH
|
34
34
|
Processing::App.sketch_class.new if !$app
|
35
|
-
return
|
36
35
|
else
|
37
36
|
require 'erb'
|
38
37
|
code = ERB.new(SKETCH_TEMPLATE).result(binding)
|
39
|
-
Object.class_eval code, SKETCH_PATH,
|
40
|
-
Processing::App.sketch_class.new
|
38
|
+
Object.class_eval code, SKETCH_PATH, -1
|
39
|
+
Processing::App.sketch_class.new
|
41
40
|
end
|
42
41
|
end
|
43
|
-
|
44
|
-
|
42
|
+
|
43
|
+
|
45
44
|
# Read in the sketch source code. Needs to work both online and offline.
|
46
45
|
def self.read_sketch_source
|
47
46
|
if Processing.online?
|
@@ -59,5 +58,5 @@ module Processing
|
|
59
58
|
end
|
60
59
|
source
|
61
60
|
end
|
62
|
-
|
63
|
-
end
|
61
|
+
|
62
|
+
end
|
@@ -8,10 +8,8 @@ module Processing
|
|
8
8
|
|
9
9
|
# Sic a new Processing::Watcher on the sketch
|
10
10
|
def initialize
|
11
|
-
|
11
|
+
reload_files_to_watch
|
12
12
|
@time = Time.now
|
13
|
-
# Doesn't work well enough for now.
|
14
|
-
# record_state_of_ruby
|
15
13
|
start_watching
|
16
14
|
end
|
17
15
|
|
@@ -19,22 +17,18 @@ module Processing
|
|
19
17
|
# Kicks off a thread to watch the sketch, reloading Ruby-Processing
|
20
18
|
# and restarting the sketch whenever it changes.
|
21
19
|
def start_watching
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
GC.start
|
32
|
-
@runner = Thread.start { report_errors { Processing.load_and_run_sketch } }
|
33
|
-
end
|
34
|
-
sleep 0.33
|
20
|
+
start_runner
|
21
|
+
loop do
|
22
|
+
if @files.detect { |file| File.exists?(file) && File.stat(file).mtime > @time }
|
23
|
+
puts "reloading sketch..."
|
24
|
+
$app && $app.close
|
25
|
+
@time = Time.now
|
26
|
+
GC.start
|
27
|
+
start_runner
|
28
|
+
reload_files_to_watch
|
35
29
|
end
|
30
|
+
sleep 0.33
|
36
31
|
end
|
37
|
-
thread.join
|
38
32
|
end
|
39
33
|
|
40
34
|
# Convenience function to report errors when loading and running a sketch,
|
@@ -47,70 +41,18 @@ module Processing
|
|
47
41
|
puts e.backtrace.join("\n")
|
48
42
|
end
|
49
43
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
return unless app
|
56
|
-
app.no_loop
|
57
|
-
# Wait for the animation thread to finish rendering
|
58
|
-
sleep 0.075
|
59
|
-
app.close
|
60
|
-
constant_names = app.class.to_s.split(/::/)
|
61
|
-
app_class_name = constant_names.pop
|
62
|
-
obj = constant_names.inject(Object) {|o, name| o.send(:const_get, name) }
|
63
|
-
obj.send(:remove_const, app_class_name)
|
64
|
-
end
|
65
|
-
|
66
|
-
# The following methods were intended to make the watcher clean up all code
|
67
|
-
# loaded in from the sketch, gems, etc, and have them be reloaded properly
|
68
|
-
# when the sketch is.... but it seems that this is neither a very good idea
|
69
|
-
# or a very possible one. If you can make the scheme work, please do,
|
70
|
-
# otherwise the following methods will probably be removed soonish.
|
71
|
-
|
72
|
-
# Do the best we can to take a picture of the current Ruby interpreter.
|
73
|
-
# For now, this means top-level constants and loaded .rb files.
|
74
|
-
def record_state_of_ruby
|
75
|
-
@saved_constants = Object.send(:constants).dup
|
76
|
-
@saved_load_paths = $LOAD_PATH.dup
|
77
|
-
@saved_features = $LOADED_FEATURES.dup
|
78
|
-
@saved_globals = Kernel.global_variables.dup
|
79
|
-
end
|
80
|
-
|
81
|
-
|
82
|
-
# Try to go back to the recorded Ruby state.
|
83
|
-
def rewind_to_recorded_state
|
84
|
-
new_constants = Object.send(:constants).reject {|c| @saved_constants.include?(c) }
|
85
|
-
new_load_paths = $LOAD_PATH.reject {|p| @saved_load_paths.include?(p) }
|
86
|
-
new_features = $LOADED_FEATURES.reject {|f| @saved_features.include?(f) }
|
87
|
-
new_globals = Kernel.global_variables.reject {|g| @saved_globals.include?(g) }
|
88
|
-
|
89
|
-
Processing::App.recursively_remove_constants(Object, new_constants)
|
90
|
-
new_load_paths.each {|p| $LOAD_PATH.delete(p) }
|
91
|
-
new_features.each {|f| $LOADED_FEATURES.delete(f) }
|
92
|
-
new_globals.each do |g|
|
93
|
-
begin
|
94
|
-
eval("#{g} = nil") # There's no way to undef a global variable in Ruby
|
95
|
-
rescue NameError => e
|
96
|
-
# Some globals are read-only, and we can't set them to nil.
|
44
|
+
def start_runner
|
45
|
+
@runner.kill if @runner && @runner.alive?
|
46
|
+
@runner = Thread.start do
|
47
|
+
report_errors do
|
48
|
+
Processing.load_and_run_sketch
|
97
49
|
end
|
98
50
|
end
|
99
51
|
end
|
100
52
|
|
101
|
-
|
102
|
-
|
103
|
-
def recursively_remove_constants(base, constant_names)
|
104
|
-
constants = constant_names.map {|name| base.const_get(name) }
|
105
|
-
constants.each_with_index do |c, i|
|
106
|
-
java_obj = Java::JavaLang::Object
|
107
|
-
constants[i] = constant_names[i] = nil if c.respond_to?(:ancestors) && c.ancestors.include?(java_obj)
|
108
|
-
constants[i] = nil if !c.is_a?(Class) && !c.is_a?(Module)
|
109
|
-
end
|
110
|
-
constants.each {|c| recursively_remove_constants(c, c.constants) if c }
|
111
|
-
constant_names.each {|name| base.send(:remove_const, name.to_sym) if name }
|
53
|
+
def reload_files_to_watch
|
54
|
+
@files = ([SKETCH_PATH] + Dir.glob(File.dirname(SKETCH_PATH) + "/*.rb")).uniq
|
112
55
|
end
|
113
|
-
|
114
56
|
end
|
115
57
|
end
|
116
58
|
|