ruby-processing 1.0.9 → 1.0.10.1

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.
Files changed (193) hide show
  1. data/CHANGELOG +13 -1
  2. data/bin/rp5 +8 -2
  3. data/lib/core/core.jar +0 -0
  4. data/lib/core/jruby-complete.jar +0 -0
  5. data/lib/ruby-processing.rb +2 -2
  6. data/lib/ruby-processing/app.rb +108 -338
  7. data/lib/ruby-processing/config.rb +6 -0
  8. data/lib/ruby-processing/helper_methods.rb +120 -0
  9. data/lib/ruby-processing/library_loader.rb +140 -0
  10. data/lib/ruby-processing/runner.rb +34 -4
  11. data/lib/ruby-processing/runners/base.rb +10 -11
  12. data/lib/ruby-processing/runners/live.rb +1 -1
  13. data/lib/ruby-processing/runners/run.rb +1 -1
  14. data/lib/ruby-processing/runners/watch.rb +18 -76
  15. data/lib/templates/applet/index.html.erb +8 -9
  16. data/library/control_panel/control_panel.rb +1 -1
  17. data/library/dxf/library/dxf.jar +0 -0
  18. data/library/dxf/library/export.txt +1 -0
  19. data/library/javascript/library/export.txt +3 -1
  20. data/library/minim/library/export.txt +1 -0
  21. data/library/minim/library/jl1.0.jar +0 -0
  22. data/library/minim/library/jsminim.jar +0 -0
  23. data/library/minim/library/minim-spi.jar +0 -0
  24. data/library/minim/library/minim.jar +0 -0
  25. data/library/minim/library/mp3spi1.9.4.jar +0 -0
  26. data/library/minim/library/tritonus_aos.jar +0 -0
  27. data/library/minim/library/tritonus_share.jar +0 -0
  28. data/library/net/library/export.txt +1 -0
  29. data/library/net/library/net.jar +0 -0
  30. data/library/opengl/library/export.txt +7 -10
  31. data/library/opengl/library/gluegen-rt.jar +0 -0
  32. data/library/opengl/library/jogl.jar +0 -0
  33. data/library/opengl/library/{libgluegen-rt.so → linux32/libgluegen-rt.so} +0 -0
  34. data/library/opengl/library/{libjogl.so → linux32/libjogl.so} +0 -0
  35. data/library/opengl/library/{libjogl_awt.so → linux32/libjogl_awt.so} +0 -0
  36. data/library/opengl/library/{libjogl_cg.so → linux32/libjogl_cg.so} +0 -0
  37. data/library/opengl/library/linux64/libgluegen-rt.so +0 -0
  38. data/library/opengl/library/linux64/libjogl.so +0 -0
  39. data/library/opengl/library/linux64/libjogl_awt.so +0 -0
  40. data/library/opengl/library/linux64/libjogl_cg.so +0 -0
  41. data/library/opengl/library/{libgluegen-rt.jnilib → macosx/libgluegen-rt.jnilib} +0 -0
  42. data/library/opengl/library/{libjogl.jnilib → macosx/libjogl.jnilib} +0 -0
  43. data/library/opengl/library/{libjogl_awt.jnilib → macosx/libjogl_awt.jnilib} +0 -0
  44. data/library/opengl/library/{libjogl_cg.jnilib → macosx/libjogl_cg.jnilib} +0 -0
  45. data/library/opengl/library/opengl.jar +0 -0
  46. data/library/opengl/library/{gluegen-rt.dll → windows32/gluegen-rt.dll} +0 -0
  47. data/library/opengl/library/{jogl.dll → windows32/jogl.dll} +0 -0
  48. data/library/opengl/library/{jogl_awt.dll → windows32/jogl_awt.dll} +0 -0
  49. data/library/opengl/library/{jogl_cg.dll → windows32/jogl_cg.dll} +0 -0
  50. data/library/opengl/library/windows64/gluegen-rt.dll +0 -0
  51. data/library/opengl/library/windows64/jogl.dll +0 -0
  52. data/library/opengl/library/windows64/jogl_awt.dll +0 -0
  53. data/library/opengl/library/windows64/jogl_cg.dll +0 -0
  54. data/library/pdf/library/export.txt +1 -0
  55. data/library/pdf/library/itext.jar +0 -0
  56. data/library/pdf/library/pdf.jar +0 -0
  57. data/library/serial/library/RXTXcomm.jar +0 -0
  58. data/library/serial/library/export.txt +1 -3
  59. data/library/serial/library/linux32/librxtxSerial.so +0 -0
  60. data/library/serial/library/linux64/librxtxSerial.so +0 -0
  61. data/library/serial/library/macosx/librxtxSerial.jnilib +0 -0
  62. data/library/serial/library/serial.jar +0 -0
  63. data/library/serial/library/windows32/rxtxSerial.dll +0 -0
  64. data/library/serial/library/windows64/rxtxSerial.dll +0 -0
  65. data/library/video/library/export.txt +1 -0
  66. data/library/video/library/video.jar +0 -0
  67. data/samples/{animator.rb → contributed/animator.rb} +0 -0
  68. data/samples/{bezier_playground.rb → contributed/bezier_playground.rb} +0 -0
  69. data/samples/{circle_collision.rb → contributed/circle_collision.rb} +0 -0
  70. data/samples/contributed/drawolver.rb +182 -0
  71. data/samples/{empathy.rb → contributed/empathy.rb} +7 -7
  72. data/samples/{fern.rb → contributed/fern.rb} +0 -0
  73. data/samples/{flight_patterns.rb → contributed/flight_patterns.rb} +0 -0
  74. data/samples/{full_screen.rb → contributed/full_screen.rb} +0 -0
  75. data/samples/{getting_started.rb → contributed/getting_started.rb} +0 -0
  76. data/samples/{gravity.rb → contributed/gravity.rb} +0 -0
  77. data/samples/{jwishy.rb → contributed/jwishy.rb} +0 -0
  78. data/samples/{orbit.rb → contributed/orbit.rb} +0 -0
  79. data/samples/{pong.rb → contributed/pong.rb} +0 -0
  80. data/samples/{reflection.rb → contributed/reflection.rb} +0 -0
  81. data/samples/{simple_buffer.rb → contributed/simple_buffer.rb} +0 -0
  82. data/samples/{tree.rb → contributed/tree.rb} +0 -0
  83. data/samples/peasy_cam/library/hilbert/hilbert.rb +11 -10
  84. data/samples/processing_app/3D/camera/move_eye.rb +29 -0
  85. data/samples/processing_app/3D/form/brick_tower.rb +11 -11
  86. data/samples/processing_app/3D/form/cubic_grid.rb +51 -0
  87. data/samples/processing_app/3D/form/icosahedra/icosahedra.rb +76 -0
  88. data/samples/processing_app/3D/form/icosahedra/icosahedron.rb +116 -0
  89. data/samples/processing_app/3D/form/icosahedra/shape_3D.rb +25 -0
  90. data/samples/processing_app/3D/form/primitives.rb +42 -0
  91. data/samples/processing_app/3D/form/rgb_cube.rb +88 -0
  92. data/samples/processing_app/3D/form/shape_transform.rb +94 -0
  93. data/samples/processing_app/3D/form/toroid.rb +130 -0
  94. data/samples/processing_app/3D/form/vertices.rb +81 -0
  95. data/samples/processing_app/3D/image/data/eames.jpg +0 -0
  96. data/samples/processing_app/3D/image/data/ystone08.jpg +0 -0
  97. data/samples/processing_app/3D/image/explode.rb +56 -0
  98. data/samples/processing_app/3D/image/extrusion.rb +49 -0
  99. data/samples/processing_app/3D/image/zoom.rb +83 -0
  100. data/samples/processing_app/3D/lights/directional.rb +41 -0
  101. data/samples/processing_app/3D/lights/lights1.rb +39 -0
  102. data/samples/processing_app/3D/lights/lights2.rb +42 -0
  103. data/samples/processing_app/3D/lights/reflection.rb +38 -0
  104. data/samples/processing_app/3D/lights/spot.rb +39 -0
  105. data/samples/processing_app/3D/textures/data/berlin-1.jpg +0 -0
  106. data/samples/processing_app/3D/textures/texture1.rb +41 -0
  107. data/samples/processing_app/3D/textures/texture2.rb +38 -0
  108. data/samples/processing_app/3D/textures/texture3.rb +68 -0
  109. data/samples/processing_app/3D/textures/texture_cube.rb +106 -0
  110. data/samples/processing_app/3D/transform/bird.rb +61 -0
  111. data/samples/processing_app/3D/transform/birds/bird.rb +87 -0
  112. data/samples/processing_app/3D/transform/birds/birds.rb +48 -0
  113. data/samples/processing_app/3D/transform/cubes_in_cube/cube.rb +57 -0
  114. data/samples/processing_app/3D/transform/cubes_in_cube/cubes_in_cube.rb +102 -0
  115. data/samples/processing_app/3D/transform/push_pop_cubes.rb +152 -0
  116. data/samples/processing_app/3D/transform/rotate1.rb +43 -0
  117. data/samples/processing_app/3D/transform/rotate2.rb +45 -0
  118. data/samples/processing_app/3D/typography/data/Univers45.vlw +0 -0
  119. data/samples/processing_app/3D/typography/letter_k.rb +136 -0
  120. data/samples/processing_app/3D/typography/typing.rb +77 -0
  121. data/samples/processing_app/basics/form/triangle_strip.rb +19 -19
  122. data/samples/processing_app/basics/math/distance1.rb +59 -0
  123. data/samples/processing_app/basics/math/distance2.rb +38 -0
  124. data/samples/processing_app/basics/math/double_random.rb +38 -0
  125. data/samples/processing_app/basics/math/graphing_2_d_equation.rb +53 -0
  126. data/samples/processing_app/basics/math/increment_decrement.rb +59 -0
  127. data/samples/processing_app/basics/math/modulo.rb +43 -0
  128. data/samples/processing_app/basics/math/noise_1_d.rb +37 -0
  129. data/samples/processing_app/basics/math/noise_2_d.rb +47 -0
  130. data/samples/processing_app/basics/math/noise_3_d.rb +50 -0
  131. data/samples/processing_app/basics/math/noise_wave.rb +61 -0
  132. data/samples/processing_app/basics/math/operator_precedence.rb +70 -0
  133. data/samples/processing_app/basics/math/polar_to_cartesian.rb +44 -0
  134. data/samples/processing_app/basics/math/random.rb +35 -0
  135. data/samples/processing_app/basics/math/sine.rb +49 -0
  136. data/samples/processing_app/basics/math/sine_cosine.rb +60 -0
  137. data/samples/processing_app/basics/math/sine_wave.rb +62 -0
  138. data/samples/processing_app/basics/objects/composite_objects.rb +139 -0
  139. data/samples/processing_app/basics/objects/inheritance.rb +104 -0
  140. data/samples/processing_app/basics/objects/multiple_constructors.rb +66 -0
  141. data/samples/processing_app/basics/objects/objects.rb +72 -0
  142. data/samples/processing_app/basics/shape/data/bot1.svg +160 -0
  143. data/samples/processing_app/basics/shape/data/usa-wikipedia.svg +452 -0
  144. data/samples/processing_app/basics/shape/disable_style.rb +36 -0
  145. data/samples/processing_app/basics/shape/get_child.rb +43 -0
  146. data/samples/processing_app/basics/shape/load_display_shape.rb +33 -0
  147. data/samples/processing_app/basics/shape/scale_shape.rb +33 -0
  148. data/samples/processing_app/basics/structure/coordinates.rb +55 -0
  149. data/samples/processing_app/basics/structure/create_graphics.rb +39 -0
  150. data/samples/processing_app/basics/structure/functions.rb +41 -0
  151. data/samples/processing_app/basics/structure/loop.rb +39 -0
  152. data/samples/processing_app/basics/structure/noloop.rb +33 -0
  153. data/samples/processing_app/basics/structure/recursion1.rb +42 -0
  154. data/samples/processing_app/basics/structure/recursion2.rb +39 -0
  155. data/samples/processing_app/basics/structure/redraw.rb +36 -0
  156. data/samples/processing_app/basics/structure/setup_draw.rb +30 -0
  157. data/samples/processing_app/basics/structure/statements_comments.rb +32 -0
  158. data/samples/processing_app/basics/structure/width_height.rb +29 -0
  159. data/samples/processing_app/basics/transform/arm.rb +47 -0
  160. data/samples/processing_app/basics/transform/rotate.rb +43 -0
  161. data/samples/processing_app/basics/transform/scale.rb +45 -0
  162. data/samples/processing_app/basics/transform/translate.rb +41 -0
  163. data/samples/processing_app/basics/transform/triangle_flower.rb +69 -0
  164. data/samples/processing_app/basics/typography/data/CourierNew36.vlw +0 -0
  165. data/samples/processing_app/basics/typography/data/Ziggurat-HTF-Black-32.vlw +0 -0
  166. data/samples/processing_app/basics/typography/letters.rb +52 -0
  167. data/samples/processing_app/basics/typography/words.rb +37 -0
  168. data/samples/processing_app/basics/web/embedded_links.rb +58 -0
  169. data/samples/processing_app/basics/web/loading_images.rb +25 -0
  170. metadata +181 -86
  171. data/lib/patches/JRubyApplet.diff +0 -24
  172. data/lib/patches/PATCHES.txt +0 -3
  173. data/lib/patches/PApplet.diff +0 -27
  174. data/library/minim/license.txt +0 -339
  175. data/library/minim/version.txt +0 -1
  176. data/library/opengl/library/gluegen-rt-natives-linux-amd64.jar +0 -0
  177. data/library/opengl/library/gluegen-rt-natives-linux-i586.jar +0 -0
  178. data/library/opengl/library/gluegen-rt-natives-macosx-ppc.jar +0 -0
  179. data/library/opengl/library/gluegen-rt-natives-macosx-universal.jar +0 -0
  180. data/library/opengl/library/gluegen-rt-natives-windows-amd64.jar +0 -0
  181. data/library/opengl/library/gluegen-rt-natives-windows-i586.jar +0 -0
  182. data/library/opengl/library/gluegen-rt.jar.pack.gz +0 -0
  183. data/library/opengl/library/jogl-natives-linux-amd64.jar +0 -0
  184. data/library/opengl/library/jogl-natives-linux-i586.jar +0 -0
  185. data/library/opengl/library/jogl-natives-macosx-ppc.jar +0 -0
  186. data/library/opengl/library/jogl-natives-macosx-universal.jar +0 -0
  187. data/library/opengl/library/jogl-natives-windows-amd64.jar +0 -0
  188. data/library/opengl/library/jogl-natives-windows-i586.jar +0 -0
  189. data/library/opengl/library/jogl.jar.pack.gz +0 -0
  190. data/library/pdf/notes.txt +0 -8
  191. data/library/serial/library/librxtxSerial.jnilib +0 -0
  192. data/library/serial/library/librxtxSerial.so +0 -0
  193. data/library/serial/library/rxtxSerial.dll +0 -0
