ruby-processing 2.4.4 → 2.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (227) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rpextras.jar +0 -0
  3. data/lib/ruby-processing.rb +8 -6
  4. data/lib/ruby-processing/app.rb +54 -67
  5. data/lib/ruby-processing/config.rb +7 -7
  6. data/lib/ruby-processing/exporters/application_exporter.rb +37 -38
  7. data/lib/ruby-processing/exporters/base_exporter.rb +34 -37
  8. data/lib/ruby-processing/exporters/creator.rb +27 -25
  9. data/lib/ruby-processing/helper_methods.rb +18 -22
  10. data/lib/ruby-processing/helpers/numeric.rb +5 -6
  11. data/lib/ruby-processing/helpers/string.rb +11 -20
  12. data/lib/ruby-processing/library_loader.rb +33 -35
  13. data/lib/ruby-processing/runner.rb +118 -65
  14. data/lib/ruby-processing/runners/base.rb +21 -26
  15. data/lib/ruby-processing/runners/live.rb +3 -4
  16. data/lib/ruby-processing/runners/run.rb +1 -3
  17. data/lib/ruby-processing/runners/watch.rb +8 -8
  18. data/lib/ruby-processing/version.rb +1 -1
  19. data/lib/templates/application/lib/args.txt.erb +1 -1
  20. data/lib/templates/application/run.erb +3 -3
  21. data/library/control_panel/control_panel.rb +29 -29
  22. data/library/fastmath/fastmath.rb +3 -0
  23. data/library/file_chooser/file_chooser.rb +11 -13
  24. data/library/vecmath/vecmath.rb +6 -35
  25. data/samples/Rakefile +3 -1
  26. data/samples/configRP5/configRP5.pde +150 -0
  27. data/samples/contributed/Rakefile +6 -6
  28. data/samples/contributed/animator.rb +6 -6
  29. data/samples/contributed/bezier_playground.rb +29 -68
  30. data/samples/contributed/circle_collision.rb +6 -13
  31. data/samples/contributed/elegant_ball.rb +14 -17
  32. data/samples/contributed/empathy.rb +8 -5
  33. data/samples/contributed/fibonacci_sphere.rb +10 -49
  34. data/samples/contributed/full_screen.rb +1 -1
  35. data/samples/contributed/grapher.rb +10 -9
  36. data/samples/contributed/gravity.rb +11 -16
  37. data/samples/contributed/jwishy.rb +18 -20
  38. data/samples/contributed/quadraticvertex.rb +26 -26
  39. data/samples/external_library/java_processing/custom/landscape.rb +6 -4
  40. data/samples/external_library/java_processing/hemesh/twin_iso.rb +69 -71
  41. data/samples/external_library/java_processing/pbox2d/bumpy_surface_noise.rb +57 -0
  42. data/samples/external_library/java_processing/pbox2d/contact_test.rb +23 -0
  43. data/samples/external_library/java_processing/pbox2d/data/java_args.txt +2 -0
  44. data/samples/external_library/java_processing/pbox2d/library/custom_shape/custom_shape.rb +158 -0
  45. data/samples/external_library/java_processing/pbox2d/library/particle_system/particle_system.rb +212 -0
  46. data/samples/external_library/java_processing/pbox2d/library/surface/surface.rb +154 -0
  47. data/samples/external_library/java_processing/pbox2d/liquidy.rb +58 -0
  48. data/samples/external_library/java_processing/pbox2d/polygons.rb +58 -0
  49. data/samples/external_library/java_processing/toxiclibs/library/vbo/vbo.rb +52 -0
  50. data/samples/external_library/java_processing/toxiclibs/model_align.rb +9 -16
  51. data/samples/processing_app/basics/color/color_wheel.rb +1 -1
  52. data/samples/processing_app/basics/form/regular_polygon.rb +2 -2
  53. data/samples/processing_app/basics/form/rgb_cube.rb +2 -2
  54. data/samples/processing_app/basics/form/shape_primitives.rb +1 -1
  55. data/samples/processing_app/basics/form/star.rb +2 -2
  56. data/samples/processing_app/basics/input/clock.rb +21 -16
  57. data/samples/processing_app/basics/input/storing_input.rb +6 -6
  58. data/samples/processing_app/basics/math/additive_wave.rb +1 -1
  59. data/samples/processing_app/basics/math/sine.rb +2 -2
  60. data/samples/processing_app/basics/math/sine_cosine.rb +1 -1
  61. data/samples/processing_app/basics/math/sine_wave.rb +1 -1
  62. data/samples/processing_app/basics/objects/inheritance.rb +2 -0
  63. data/samples/processing_app/basics/objects/inheritance_two.rb +88 -0
  64. data/samples/processing_app/basics/objects/module.rb +89 -0
  65. data/samples/processing_app/{library/vecmath/drawolver.rb → basics/objects/module_two.rb} +1 -1
  66. data/samples/processing_app/basics/objects/multiple_constructors.rb +5 -0
  67. data/samples/processing_app/basics/objects/struct.rb +38 -0
  68. data/samples/processing_app/basics/structure/recursion2.rb +1 -1
  69. data/samples/processing_app/basics/transform/birds.rb +7 -10
  70. data/samples/processing_app/basics/transform/library/bird/bird.rb +3 -3
  71. data/samples/processing_app/basics/transform/rotate.rb +1 -1
  72. data/samples/processing_app/basics/transform/rotate1.rb +1 -1
  73. data/samples/processing_app/basics/transform/rotate_x_y.rb +1 -1
  74. data/samples/processing_app/demos/graphics/bezier_patch.rb +1 -38
  75. data/samples/processing_app/demos/graphics/trefoil.rb +50 -40
  76. data/samples/processing_app/demos/graphics/wiggling.rb +36 -38
  77. data/samples/processing_app/demos/performance/cubic_grid_retained.rb +14 -14
  78. data/samples/processing_app/demos/performance/esfera.rb +27 -39
  79. data/samples/processing_app/demos/performance/text_rendering.rb +1 -1
  80. data/samples/processing_app/library/fastmath/clock.rb +44 -0
  81. data/samples/processing_app/library/pdf/complex_3D.rb +26 -24
  82. data/samples/processing_app/library/vecmath/{Rakefile → arcball/Rakefile} +6 -6
  83. data/samples/processing_app/library/vecmath/arcball/arcball_box.rb +23 -0
  84. data/samples/processing_app/library/vecmath/arcball/arcball_radius.rb +23 -0
  85. data/samples/processing_app/library/vecmath/arcball/arcball_shape.rb +29 -0
  86. data/samples/processing_app/library/vecmath/{README.txt → vec2d/README.txt} +0 -0
  87. data/samples/processing_app/library/vecmath/vec2d/Rakefile +30 -0
  88. data/samples/processing_app/library/vecmath/{acceleration_with_vectors.rb → vec2d/acceleration_with_vectors.rb} +4 -5
  89. data/samples/processing_app/library/vecmath/{bouncing_ball.rb → vec2d/bouncing_ball.rb} +9 -15
  90. data/samples/processing_app/library/vecmath/{circle_collision.rb → vec2d/circle_collision.rb} +46 -51
  91. data/samples/processing_app/library/vecmath/{data → vec2d/data}/java_args.txt +0 -0
  92. data/samples/processing_app/library/vecmath/{data → vec2d/data}/sprite.png +0 -0
  93. data/samples/processing_app/library/vecmath/{data → vec2d/data}/texture.png +0 -0
  94. data/samples/processing_app/library/vecmath/{flocking.rb → vec2d/flocking.rb} +3 -6
  95. data/samples/processing_app/library/vecmath/{library → vec2d/library}/flock/flock.rb +47 -67
  96. data/samples/processing_app/library/vecmath/{library → vec2d/library}/particle/particle_system.rb +5 -5
  97. data/samples/processing_app/library/vecmath/vec2d/library/tile/tile.rb +85 -0
  98. data/samples/processing_app/library/vecmath/{morph.rb → vec2d/morph.rb} +17 -16
  99. data/samples/processing_app/library/vecmath/{multiple_particle_systems.rb → vec2d/multiple_particle_systems.rb} +11 -28
  100. data/samples/processing_app/library/vecmath/{particle_system_pshape.rb → vec2d/particle_system_pshape.rb} +4 -6
  101. data/samples/processing_app/library/vecmath/vec2d/penrose.rb +71 -0
  102. data/samples/processing_app/library/vecmath/{reflection1.rb → vec2d/reflection1.rb} +6 -6
  103. data/samples/processing_app/library/vecmath/{seeking_neural.rb → vec2d/seeking_neural.rb} +12 -16
  104. data/samples/processing_app/library/vecmath/{simple_particle_system.rb → vec2d/simple_particle_system.rb} +8 -12
  105. data/samples/processing_app/library/vecmath/{smoke_particle_system.rb → vec2d/smoke_particle_system.rb} +8 -13
  106. data/samples/processing_app/library/vecmath/{vector_math.rb → vec2d/vector_math.rb} +0 -0
  107. data/samples/processing_app/library/vecmath/{library/wiggler/wiggler.rb → vec2d/wiggle_pshape.rb} +28 -4
  108. data/samples/processing_app/library/vecmath/vec3d/Rakefile +30 -0
  109. data/samples/processing_app/library/vecmath/vec3d/drawolver.rb +86 -0
  110. data/samples/processing_app/library/vecmath/vec3d/frame_of_reference.rb +103 -0
  111. data/samples/processing_app/library/vecmath/{hilbert_fractal.rb → vec3d/hilbert_fractal.rb} +5 -33
  112. data/samples/processing_app/library/vecmath/vec3d/library/geometry/geometry.rb +3 -0
  113. data/samples/processing_app/library/vecmath/vec3d/library/geometry/lib/cylinder.rb +44 -0
  114. data/samples/processing_app/library/vecmath/vec3d/library/geometry/lib/mat4.rb +28 -0
  115. data/samples/processing_app/library/vecmath/vec3d/library/geometry/lib/plane.rb +60 -0
  116. data/samples/processing_app/library/vecmath/{library → vec3d/library}/hilbert/hilbert.rb +14 -17
  117. data/samples/processing_app/library/vecmath/{retained_menger.rb → vec3d/retained_menger.rb} +20 -55
  118. data/samples/processing_app/topics/advanced_data/Rakefile +6 -6
  119. data/samples/processing_app/topics/advanced_data/counting_words.rb +7 -7
  120. data/samples/processing_app/topics/advanced_data/data/data.xml +0 -15
  121. data/samples/processing_app/topics/advanced_data/data/struct_data.yml +5 -0
  122. data/samples/processing_app/topics/advanced_data/library/bubble/bubble.rb +8 -8
  123. data/samples/processing_app/topics/advanced_data/load_save_XML.rb +41 -42
  124. data/samples/processing_app/topics/advanced_data/load_save_json.rb +11 -11
  125. data/samples/processing_app/topics/advanced_data/load_save_struct_yaml.rb +22 -23
  126. data/samples/processing_app/topics/advanced_data/load_save_table.rb +12 -12
  127. data/samples/processing_app/topics/advanced_data/load_save_yaml.rb +10 -12
  128. data/samples/processing_app/topics/advanced_data/regex.rb +5 -6
  129. data/samples/processing_app/topics/advanced_data/threads.rb +27 -27
  130. data/samples/processing_app/topics/advanced_data/threads_two.rb +3 -2
  131. data/samples/processing_app/topics/advanced_data/word_frequency.rb +18 -16
  132. data/samples/processing_app/topics/advanced_data/yahoo_weather.rb +6 -5
  133. data/samples/processing_app/topics/animation/animated_sprite.rb +9 -7
  134. data/samples/processing_app/topics/animation/sequential.rb +19 -19
  135. data/samples/processing_app/topics/cellular_automata/library/ca/ca.rb +1 -1
  136. data/samples/processing_app/topics/cellular_automata/wolfram.rb +1 -1
  137. data/samples/processing_app/topics/create_shapes/begin_end_contour.rb +1 -1
  138. data/samples/processing_app/topics/create_shapes/library/wiggler/wiggler.rb +4 -4
  139. data/samples/processing_app/topics/create_shapes/particle_system_pshape.rb +2 -2
  140. data/samples/processing_app/topics/create_shapes/path_pshape.rb +1 -1
  141. data/samples/processing_app/topics/create_shapes/polygon_pshape_oo3.rb +1 -1
  142. data/samples/processing_app/topics/create_shapes/polygon_shape.rb +3 -3
  143. data/samples/processing_app/topics/file_io/load_file1.rb +1 -1
  144. data/samples/processing_app/topics/file_io/save_frames.rb +5 -5
  145. data/samples/processing_app/topics/file_io/save_one_image.rb +2 -2
  146. data/samples/processing_app/topics/file_io/tile_images.rb +1 -1
  147. data/samples/processing_app/topics/gui/scrollbar.rb +3 -3
  148. data/samples/processing_app/topics/image_processing/blending.rb +13 -13
  149. data/samples/processing_app/topics/image_processing/blur.rb +1 -1
  150. data/samples/processing_app/topics/image_processing/brightness.rb +1 -1
  151. data/samples/processing_app/topics/image_processing/convolution.rb +1 -1
  152. data/samples/processing_app/topics/image_processing/edge_detection.rb +4 -4
  153. data/samples/processing_app/topics/image_processing/explode.rb +1 -1
  154. data/samples/processing_app/topics/image_processing/extrusion.rb +1 -1
  155. data/samples/processing_app/topics/image_processing/histogram.rb +1 -1
  156. data/samples/processing_app/topics/image_processing/linear_image.rb +1 -1
  157. data/samples/processing_app/topics/image_processing/pixel_array.rb +1 -1
  158. data/samples/processing_app/topics/image_processing/zoom.rb +2 -2
  159. data/samples/processing_app/topics/lsystems/Rakefile +6 -6
  160. data/samples/processing_app/topics/lsystems/chequer.rb +4 -10
  161. data/samples/processing_app/topics/lsystems/csplant.rb +25 -25
  162. data/samples/processing_app/topics/lsystems/cstest.rb +9 -4
  163. data/samples/processing_app/topics/lsystems/david_tour.rb +14 -16
  164. data/samples/processing_app/topics/lsystems/koch.rb +8 -18
  165. data/samples/processing_app/topics/lsystems/library/cs_grammar/cs_grammar.rb +18 -24
  166. data/samples/processing_app/topics/lsystems/library/grammar/grammar.rb +7 -9
  167. data/samples/processing_app/topics/lsystems/library/koch/koch_fractal.rb +75 -94
  168. data/samples/processing_app/topics/lsystems/library/stochastic_grammar/stochastic_grammar.rb +11 -13
  169. data/samples/processing_app/topics/lsystems/mpeano.rb +29 -32
  170. data/samples/processing_app/topics/lsystems/peano.rb +19 -21
  171. data/samples/processing_app/topics/lsystems/penrose.rb +31 -37
  172. data/samples/processing_app/topics/lsystems/penrose_snowflake.rb +10 -15
  173. data/samples/processing_app/topics/lsystems/pentagonal.rb +20 -23
  174. data/samples/processing_app/topics/lsystems/snake_kolam.rb +13 -13
  175. data/samples/processing_app/topics/lsystems/stochastic_test.rb +25 -28
  176. data/samples/processing_app/topics/lsystems/three_d_tree.rb +25 -24
  177. data/samples/processing_app/topics/motion/bouncy_bubbles.rb +17 -17
  178. data/samples/processing_app/topics/motion/cubes_in_cube.rb +1 -3
  179. data/samples/processing_app/topics/motion/library/cube/cube.rb +2 -2
  180. data/samples/processing_app/topics/motion/reflection2.rb +1 -1
  181. data/samples/processing_app/topics/shaders/blur_filter.rb +3 -3
  182. data/samples/processing_app/topics/shaders/bw_shader.rb +3 -3
  183. data/samples/processing_app/topics/shaders/conway.rb +5 -5
  184. data/samples/processing_app/topics/shaders/deform.rb +5 -5
  185. data/samples/processing_app/topics/shaders/edge_detect.rb +3 -5
  186. data/samples/processing_app/topics/shaders/glossy_fish_eye.rb +15 -21
  187. data/samples/processing_app/topics/shaders/glsl_heightmap_noise.rb +21 -19
  188. data/samples/processing_app/topics/shaders/image_mask.rb +6 -6
  189. data/samples/processing_app/topics/shaders/landscape.rb +4 -4
  190. data/samples/processing_app/topics/shaders/monjori.rb +15 -15
  191. data/samples/processing_app/topics/shaders/nebula.rb +3 -3
  192. data/samples/processing_app/topics/shaders/sep_blur.rb +15 -15
  193. data/samples/processing_app/topics/shaders/toon_shading.rb +2 -2
  194. data/samples/processing_app/topics/simulate/chain.rb +16 -14
  195. data/samples/processing_app/topics/simulate/smoke_particle_system.rb +3 -3
  196. data/samples/processing_app/topics/vectors/acceleration_with_vectors.rb +3 -2
  197. data/samples/processing_app/topics/vectors/bouncing_ball.rb +1 -0
  198. data/samples/processing_app/topics/vectors/vector_math.rb +2 -1
  199. data/vendors/Rakefile +15 -3
  200. metadata +99 -86
  201. data/.gitignore +0 -13
  202. data/.travis.yml +0 -6
  203. data/.yardopts +0 -5
  204. data/CHANGELOG +0 -316
  205. data/CONTRIBUTING.md +0 -35
  206. data/Gemfile +0 -6
  207. data/LICENSE.md +0 -39
  208. data/README.md +0 -119
  209. data/Rakefile +0 -37
  210. data/bin/install_jruby_complete +0 -13
  211. data/lib/ruby-processing/exporters/exporters.rb +0 -7
  212. data/library/vecmath/lib/arcball.rb +0 -64
  213. data/library/vecmath/lib/quaternion.rb +0 -62
  214. data/library/vecmath/lib/vec.rb +0 -232
  215. data/ruby-processing.gemspec +0 -54
  216. data/samples/processing_app/library/pdf/.gitignore +0 -1
  217. data/samples/processing_app/library/vecmath/retained_test.rb +0 -65
  218. data/samples/processing_app/library/vecmath/retained_test2.rb +0 -65
  219. data/samples/processing_app/library/vecmath/wiggle_pshape.rb +0 -22
  220. data/test/README.md +0 -6
  221. data/test/basic.rb +0 -14
  222. data/test/draw_ex.rb +0 -12
  223. data/test/graphics.rb +0 -7
  224. data/test/p2d.rb +0 -14
  225. data/test/p3d.rb +0 -14
  226. data/test/rp5_test.rb +0 -86
  227. data/test/setup_ex.rb +0 -12
@@ -0,0 +1,3 @@
1
+ require 'rpextras'
2
+
3
+ Java::ProcessingFastmath::DeglutLibrary.new.load(JRuby.runtime, false)
@@ -12,13 +12,12 @@ module FileChooser
12
12
  System = Java::JavaLang::System
13
13
 
14
14
  class Filter < Java::javax::swing::filechooser::FileFilter
15
- attr_reader :description, :extensions
15
+ attr_reader :description, :extensions
16
16
  def define(description, extensions)
17
- @description = description
18
- @extensions = extensions
17
+ @description, @extensions = description, extensions
19
18
  end
20
19
 
21
- def accept fobj
20
+ def accept(fobj)
22
21
  return true if extensions.include?(File.extname(fobj.to_s).downcase)
23
22
  return true if fobj.isDirectory
24
23
  end
@@ -35,24 +34,23 @@ module FileChooser
35
34
  HOST = 'host_os'
36
35
  UHOME = 'user.home'
37
36
  UDIR = 'user.dir'
38
- OS = case RbConfig::CONFIG[HOST]
39
- # Detect OS
40
- when /darwin/ then :mac
41
- when /mswin|mingw/ then :windows
42
- else
43
- :unix
37
+ OS = :unix
38
+ case RbConfig::CONFIG[HOST]
39
+ when /darwin/ then OS = :mac
40
+ when /mswin|mingw/ then OS = :windows
44
41
  end