data/CHANGELOG CHANGED
@@ -1,3 +1,15 @@
1
+ v1.0.10 Solidifying before Processing 2.0 ...
2
+ * JRuby upgraded to 1.6.4
3
+ * Processing upgraded to 1.5.1
4
+ * load_library now works for Ruby and Java libraries present in the libraries Processing sketchbook
5
+ * test suite created
6
+ * removed ruby-processing specific hex() and shape() methods in favor of Processing ones
7
+ * added some missing methods from Processing: println(), min(), max(), abs(), binary(), nf*(), etc...
8
+ * watcher: watch for *.rb files inside sketch directory
9
+ * linux opengl bugs fixed
10
+ * samples/peasy_cam/hilbert_fractal example now allow the possibility of changing the fractal depth and to more correctly centre the fractal
11
+ * added configuration file in $HOME/.rp5rc to configure java_args and sketchbook_path
12
+
1
13
  v1.0.9 The Yearly Update...
2
14
  * JRuby upgraded to 1.4.0 final.
3
15
  * Fix to allow arguments to be passed to sketches.
@@ -203,4 +215,4 @@ v0.3. First Real Release
203
215
  * Processing::App.current will give you a handle on the app. (Useful
204
216
  in jirb).
205
217
  * samples/jwishy.rb has some new hooks for live coding.