45
42
 
46
43
  def initialize
47
44
  @chooser = JXChooser.new
48
45
  end
49
46
 
50
- def look_feel lf = "Metal"
51
- lafs = javax.swing.UIManager::getInstalledLookAndFeels.select{|info| info.getName.eql? lf}
47
+ def look_feel(lf = 'Metal')
48
+ lafs = javax.swing.UIManager::getInstalledLookAndFeels.select{ |info|
49
+ info.getName.eql? lf }
52
50
  javax.swing.UIManager::setLookAndFeel(lafs[0].getClassName) if lafs.size > 0
53
51
  end
54
52
 
55
- def set_filter description, extensions
53
+ def set_filter(description, extensions)
56
54
  filter = FileChooser::Filter.new
57
55
  filter.define(description, extensions)
58
56
  @chooser.setFileFilter(filter)
@@ -1,37 +1,8 @@
1
- # vecmath.rb
2
- # The vecmath library provides Vec2D and Vec3D classes which can be
3
- # use in place of processing PVector, and provide a more rubylike interface.
4
- # Also included in the vecmath library is the ArcBall utility after:-
5
- # Ken Shoemake. Computer Graphics Laboratory. University of Pennsylvania. Philadelphia, PA
6
- # ==== Example Arcball usage see vecmath library in samples
7
- # def setup
8
- # .....
9
- # camera(width/2.0, height/2.0, (height/2.0) / tan(PI*30.0 / 180.0), 0, 0, 0, 0, 1, 0)
10
- # @arcball = ArcBall.new(0, 0, min(width - 20, height - 20) * 0.8)
11
- # .....
12
- # end
13
- #
14
- # def draw
15
- # .....
16
- # update
17
- # some_render_code
18
- # .....
19
- # end
20
- #
21
- # def update
22
- # theta, x, y, z = arcball.update
23
- # rotate(theta, x, y, z)
24
- # end
25
- #
26
- # def mouse_pressed
27
- # arcball.mouse_pressed(mouse_x, mouse_y)
28
- # end
29
- #
30
- # def mouse_dragged
31
- # arcball.mouse_dragged(mouse_x, mouse_y)
32
- # end
1
+ require 'rpextras'
33
2
 
3
+ Java::ProcessingVecmathArcball::ArcballLibrary.new.load(JRuby.runtime, false)
4
+ Java::ProcessingVecmathVec2::Vec2Library.new.load(JRuby.runtime, false)
5
+ Java::ProcessingVecmathVec3::Vec3Library.new.load(JRuby.runtime, false)
34
6
 
35
- require_relative 'lib/vec'
36
- require_relative 'lib/quaternion'
37
- require_relative 'lib/arcball'
7
+ AppRender = Java::ProcessingVecmath::AppRender
8
+ ShapeRender = Java::ProcessingVecmath::ShapeRender
@@ -15,5 +15,7 @@ end
15
15
 
16
16
  desc 'vecmath'
17
17
  task :vecmath do
18
- sh "cd processing_app/library/vecmath && rake"
18
+ sh "cd processing_app/library/vecmath/vec2d && rake"
19
+ # sh "cd processing_app/library/vecmath/vec3d && rake"
20
+ # sh "cd processing_app/library/vecmath/arc_ball && rake"
19
21
  end
@@ -0,0 +1,150 @@
1
+ Button enter, nojruby;
2
+ String processingRoot = "enter your processing root here"; // edit this line in the sketch
3
+ String done = "Done";
4
+ String OS = System.getProperty("os.name").toLowerCase();
5
+ String home, suggestion, separator, root;
6
+ PFont font;
7
+ StringBuilder header = new StringBuilder(200);
8
+ float rectX, rectX2, rectY; // Position of buttons
9
+ float rectHeight = 30; // height of rect
10
+ float rectWidth = 90; // width of rect
11
+ int rectColor, rectColor2;
12
+ int rectHighlight, rectHighlight2;
13
+ int currentColor;
14
+ int selectedColor;
15
+ boolean acceptOver = false;
16
+ boolean noJruby = false;
17
+ boolean selected = false;
18
+ boolean no_jruby = false;
19
+
20
+
21
+ void setup() {
22
+ size(600, 200);
23
+ home = System.getProperty("user.home");
24
+ File f = new File(home);
25
+ root = f.getParent();
26
+ separator = System.getProperty("file.separator");
27
+ header.append("# YAML configuration file for ruby-processing\n");
28
+ header.append("# RP5HOME: \"").append(root).append(separator).append("ruby193 ... ").append(separator);
29
+ header.append("ruby-processing\" #windows users may need to set this\n");
30
+ font = createFont("Helvetica", 18);
31
+ if (OS.contains("mac")) {
32
+ suggestion = "/Applications/Processing.app/Contents/Resources/Java";
33
+ } else {
34
+ suggestion = home + separator + "processing-2.2.1";
35
+ }
36
+ rectColor = color(140);
37
+ rectColor2 = color(140);
38
+ rectHighlight = color(100);
39
+ rectHighlight2 = color(100);
40
+ selectedColor = color(0);
41
+ rectX = rectWidth + 20;
42
+ rectX2 = rectWidth + 150;
43
+ rectY = height * 0.8f - rectHeight / 4;
44
+ enter = new Button(rectX2, rectY, rectWidth, rectHeight, "enter");
45
+ nojruby = new Button(rectX, rectY, rectWidth, rectHeight, "nojruby");
46
+ }
47
+
48
+ void draw() {
49
+ background(200);
50
+ fill(0, 0, 200);
51
+ text("Suggestion:", 35, 28);
52
+ text(suggestion, 35, 56);
53
+ textFont(font, 18);
54
+ fill(255, 0, 0);
55
+ // this adds a blinking cursor after your text, at the expense of redrawing everything every frame
56
+ text(processingRoot + (frameCount / 10 % 2 == 0 ? "_" : ""), 35, 100);
57
+ fill(0, 0, 200);
58
+ text("Select nojruby to use jruby-complete by default", 35, 140);
59
+ update(mouseX, mouseY);
60
+ //background(200);
61
+
62
+ if (acceptOver) {
63
+ enter.draw(rectHighlight);
64
+ nojruby.draw(rectHighlight2);
65
+ } else {
66
+ enter.draw(rectColor);
67
+ nojruby.draw(rectColor2);
68
+ }
69
+ }
70
+
71
+ void writeRoot() {
72
+ rectColor = selectedColor;
73
+ rectHighlight = selectedColor;
74
+ header.append("PROCESSING_ROOT: \"").append(processingRoot).append("\"\n");
75
+ if (no_jruby) {
76
+ header.append("JRUBY: \'false\'\n");
77
+ } else {
78
+ header.append("JRUBY: \'true\'\n");
79
+ }
80
+ PrintWriter pw = createWriter(home + separator + ".rp5rc");
81
+ pw.append(header);
82
+ pw.flush();
83
+ pw.close();
84
+ processingRoot = done;
85
+ }
86
+
87
+ void keyReleased() {
88
+ if (key != CODED) {
89
+ switch (key) {
90
+ case BACKSPACE:
91
+ processingRoot = processingRoot.substring(0, max(0, processingRoot.length() - 1));
92
+ break;
93
+ case ENTER: // save the processing root to the config file
94
+ case RETURN:
95
+ writeRoot();
96
+ break;
97
+ case ESC:
98
+ case DELETE:
99
+ break;
100
+ default:
101
+ processingRoot += key;
102
+ }
103
+ }
104
+ }
105
+
106
+ void update(float x, float y) {
107
+ acceptOver = enter.overRect();
108
+ noJruby = nojruby.overRect();
109
+ }
110
+
111
+ void mouseClicked() {
112
+ update(mouseX, mouseY);
113
+ if (acceptOver) {
114
+ rectColor = selectedColor;
115
+ rectHighlight = selectedColor;
116
+ writeRoot();
117
+ }
118
+ if (noJruby) {
119
+ rectColor2 = selectedColor;
120
+ rectHighlight2 = selectedColor;
121
+ no_jruby = true;
122
+ }
123
+ }
124
+
125
+ class Button {
126
+
127
+ float x, y, w, h;
128
+ String text;
129
+
130
+ Button(float x, float y, float w, float h, String text) {
131
+ this.x = x;
132
+ this.y = y;
133
+ this.w = w;
134
+ this.h = h;
135
+ this.text = text;
136
+ }
137
+
138
+ void draw(int col) {
139
+ fill(col);
140
+ rect(x, y, w, h, 20, 20, 20, 20);
141
+ fill(255);
142
+ text(text, x + 8, y + 20);
143
+ }
144
+
145
+ boolean overRect() {
146
+ return (mouseX >= x && mouseX <= x + w
147
+ && mouseY >= y && mouseY <= y + h);
148
+ }
149
+ }
150
+
@@ -1,20 +1,20 @@
1
1
  # Simple demo Rakefile to autorun samples in current directory