206
- * circle_collision and tree samples added (Joe Holt)
218
+ * circle_collision and tree samples added (Joe Holt)
data/bin/rp5 CHANGED
@@ -1,4 +1,10 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require File.expand_path(File.dirname(__FILE__) + "/../lib/ruby-processing")
4
- Processing::Runner.execute
3
+ file = __FILE__
4
+ if test(?l, file)
5
+ require "pathname"
6
+ file = Pathname.new(file).realpath
7
+ end
8
+
9
+ require File.expand_path(File.dirname(file) + "/../lib/ruby-processing")
10
+ Processing::Runner.execute
data/lib/core/core.jar CHANGED
Binary file
Binary file
@@ -14,7 +14,7 @@ require 'ruby-processing/helpers/numeric'
14
14
 
15
15
  # The top-level namespace, a home for all Ruby-Processing classes.
16
16
  module Processing
17
- VERSION = "1.0.9" unless defined? Processing::VERSION
17
+ VERSION = "1.0.10" unless defined? Processing::VERSION
18
18
 
19
19
  # Are we online -- inside an applet?
20
20
  def self.online?
@@ -34,4 +34,4 @@ module Processing
34
34
  autoload :BaseExporter, 'ruby-processing/exporters/base_exporter'
35
35
  autoload :AppletExporter, 'ruby-processing/exporters/applet_exporter'