2
2
  # adjust path to rp5 executable, and or opts as required
3
3
 
4
- SAMPLES_DIR="./"
4
+ SAMPLES_DIR = './'
5
5
 
6
6
  desc 'run demo'
7
- task :default => [:demo]
7
+ task default: [:demo]
8
8
 
9
9
  desc 'demo'
10
10
  task :demo do
11
- samples_list.shuffle.each{|sample| run_sample sample}
11
+ samples_list.shuffle.each{ |sample| run_sample sample }
12
12
  end
13
13
 
14
14
  def samples_list
15
15
  files = []
16
16
  Dir.chdir(SAMPLES_DIR)
17
- Dir.glob("*.rb").each do |file|
17
+ Dir.glob('*.rb').each do |file|
18
18
  files << File.join(SAMPLES_DIR, file)
19
19
  end
20
20
  return files
@@ -22,9 +22,9 @@ end
22
22
 
23
23
  def run_sample(sample_name)
24
24
  puts "Running #{sample_name}...quit to run next sample"
25
- open("|rp5 run #{sample_name}", "r") do |io|
25
+ open("|rp5 run #{sample_name}", 'r') do |io|
26
26
  while l = io.gets
27
- puts(l.chop)
27
+ puts(l.chop)
28
28
  end
29
29
  end