36
36
  autoload :ApplicationExporter, 'ruby-processing/exporters/application_exporter'
37
- end
37
+ end
@@ -3,11 +3,19 @@
3
3
  # web applets, going fullscreen and so on.
4
4
 
5
5
  require 'java'
6
+ require 'ruby-processing/config'
7
+ require 'ruby-processing/helper_methods'
8
+ require 'ruby-processing/library_loader'
6
9
 
7
- module Processing
10
+ # Conditionally load core.jar
11
+ require "#{RP5_ROOT}/lib/core/core.jar" unless Processing.online? || Processing.embedded?
12
+
13
+ # Include some processing classes that we'd like to use:
14
+ %w(PShape PImage PGraphics PFont PVector).each do |klass|
15
+ import "processing.core.#{klass}"
16
+ end
8
17
 
9
- # Conditionally load core.jar
10
- require "#{RP5_ROOT}/lib/core/core.jar" unless Processing.online? || Processing.embedded?
18
+ module Processing
11
19
  import "processing.core"
12
20
 
13
21
  # This is the main Ruby-Processing class, and is what you'll
@@ -19,45 +27,42 @@ module Processing
19
27
  # called constantly, for every frame.
20
28
  class App < PApplet
21
29
  include Math
22
-
23
- # Include some processing classes that we'd like to use:
24
- %w(PShape PImage PGraphics PFont PVector).each do |klass|
25
- import "processing.core.#{klass}"
26
- end
30
+ include HelperMethods
27
31
 
28
32
  # Alias some methods for familiarity for Shoes coders.
29
- attr_accessor :frame, :title
33
+ #attr_accessor :frame, :title
30
34
  alias_method :oval, :ellipse
31
35
  alias_method :stroke_width, :stroke_weight
32
36
  alias_method :rgb, :color
33
37
  alias_method :gray, :color
34
38
 
35
- # Watch the definition of these methods, to make sure
36
- # that Processing is able to call them during events.
37
- METHODS_TO_WATCH_FOR = {
38
- :mouse_pressed => :mousePressed,
39
- :mouse_dragged => :mouseDragged,
40
- :mouse_clicked => :mouseClicked,
41
- :mouse_moved => :mouseMoved,
42
- :mouse_released => :mouseReleased,
43
- :key_pressed => :keyPressed,
44
- :key_released => :keyReleased,
45
- :key_typed => :keyTyped
46
- }
47
-
48
39
 
49
40
  # When certain special methods get added to the sketch, we need to let
50
41
  # Processing call them by their expected Java names.
51
42
  def self.method_added(method_name) #:nodoc:
52
- if METHODS_TO_WATCH_FOR.keys.include?(method_name)
53
- alias_method METHODS_TO_WATCH_FOR[method_name], method_name
43
+ # Watch the definition of these methods, to make sure
44
+ # that Processing is able to call them during events.
45
+ methods_to_alias = {
46
+ :mouse_pressed => :mousePressed,
47
+ :mouse_dragged => :mouseDragged,
48
+ :mouse_clicked => :mouseClicked,
49
+ :mouse_moved => :mouseMoved,
50
+ :mouse_released => :mouseReleased,
51
+ :key_pressed => :keyPressed,
52
+ :key_released => :keyReleased,
53
+ :key_typed => :keyTyped
54
+ }
55
+ if methods_to_alias.keys.include?(method_name)
56
+ alias_method methods_to_alias[method_name], method_name
54
57
  end
55
58
  end
56
59
 
57
60
 
58
61
  # Class methods that we should make available in the instance.
59
62
  [:map, :pow, :norm, :lerp, :second, :minute, :hour, :day, :month, :year,
60
- :sq, :constrain, :dist, :blend_color, :degrees, :radians, :mag].each do |meth|
63
+ :sq, :constrain, :dist, :blend_color, :degrees, :radians, :mag, :println,
64
+ :hex, :min, :max, :abs, :binary, :ceil, :nf, :nfc, :nfp, :nfs,
65
+ :norm, :round, :trim, :unbinary, :unhex ].each do |meth|
61
66
  method = <<-EOS
62
67
  def #{meth}(*args)
63
68
  self.class.#{meth}(*args)
@@ -66,9 +71,9 @@ module Processing
66
71
  eval method
67
72
  end
68
73
 
69
-
70
74
  # Handy getters and setters on the class go here:
71
75
  def self.sketch_class; @sketch_class; end
76
+ @@full_screen = false
72
77
  def self.full_screen; @@full_screen = true; end
73
78
  def full_screen?; @@full_screen; end
74
79
 
@@ -80,84 +85,34 @@ module Processing
80
85
  @sketch_class = subclass
81
86
  end
82
87
 
83
-
84
- # Detect if a library has been loaded (for conditional loading)
85
- @@loaded_libraries = Hash.new(false)
86
- def self.library_loaded?(folder)
87
- @@loaded_libraries[folder.to_sym]
88
+ def self.has_slider(*args) #:nodoc:
89
+ raise "has_slider has been replaced with a nicer control_panel library. Check it out."
88
90
  end
89
- def library_loaded?(folder); self.class.library_loaded?(folder); end
90
-
91
-
92
- # Load a list of Ruby or Java libraries (in that order)
93
- # Usage: load_libraries :opengl, :boids
94
- #
95
- # If a library is put into a 'library' folder next to the sketch it will
96
- # be used instead of the library that ships with Ruby-Processing.
97
- def self.load_libraries(*args)
98
- args.each do |lib|
99
- loaded = load_ruby_library(lib) || load_java_library(lib)
100
- raise LoadError.new "no such file to load -- #{lib}" if !loaded
91
+
92
+ @@library_loader = LibraryLoader.new
93
+ class << self
94
+ def load_libraries(*args)
95
+ @@library_loader.load_library(*args)
101
96
  end
102
- end
103
- def self.load_library(*args); self.load_libraries(*args); end
104
-
97
+ alias :load_library :load_libraries
105
98
 
106
- # For pure ruby libraries.
107
- # The library should have an initialization ruby file
108
- # of the same name as the library folder.
109
- def self.load_ruby_library(dir)
110
- dir = dir.to_sym
111
- return true if @@loaded_libraries[dir]
112
- if Processing.online?
113
- begin
114
- return @@loaded_libraries[dir] = (require "library/#{dir}/#{dir}")
115
- rescue LoadError => e
116
- return false
117
- end
99
+ def library_loaded?(library_name)
100
+ @@library_loader.library_loaded?(library_name)
118
101
  end
119
- local_path = "#{SKETCH_ROOT}/library/#{dir}"
120
- gem_path = "#{RP5_ROOT}/library/#{dir}"
121
- path = File.exists?(local_path) ? local_path : gem_path
122
- return false unless (File.exists?("#{path}/#{dir}.rb"))
123
- return @@loaded_libraries[dir] = (require "#{path}/#{dir}")
124
- end
125
102
 
103
+ def load_ruby_library(*args)
104
+ @@library_loader.load_ruby_library(*args)
105
+ end
126
106
 
127
- # For pure java libraries, such as the ones that are available
128
- # on this page: http://processing.org/reference/libraries/index.html
129
- #
130
- # P.S. -- Loading libraries which include native code needs to
131
- # hack the Java ClassLoader, so that you don't have to
132
- # futz with your PATH. But it's probably bad juju.
133
- def self.load_java_library(dir)
134
- dir = dir.to_sym
135
- return true if @@loaded_libraries[dir]
136
- return @@loaded_libraries[dir] = !!(JRUBY_APPLET.get_parameter("archive").match(%r(#{dir}))) if Processing.online?
137
- local_path = "#{SKETCH_ROOT}/library/#{dir}"
138
- gem_path = "#{RP5_ROOT}/library/#{dir}"
139
- path = File.exists?(local_path) ? local_path : gem_path
140
- jars = Dir["#{path}/**/*.jar"]
141
- return false if jars.empty?
142
- jars.each {|jar| require jar }
143
- # Here goes...
144
- library_path = java.lang.System.getProperty("java.library.path")
145
- new_library_path = [path, "#{path}/library", library_path].join(java.io.File.pathSeparator)
146
- java.lang.System.setProperty("java.library.path", new_library_path)
147
- field = java.lang.Class.for_name("java.lang.ClassLoader").get_declared_field("sys_paths")
148
- if field
149
- field.accessible = true
150
- field.set(java.lang.Class.for_name("java.lang.System").get_class_loader, nil)
107
+ def load_java_library(*args)
108
+ @@library_loader.load_java_library(*args)
151
109
  end
152
- return @@loaded_libraries[dir] = true
153
110
  end
154
111
 
155
-
156
- def self.has_slider(*args) #:nodoc:
157
- raise "has_slider has been replaced with a nicer control_panel library. Check it out."
112
+ def library_loaded?(library_name)
113
+ self.class.library_loaded?(library_name)
158
114
  end
159
115
 
160
-
161
116
  # When you make a new sketch, you pass in (optionally),
162
117
  # a width, height, x, y, title, and whether or not you want to
163
118
  # run in full-screen.
@@ -169,53 +124,83 @@ module Processing
169
124
  $app = self
170
125
  proxy_java_fields
171
126
  set_sketch_path unless Processing.online?
172
- # make_accessible_to_the_browser if Processing.online?
173
- default_title = File.basename(SKETCH_PATH).sub(/(\.rb|\.pde)$/, '').titleize
174
- @width = options[:width]
175
- @height = options[:height]
176
- @frame_x = options[:x] || 0
177
- @frame_y = options[:y] || 0
178
- @title = options[:title] || default_title
179
- @render_mode ||= JAVA2D
180
- @@full_screen ||= options[:full_screen]
181
- self.init
182
- determine_how_to_display
127
+ mix_proxy_into_inner_classes
128
+ @started = false
129
+
130
+ java.lang.Thread.default_uncaught_exception_handler = proc do |thread, exception|
131
+ puts(exception.class.to_s)
132
+ puts(exception.message)
133
+ puts(exception.backtrace.collect { |trace| "\t" + trace })
134
+ close
135
+ end
136
+
137
+ # for the list of all available args, see
138
+ # http://processing.googlecode.com/svn/trunk/processing/build/javadoc/core/processing/core/PApplet.html#runSketch%28java.lang.String[],%20processing.core.PApplet%29
139
+ args = []
140
+
141
+ @width, @height = options[:width], options[:height]
142
+
143
+ if @@full_screen || options[:full_screen]
144
+ @@full_screen = true
145
+ args << "--present"
146
+ end
147
+
148
+ @render_mode ||= JAVA2D
149
+
150
+ x = options[:x] || 0
151
+ y = options[:y] || 0
152
+ args << "--location=#{x},#{y}"
153
+
154
+ title = options[:title] || File.basename(SKETCH_PATH).sub(/(\.rb|\.pde)$/, '').titleize
155
+ args << title
156
+ PApplet.run_sketch(args, self)
183
157
  end
184
158
 
159
+ def started?
160
+ @started
161
+ end
162
+
163
+ def hint(*args)
164
+ begin
165
+ super(*args)
166
+ rescue Exception => e
167
+ raise e.cause
168
+ end
169
+ end
185
170
 
186
171
  # Make sure we set the size if we set it before we start the animation thread.
187
172
  def start
188
173
  self.size(@width, @height) if @width && @height
189
- mix_proxy_into_inner_classes
190
174
  super()
191
175
  end
192
176
 
193
-
194
177
  # Provide a loggable string to represent this sketch.
195
178
  def inspect
196
179
  "#<Processing::App:#{self.class}:#{@title}>"
197
180
  end
198
181
 
199
182
 
200
- # By default, your sketch path is the folder that your sketch is in.
201
- # If you'd like to do something fancy, feel free.
202
- def set_sketch_path(path=nil)
203
- field = @declared_fields['sketchPath']
204
- field.set_value(java_self, path || SKETCH_ROOT)
205
- end
206
-
207
-
208
183
  # We override size to support setting full_screen and to keep our
209
184
  # internal @width and @height in line.
210
185
  def size(*args)
211
- args[0], args[1] = *full_screen_dimensions if @@full_screen && !args.empty?
186
+ args[0], args[1] = screenWidth, screenHeight if @@full_screen && !args.empty?
212
187
  w, h, mode = *args
213
188
  @width = w || @width
214
189
  @height = h || @height
215
190
  @render_mode = mode || @render_mode
191
+ @started = true
216
192
  super(*args)
193
+ rescue Exception => e
194
+ raise e.cause
217
195
  end
218
196
 
197
+ def handleDraw()
198
+ super
199
+ rescue Exception => exception
200
+ puts(exception.message)
201
+ puts(exception.backtrace.collect { |trace| "\t" + trace })
202
+ close
203
+ end
219
204
 
220
205
  # Specify what rendering Processing should use, without needing to pass size.
221
206
  def render_mode(mode_const)
@@ -223,225 +208,33 @@ module Processing
223
208
  size(@width, @height, @render_mode)
224
209
  end
225
210
 
226
-
227
- # There's just so many functions in Processing,
228
- # Here's a convenient way to look for them.
229
- def find_method(method_name)
230
- reg = Regexp.new("#{method_name}", true)
231
- self.methods.sort.select {|meth| reg.match(meth)}
232
- end
233
-
234
-
235
- # Nice block method to draw to a buffer.
236
- # You can optionally pass it a width, a height, and a renderer.
237
- # Takes care of starting and ending the draw for you.
238
- def buffer(buf_width=width, buf_height=height, renderer=@render_mode)
239
- buf = create_graphics(buf_width, buf_height, renderer)
240
- buf.begin_draw
241
- yield buf
242
- buf.end_draw
243
- buf
244
- end
245
-
246
-
247
- # A nice method to run a given block for a grid.
248
- # Lifted from action_coding/Nodebox.
249
- def grid(cols, rows, col_size=1, row_size=1)
250
- (0...cols*rows).map do |i|
251
- x = col_size * (i % cols)
252
- y = row_size * i.div(cols)
253
- yield x, y
254
- end
255
- end
256
-
257
- # Shortcut for begin_shape/end_shape pair
258
- def shape(*mode)
259
- begin_shape *mode
260
- yield
261
- end_shape
262
- end
263
-
264
- # Provide a convenient handle for the Java-space version of self.
265
- def java_self
266
- @java_self ||= Java.ruby_to_java self
267
- end
268
-
269
-
270
- # Fix java conversion problems getting the last key
271
- # If it's ASCII, return the character, otherwise the integer
272
- def key
273
- int = @declared_fields['key'].value(java_self)
274
- int < 256 ? int.chr : int
275
- end
276
-
277
-
278
- # Get the sketch path
279
- def sketch_path
280
- @declared_fields['sketchPath'].value(java_self)
281
- end
282
-
283
-
284
- # From ROP. Turns a color hash-string into hexadecimal, for Processing.
285
- def hex(value)
286
- value[1..-1].hex + 0xff000000
287
- end
288
-
289
-
290
- # Fields that should be made accessible as under_scored.
291
- def mouse_x; mouseX; end
292
- def mouse_y; mouseY; end
293
- def pmouse_x; pmouseX; end
294
- def pmouse_y; pmouseY; end
295
- def frame_count; frameCount; end
296
- def mouse_button; mouseButton; end
297
- def key_code; keyCode; end
298
-
299
-
300
- # Ensure that load_strings returns a real Ruby array
301
- def load_strings(file_or_url)
302
- loadStrings(file_or_url).to_a
303
- end
304
-
305
-
306
- # Writes an array of strings to a file, one line per string.
307
- # This file is saved to the sketch's data folder
308
- def save_strings(filename, strings)
309
- saveStrings(filename, [strings].flatten.to_java(:String))
310
- end
311
-
312
-
313
- # frame_rate needs to support reading and writing
314
- def frame_rate(fps = nil)
315
- return @declared_fields['frameRate'].value(java_self) unless fps
316
- super(fps)
317
- end
318
-
319
-
320
- # Is the sketch still displaying with the default size?
321
- def default_size?
322
- @declared_fields['defaultSize'].value(java_self)
323
- end
324
-
325
-
326
- # Is the sketch finished?
327
- def finished?
328
- @declared_fields['finished'].value(java_self)
329
- end
330
-
331
-
332
- # Is the mouse pressed for this frame?
333
- def mouse_pressed?
334
- Java.java_to_primitive(java_class.field("mousePressed").value(java_object))
335
- end
336
-
337
-
338
- # Is a key pressed for this frame?
339
- def key_pressed?
340
- Java.java_to_primitive(java_class.field("keyPressed").value(java_object))
341
- end
342
-
343
-
344
- # lerp_color takes three or four arguments, in Java that's two
345
- # different methods, one regular and one static, so:
346
- def lerp_color(*args)
347
- args.length > 3 ? self.class.lerp_color(*args) : super(*args)
348
- end
349
-
350
-
351
211
  # Cleanly close and shutter a running sketch.
352
212
  def close
353
- $app = nil
213
+ #$app = nil
354
214
  if Processing.online?
355
215
  JRUBY_APPLET.remove(self)
356
- self.destroy
357
216
  else
358
217
  control_panel.remove if respond_to?(:control_panel)
359
- @frame.remove(self) if @frame
360
- self.destroy
361
- @frame.dispose if @frame
218
+ self.dispose
219
+ self.frame.dispose
362
220
  end
363
221
  end
364
222
 
365
223
 
366
- private
367
-
368
- # Proxy over a list of Java declared fields that have the same name as
369
- # some methods. Add to this list as needed.
370
- def proxy_java_fields
371
- @declared_fields = {}
372
- fields = %w(sketchPath key frameRate defaultSize finished)
373
- fields.each {|f| @declared_fields[f] = java_class.declared_field(f) }
374
- end
375
-
224
+ private
376
225
 
377
226
  # Mix the Processing::Proxy into any inner classes defined for the
378
227
  # sketch, attempting to mimic the behavior of Java's inner classes.
379
228
  def mix_proxy_into_inner_classes
380
- unwanted = /Java::ProcessingCore/
229
+
381
230
  klass = Processing::App.sketch_class
382
231
  klass.constants.each do |name|
383
232
  const = klass.const_get name
384
- next if const.class != Class || const.to_s.match(unwanted)
233
+ next if const.class != Class || const.to_s.match(/^Java::/)
385
234
  const.class_eval 'include Processing::Proxy'
386
235
  end
387
236
  end
388
237
 
389
-
390
- # Tests to see which display method should run.
391
- def determine_how_to_display
392
- # Wait for init to get its grey tracksuit on and run a few laps.
393
- sleep 0.02 while default_size? && !finished? && !@@full_screen
394
-
395
- if Processing.online?
396
- display_in_an_applet
397
- elsif full_screen?
398
- display = java.awt.GraphicsEnvironment.local_graphics_environment.default_screen_device
399
- linux = java.lang.System.get_property("os.name") == "Linux"
400
- supported = display.full_screen_supported? || linux
401
- supported ? display_full_screen(display) : display_in_a_window
402
- else
403
- display_in_a_window
404
- end
405
- @done_displaying = true
406
- end
407
-
408
-
409
- def display_full_screen(display)
410
- @frame = java.awt.Frame.new(display.default_configuration)
411
- mode = display.display_mode
412
- @width, @height = *full_screen_dimensions
413
- @frame.set_undecorated true
414
- @frame.set_ignore_repaint true
415
- @frame.set_background java.awt.Color.black
416
- @frame.set_layout java.awt.BorderLayout.new
417
- @frame.add(self, java.awt.BorderLayout::CENTER)
418
- @frame.pack
419
- display.set_full_screen_window @frame
420
- @frame.set_location(0, 0)
421
- @frame.show
422
- self.request_focus
423
- end
424
-
425
-
426
- def display_in_a_window
427
- @frame = javax.swing.JFrame.new(@title)
428
- @frame.set_layout nil
429
- @frame.add self
430
- @frame.pack
431
- @frame.set_resizable false
432
- @frame.set_default_close_operation Processing.embedded? ?
433
- javax.swing.JFrame::DISPOSE_ON_CLOSE : javax.swing.JFrame::EXIT_ON_CLOSE
434
- ins = @frame.get_insets
435
- hpad, vpad = ins.left + ins.right, ins.top + ins.bottom
436
- frame_width = [width, MIN_WINDOW_WIDTH].max + hpad
437
- frame_height = [height, MIN_WINDOW_HEIGHT].max + vpad
438
- @frame.set_size(frame_width, frame_height)
439
- set_bounds((frame_width - hpad - width) / 2.0, (frame_height - vpad - height) / 2.0, width, height)
440
- @frame.set_location(@frame_x, @frame_y)
441
- @frame.show
442
- end
443
-
444
-
445
238
  def display_in_an_applet
446
239
  JRUBY_APPLET.background_color = nil
447
240
  JRUBY_APPLET.double_buffered = false
@@ -451,30 +244,6 @@ module Processing
451
244
  JRUBY_APPLET.on_stop { self.stop }
452
245
  JRUBY_APPLET.on_destroy { self.destroy }
453
246
  end
454
-
455
-
456
- # Grab the dimensions of the main display.
457
- # Some Linux variants don't have the 'display_mode'.
458
- def full_screen_dimensions
459
- screen = java.awt.GraphicsEnvironment.local_graphics_environment.default_screen_device.display_mode
460
- screen = java.awt.Toolkit.default_toolkit.screen_size if !display
461
- return screen.width, screen.height
462
- end
463
-
464
-
465
- # When the net library is included, we make the Ruby interpreter
466
- # accessible to javascript as the 'ruby' variable. From javascript,
467
- # you can call evalScriptlet() to run code against the sketch.
468
- #
469
- # def make_accessible_to_the_browser
470
- # return unless library_loaded?('net')
471
- # field = java.lang.Class.for_name("org.jruby.JRubyApplet").get_declared_field("runtime")
472
- # field.set_accessible true
473
- # ruby = field.get(JRUBY_APPLET)
474
- # window = Java::netscape.javascript.JSObject.get_window(JRUBY_APPLET)
475
- # window.set_member('ruby', ruby)
476
- # end
477
-
478
247
  end # Processing::App
479
248
 
480
249
 
@@ -482,13 +251,14 @@ module Processing
482
251
  # a Processing::App, in order to mimic Java's inner classes, which have
483
252
  # unfettered access to the methods defined in the surrounding class.
484
253
  module Proxy
254
+ include Math
485
255
 
486
256
  # Generate the list of method names that we'd like to proxy for inner classes.
487
257
  # Nothing camelCased, nothing __internal__, just the Processing API.
488
258
  def self.desired_method_names
489
259
  bad_method = /__/ # Internal JRuby methods.
490
260
  unwanted = PApplet.superclass.instance_methods + Object.instance_methods
491
- unwanted -= ['width', 'height', 'cursor']
261
+ unwanted -= ['width', 'height', 'cursor', 'create_image', 'background', 'size', 'resize']
492
262
  methods = Processing::App.public_instance_methods
493
263
  methods.reject {|m| unwanted.include?(m) || bad_method.match(m) }
494
264
  end