30
30
  end
@@ -11,15 +11,15 @@ def setup
11
11
  @last_time = 0
12
12
  @current_frame = 0
13
13
  @draw = false
14
- @back_color = 204
14
+ @back_color = 204
15
15
  stroke_weight 4
16
16
  smooth
17
17
  background @back_color
18
- FRAME_COUNT.times { @frames << get() }
18
+ FRAME_COUNT.times { @frames << get }
19
19
  end
20
20
 
21
21
  def draw
22
- time = millis()
22
+ time = millis
23
23
  if time > @last_time + 100
24
24
  next_frame
25
25
  @last_time = time
@@ -37,12 +37,12 @@ end
37
37
 
38
38
  def key_pressed
39
39
  background @back_color
40
- @frames.size.times {|i| @frames[i] = get()}
40
+ @frames.size.times { |i| @frames[i] = get }
41
41
  end
42
42
 
43
43
  def next_frame
44
- @frames[@current_frame] = get()
44
+ @frames[@current_frame] = get
45
45
  @current_frame += 1
46
46
  @current_frame = 0 if @current_frame >= @frames.size
47
47
  image(@frames[@current_frame], 0, 0)
48
- end
48
+ end
@@ -3,62 +3,55 @@
3
3
  # You can print out the parametric equations for t = 0..1
4
4
  module Olap
5
5
  def self.overlaps(x, y, point_x, point_y)
6
- (x-point_x)**2 + (y-point_y)**2 < RADIUS * RADIUS
6
+ Math.hypot(x - point_x, y - point_y) < RADIUS
7
7
  end
8
8
  end
9
9
 
10
10
  class Curve
11
- include Olap
12
- include Processing::Proxy
11
+ include Olap, Processing::Proxy
13
12
  attr_accessor :x1, :y1, :c1x, :c1y, :c2x, :c2y, :x2, :y2
14
13
 
15
14
  def initialize
16
15
  @x1, @y1, @x2, @y2 = X1, Y1, X2, Y2
17
- set_control_points(X1+30, Y1, X2-30, Y2)
16
+ set_control_points(X1 + 30, Y1, X2 - 30, Y2)
18
17
  end
19
18
 
20
19
  def contains(x, y)
21
- return :one if Olap::overlaps(@x1, @y1, x, y)
22
- return :two if Olap::overlaps(@x2, @y2, x, y)
20
+ return :one if Olap.overlaps(x1, y1, x, y)
21
+ return :two if Olap.overlaps(x2, y2, x, y)
23
22
  end
24
23
 
25
-
26
24
  def all_points
27
25
  return x1, y1, c1x, c1y, c2x, c2y, x2, y2
28
26
  end
29
27
 
30
-
31
28
  def control_points
32
29
  return c1x, c1y, c2x, c2y
33
30
  end
34
31
 
35
-
36
32
  def set_control_points(*points)
37
33
  @c1x, @c1y, @c2x, @c2y = *points
38
34
  end
39
35
 
40
-
41
36
  def draw
42
- bezier *all_points
43
- oval @x1, @y1, 3, 3
44
- oval @x2, @y2, 3, 3
37
+ bezier(*all_points)
38
+ oval x1, y1, 3, 3
39
+ oval x2, y2, 3, 3
45
40
  end
46
41
 
47
-
48
- def print_equation
49
- p = all_points.map {|p| p.to_i }
42
+ def print_equation(id)
43
+ p = all_points.map { |pt| pt.to_i }
50
44
  puts ""
51
- puts "*** line ##{$app.curves.index(self) + 1} ***"
45
+ puts "*** line ##{id} ***"
52
46
  puts "x = (1-t)^3 #{p[0]} + 3(1-t)^2 t#{p[2]} + 3(1-t)t^2 #{p[4]} + t^3 #{p[6]}"
53
47
  puts "y = -1 * ((1-t)^3 #{p[1]} + 3(1-t)^2 t#{p[3]} + 3(1-t)t^2 #{p[5]} + t^3 #{p[7]})"
54
48
  puts ""
55
49
  end
56
-
57
50
  end
58
51
 
59
52
 
60
53
  attr_accessor :curves, :c1x, :c1y, :c2x, :c2y
61
- attr_reader :panel
54
+ attr_reader :panel, :hide
62
55
 
63
56
  X1, Y1, X2, Y2 = 50.0, 50.0, 250.0, 250.0
64
57
  REDDISH = [250, 100, 100]
@@ -67,14 +60,12 @@ RADIUS = 7
67
60
  load_library :control_panel
68
61
  include Olap
69
62
 
70
- attr_reader :hide
71
-
72
63
  def setup
73
64
  size 300, 300
74
65
  @curves = []
75
66
  @hide = false
76
67
  control_panel do |c|
77
- c.look_feel "Nimbus"
68
+ c.look_feel 'Nimbus'
78
69
  c.button :new_curve
79
70
  c.button :print_equations
80
71
  @panel = c
@@ -82,68 +73,44 @@ def setup
82
73
  generate_curve
83
74
  end
84
75
 
85
-
86
-
87
76
  def print_equations
88
- curves.each {|c| c.print_equation }
77
+ curves.each_with_index { |c, i| c.print_equation(i + 1) }
89
78
  end
90
79
 
91
-
92
80
  def control_points
93
81
  return c1x, c1y, c2x, c2y
94
82
  end
95
83
 
96
-
97
84
  def set_control_points(*points)
98
85
  @c1x, @c1y, @c2x, @c2y = points.any? ? points : [X1, Y1, X2, Y2]
99
86
  end
100
87
 
101
-
102
88
  def generate_curve
103
- @curves << current_curve = Curve.new
89
+ curves << current_curve = Curve.new
104
90
  @current = curves.length - 1
105
91
  set_control_points(*current_curve.control_points)
106
92
  end
107
93
 
108
-
109
94
  def current_curve
110
- @curves[@current]
95
+ curves[@current]
111
96
  end
112
97
 
113
-
114
98
  def new_curve
115
99
  current_curve.set_control_points(c1x, c1y, c2x, c2y)
116
100
  generate_curve
117
101
  end
118
102
 
119
-
120
103
  def clicked_control_point?
121
104
  x, y = mouse_x, mouse_y
122
- return :one if Olap::overlaps(@c1x, @c1y, x, y)
123
- return :two if Olap::overlaps(@c2x, @c2y, x, y)
105
+ return :one if Olap.overlaps(c1x, c1y, x, y)
106
+ return :two if Olap.overlaps(c2x, c2y, x, y)
124
107
  end
125
108
 
126
-
127
- def key_pressed
128
- case keyCode
129
- when 8 # Delete the current line
130
- return if @curves.length <= 1
131
- @curves.delete(current_curve)
132
- @current = @curves.length - 1
133
- when LEFT # Flip forward
134
- @current = (@current + 1) % @curves.length
135
- when RIGHT # Flip back
136
- @current = (@current - 1) % @curves.length
137
- end
138
- set_control_points(*current_curve.control_points)
139
- end
140
-
141
-
142
109
  def mouse_pressed
143
110
  switch_curve_if_endpoint_clicked
144
111
  @control = clicked_control_point?
145
112
  return if @control
146
- curve = @curves.detect {|c| c.contains(mouse_x, mouse_y) }
113
+ curve = curves.detect { |c| c.contains(mouse_x, mouse_y) }
147
114
  @end_point = curve.contains(mouse_x, mouse_y) if curve
148
115
  end
149
116
 
@@ -153,22 +120,20 @@ def mouse_released
153
120
  @hide = false
154
121
  end
155
122
 
156
-
157
123
  def mouse_dragged
158
124
  offs = compute_offsets
159
- return if offs.map {|o| o.abs }.max > 100
125
+ return if offs.map { |o| o.abs }.max > 100
160
126
  return move_control_point(*offs) if @control
161
127
  return move_end_point(*offs) && move_control_point(*offs) if @end_point
162
128
  move_current_curve(*offs)
163
129
  end
164
130
 
165
-
166
131
  def switch_curve_if_endpoint_clicked
167
- become = @curves.detect {|c| c.contains(mouse_x, mouse_y) }
132
+ become = curves.detect { |c| c.contains(mouse_x, mouse_y) }
168
133
  return unless become && become != current_curve
169
134
  current_curve.set_control_points(*control_points)
170
135
  self.set_control_points(*become.control_points)
171
- @current = @curves.index(become)
136
+ @current = curves.index(become)
172
137
  end
173
138
 
174
139
 
@@ -203,32 +168,28 @@ def compute_offsets
203
168
  return mouse_x - pmouse_x, mouse_y - pmouse_y
204
169
  end
205
170
 
206
-
207
171
  def draw_curves
208
172
  stroke 255
209
173
  no_fill
210
174
  stroke_width 2
211
- @curves.each {|curve| curve.draw }
175
+ curves.each { |curve| curve.draw }
212
176
  end
213
177
 
214
-
215
178
  def draw_current_control_points
216
- fill *REDDISH
179
+ fill color(*REDDISH)
217
180
  no_stroke
218
- oval @c1x, @c1y, 5, 5
219
- oval @c2x, @c2y, 5, 5
181
+ oval c1x, c1y, 5, 5
182
+ oval c2x, c2y, 5, 5
220
183
  end
221
184
 
222
-
223
185
  def draw_control_tangent_lines
224
186
  c = current_curve
225
- stroke *REDDISH
187
+ stroke color(*REDDISH)
226
188
  stroke_width 1
227
- line @c1x, @c1y, c.x1, c.y1
228
- line @c2x, @c2y, c.x2, c.y2
189
+ line c1x, c1y, c.x1, c.y1
190
+ line c2x, c2y, c.x2, c.y2
229
191
  end
230
192
 
231
-
232
193
  def draw
233
194
  if (!hide)
234
195
  panel.visible = self.visible