ruby-processing 2.4.4 → 2.5.0

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 (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
@@ -1,24 +1,23 @@
1
1
  require 'fileutils'
2
2
  require 'erb'
3
- require 'ruby-processing/library_loader'
3
+ require_relative '../../ruby-processing/library_loader'
4
4
 
5
5
  module Processing
6
-
7
- # This base exporter implements some of the common
8
- # code-munging needed to generate apps and applets.
6
+ # This base exporter implements some of the common
7
+ # code-munging needed to generate apps.
9
8
  class BaseExporter
10
9
  include FileUtils
11
10
  ## hashes with strings as keys need to retain old hash syntax
12
- DEFAULT_DIMENSIONS = {'width' => '100', 'height' => '100'}
11
+ DEFAULT_DIMENSIONS = { 'width' => '100', 'height' => '100' }
13
12
  DEFAULT_DESCRIPTION = ''
14
- NECESSARY_FOLDERS = ['data', 'lib', 'vendor']
15
-
13
+ NECESSARY_FOLDERS = %w(data lib vendor)
14
+
16
15
  # Returns the filepath, basename, and directory name of the sketch.
17
16
  def get_main_file(file)
18
17
  @file = file
19
18
  return file, File.basename(file), File.dirname(file)
20
19
  end
21
-
20
+
22
21
  # Centralized method to read the source of the sketch and extract
23
22
  # all the juicy details.
24
23
  def extract_information
@@ -35,49 +34,49 @@ module Processing
35
34
  hash_to_ivars @info
36
35
  @info
37
36
  end
38
-
37
+
39
38
  # Searches the source for a class name.
40
39
  def extract_class_name(source)
41
40
  match = source.match(/(\w+)\s*<\s*Processing::App/)
42
41
  match ? match[1] : 'Sketch'
43
42
  end
44
-
43
+
45
44
  # Searches the source for a title.
46
45
  def extract_title(source)
47
46
  match = source.match(/#{@info[:class_name]}\.new.*?:title\s=>\s["'](.+?)["']/m)
48
47
  match ? match[1] : File.basename(@file, '.rb').titleize
49
48
  end
50
-
49
+
51
50
  # Searches the source for the width and height of the sketch.
52
51
  def extract_dimension(source, dimension)
53
52
  match = source.match(/#{@info[:class_name]}\.new.*?:#{dimension}\s?=>\s?(\d+)/m)
54
53
  size_match = source.match(/^[^#]*size\(?\s*(\d+)\s*,\s*(\d+)\s*\)?/)
55
54
  return match[1] if match
56
55
  return (dimension == 'width' ? size_match[1] : size_match[2]) if size_match
57
- warn "using default dimensions for export, please use constants integer values in size() call instead of computed ones"
56
+ warn 'using default dimensions for export, please use constants integer values in size() call instead of computed ones'
58
57
  DEFAULT_DIMENSIONS[dimension]
59
58
  end
60
-
59
+
61
60
  # Searches the source for a description of the sketch.
62
61
  def extract_description(source)
63
62
  match = source.match(/\A((\s*#(.*?)\n)+)[^#]/m)
64
63
  match ? match[1].gsub(/\s*#\s*/, "\n") : DEFAULT_DESCRIPTION
65
64
  end
66
-
65
+
67
66
  # Searches the source for any libraries that have been loaded.
68
67
  def extract_libraries(source)
69
68
  lines = source.split("\n")
70
69
  libs = lines.grep(/^[^#]*load_(?:java_|ruby_)?librar(?:y|ies)\s+(.+)/) do
71
- $1.split(/\s*,\s*/).collect do |raw_library_name|
72
- raw_library_name.tr("\"':\r\n", '')
70
+ $1.split(/\s*,\s*/).map do |raw_library_name|
71
+ raw_library_name.tr("\"':\r\n", '')
73
72
  end
74
73
  end.flatten
75
74
  lib_loader = LibraryLoader.new
76
75
  libs.map { |lib| lib_loader.get_library_paths(lib) }.flatten.compact
77
76
  end
78
-
79
- # Looks for all of the codes require or load commands, checks
80
- # to see if the file exists (that it's not a gem, or a standard lib)
77
+
78
+ # Looks for all of the codes require or load commands, checks
79
+ # to see if the file exists (that it's not a gem, or a standard lib)
81
80
  # and hands you back all the real ones.
82
81
  def extract_real_requires(source)
83
82
  code = source.dup
@@ -90,48 +89,46 @@ module Processing
90
89
  line = line.gsub(/\b(require_relative|require|load)\b/, 'partial_paths << ')
91
90
  eval(line)
92
91
  where = "{#{local_dir}/,}{#{partial_paths.join(',')}}"
93
- unless line =~ /\.[^.]+$/
94
- where += ".{rb,jar}"
95
- end
92
+ where += '.{rb,jar}' unless line =~ /\.[^.]+$/
96
93
  requirements += Dir[where]
97
94
  code = matchdata.post_match
98
95
  end
99
96
  requirements
100
97
  end
101
-
102
-
98
+
99
+
103
100
  protected
104
-
101
+
105
102
  def read_source_code
106
103
  File.read(@main_file_path)
107
104
  end
108
-
105
+
109
106
  def local_dir
110
107
  File.dirname(@main_file_path)
111
108
  end
112
-
109
+
113
110
  def hash_to_ivars(hash)
114
- hash.each{|k,v| instance_variable_set("@" + k.to_s, v) }
111
+ hash.each { |k, v| instance_variable_set('@' + k.to_s, v) }
115
112
  end
116
-
113
+
117
114
  def wipe_and_recreate_destination
118
115
  remove_entry_secure @dest if File.exist?(@dest)
119
116
  mkdir_p @dest
120
117
  end
121
-
122
- def render_erb_in_path_with_binding(path, some_binding, opts={})
123
- erbs = Dir.glob(path + "/**/*.erb")
118
+
119
+ def render_erb_in_path_with_binding(path, some_binding, opts = {})
120
+ erbs = Dir.glob(path + '/**/*.erb')
124
121
  erbs.each do |erb|
125
- string = File.open(erb) {|f| f.read }
122
+ string = File.open(erb) { |f| f.read }
126
123
  rendered = render_erb_from_string_with_binding(string, some_binding)
127
- File.open(erb.sub(".erb", ""), "w") {|f| f.print rendered }
124
+ File.open(erb.sub('.erb', ''), 'w') { |f| f.print rendered }
128
125
  rm erb if opts[:delete]
129
126
  end
130
127
  end
131
-
128
+
132
129
  def render_erb_from_string_with_binding(erb, some_binding)
133
- rendered = ERB.new(erb, nil, "<>", "rendered").result(some_binding)
130
+ ERB.new(erb, nil, '<>', 'rendered').result(some_binding)
134
131
  end
135
-
136
132
  end
137
133
  end
134
+
@@ -1,30 +1,27 @@
1
1
  module Processing
2
-
2
+ require_relative '../../ruby-processing/exporters/base_exporter'
3
3
  # This class creates blank sketches, with the boilerplate filled in.
4
4
  class Creator < BaseExporter
5
-
5
+
6
6
  ALL_DIGITS = /\A\d+\Z/
7
-
7
+
8
8
  # Create a blank sketch, given a path.
9
+ # @TODO reduce cyclomatic complexity
9
10
  def create!(path, args, p3d)
10
- usage path
11
- main_file = File.basename(path, ".rb")
12
- # Check to make sure that the main file exists
13
- already_exists = File.exist?(path) || File.exist?("#{File.dirname(path)}/#{main_file.underscore}.rb")
14
- if already_exists
15
- puts "That sketch already exists."
16
- exit
17
- end
18
-
11
+ usage if /\?/ =~ path || /--help/ =~ path
12
+ main_file = File.basename(path, '.rb')
13
+ # Check to make sure that the main file doesn't exist already
14
+ already_exists(path)
15
+
19
16
  # Get the substitutions
20
17
  @name = main_file.camelize
21
18
  @file_name = main_file.underscore
22
19
  @title = main_file.titleize
23
-
20
+
24
21
  @width, @height = args[0], args[1]
25
22
  @with_size = @width && @width.match(ALL_DIGITS) &&
26
23
  @height && @height.match(ALL_DIGITS)
27
-
24
+
28
25
  # Make the file
29
26
  dir = File.dirname path
30
27
  mkdir_p dir
@@ -32,23 +29,28 @@ module Processing
32
29
  template = File.new("#{RP5_ROOT}/lib/templates/create/#{template_name}")
33
30
  rendered = render_erb_from_string_with_binding(template.read, binding)
34
31
  full_path = File.join(dir, "#{@file_name}.rb")
35
- File.open(full_path, "w") {|f| f.print(rendered) }
36
- puts "Created Sketch \"#{@name}\" in #{full_path.sub(/\A\.\//, '')}"
32
+ File.open(full_path, 'w') { |f| f.print(rendered) }
33
+ puts "Created a new Sketch in #{full_path.sub(/\A\.\//, '')}"
34
+ end
35
+
36
+ def already_exist(path)
37
+ if File.exist?(path) || File.exist?("#{File.dirname(path)}/#{main_file.underscore}.rb")
38
+ puts 'That sketch already exists.'
39
+ end
40
+ exit
37
41
  end
38
-
42
+
39
43
  # Show the help/usage message for create.
40
- def usage(predicate)
41
- unless predicate
42
- puts <<-USAGE
43
-
44
+ def usage
45
+ puts <<-USAGE
46
+
44
47
  Usage: script/generate <sketch_to_generate> <width> <height>
45
48
  Width and Height are optional.
46
-
49
+
47
50
  Example: script/generate fancy_drawing/app 800 600
48
-
51
+
49
52
  USAGE
50
- exit
51
- end
53
+ exit
52
54
  end
53
55
  end
54
56
  end
@@ -4,7 +4,7 @@ module Processing
4
4
  # Nice block method to draw to a buffer.
5
5
  # You can optionally pass it a width, a height, and a renderer.
6
6
  # Takes care of starting and ending the draw for you.
7
- def buffer(buf_width=width, buf_height=height, renderer=@render_mode)
7
+ def buffer(buf_width = width, buf_height = height, renderer = @render_mode)
8
8
  buf = create_graphics(buf_width, buf_height, renderer)
9
9
  buf.begin_draw
10
10
  yield buf
@@ -14,8 +14,8 @@ module Processing
14
14
 
15
15
  # A nice method to run a given block for a grid.
16
16
  # Lifted from action_coding/Nodebox.
17
- def grid(cols, rows, col_size=1, row_size=1)
18
- (0...cols*rows).map do |i|
17
+ def grid(cols, rows, col_size = 1, row_size = 1)
18
+ (0...cols * rows).map do |i|
19
19
  x = col_size * (i % cols)
20
20
  y = row_size * i.div(cols)
21
21
  yield x, y
@@ -31,22 +31,18 @@ module Processing
31
31
  def color(*args)
32
32
  a = args[0]
33
33
  # convert to signed int
34
- if args.length == 1
34
+ if args.length == 1
35
35
  if a.is_a?(Fixnum) && a >= 2**31
36
36
  args = [ a - 2**32 ]
37
- elsif a.is_a?(String) && a[0] == ?#
38
- h = a[1..-1]
39
- # add opaque alpha channel
40
- if h.size <= 6
41
- h = "ff" + "0"*(6-h.size) + h
42
- end
37
+ elsif a.is_a?(String) && a[0].eql?('#')
38
+ h = a[1..-1].rjust(6, '0').prepend('ff')
43
39
  return color(h.hex)
44
40
  end
45
41
  end
46
42
  super(*args)
47
43
  end
48
-
49
- # Overrides convenience function loop, to add ability to loop over a block
44
+
45
+ # Overrides convenience function loop, to add ability to loop over a block
50
46
  # if supplied, otherwise perform as the PApplet class would
51
47
  def loop(&block)
52
48
  if block_given?
@@ -57,14 +53,14 @@ module Processing
57
53
  super
58
54
  end
59
55
  end
60
-
56
+
61
57
  # Overrides Processing convenience function thread, which takes a String
62
- # arg (for a function) to more rubylike version, takes a block...
58
+ # arg (for a function) to more rubylike version, takes a block...
63
59
  def thread(*args, &block)
64
60
  if block_given?
65
61
  Thread.new *args, &block
66
62
  else
67
- raise ArgumentError, "thread must be called with a block" , caller
63
+ raise ArgumentError, 'thread must be called with a block' , caller
68
64
  end
69
65
  end
70
66
 
@@ -72,7 +68,7 @@ module Processing
72
68
  # Here's a convenient way to look for them.
73
69
  def find_method(method_name)
74
70
  reg = Regexp.new("#{method_name}", true)
75
- self.methods.sort.select {|meth| reg.match(meth)}
71
+ self.methods.sort.select { |meth| reg.match(meth) }
76
72
  end
77
73
 
78
74
  # Proxy over a list of Java declared fields that have the same name as
@@ -80,12 +76,12 @@ module Processing
80
76
  def proxy_java_fields
81
77
  @declared_fields = {}
82
78
  fields = %w(sketchPath key frameRate frame mousePressed keyPressed)
83
- fields.each {|f| @declared_fields[f] = java_class.declared_field(f) }
79
+ fields.each { |f| @declared_fields[f] = java_class.declared_field(f) }
84
80
  end
85
81
 
86
82
  # By default, your sketch path is the folder that your sketch is in.
87
83
  # If you'd like to do something fancy, feel free.
88
- def set_sketch_path(path=nil)
84
+ def set_sketch_path(path = nil)
89
85
  field = @declared_fields['sketchPath']
90
86
  field.set_value(java_self, path || SKETCH_ROOT)
91
87
  end
@@ -139,12 +135,12 @@ module Processing
139
135
 
140
136
  # Is the mouse pressed for this frame?
141
137
  def mouse_pressed?
142
- field = @declared_fields['mousePressed'].value(java_self)
138
+ @declared_fields['mousePressed'].value(java_self)
143
139
  end
144
140
 
145
141
  # Is a key pressed for this frame?
146
- def key_pressed?
147
- field = @declared_fields['keyPressed'].value(java_self)
142
+ def key_pressed?
143
+ @declared_fields['keyPressed'].value(java_self)
148
144
  end
149
145
  end
150
- end
146
+ end
@@ -1,11 +1,10 @@
1
1
  class Numeric #:nodoc
2
-
2
+
3
3
  def degrees
4
- self*180/Math::PI
4
+ self * 180 / Math::PI
5
5
  end
6
-
6
+
7
7
  def radians
8
- self*Math::PI/180
8
+ self * Math::PI / 180
9
9
  end
10
-
11
- end
10
+ end
@@ -1,35 +1,26 @@
1
1
  class String #:nodoc:
2
-
2
+
3
3
  def titleize
4
4
  self.underscore.humanize.gsub(/\b([a-z])/) { $1.capitalize }
5
5
  end
6
-
6
+
7
7
  def humanize()
8
- self.gsub(/_id$/, "").gsub(/_/, " ").capitalize
8
+ self.gsub(/_id$/, '').gsub(/_/, ' ').capitalize
9
9
  end
10
-
10
+
11
11
  def camelize(first_letter_in_uppercase = true)
12
12
  if first_letter_in_uppercase
13
- self.gsub(/\/(.?)/) { "::" + $1.upcase }.gsub(/(^|_)(.)/) { $2.upcase }
13
+ self.gsub(/\/(.?)/) { '::' + $1.upcase }.gsub(/(^|_)(.)/) { $2.upcase }
14
14
  else
15
15
  self.first + self.camelize[1..-1]
16
16
  end
17
17
  end
18
-
18
+
19
19
  def underscore
20
- self.gsub(/::/, '/').
21
- gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
22
- gsub(/([a-z\d])([A-Z])/,'\1_\2').
23
- tr("-", "_").
24
- downcase
20
+ self.gsub(/::/, '/')
21
+ .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
22
+ .gsub(/([a-z\d])([A-Z])/, '\1_\2')
23
+ .tr('-', '_')
24
+ .downcase
25
25
  end
26
-
27
- # String.ord is Ruby 1.9, so this is a little fix for R 1.8
28
- # to make it forward compatible and readable
29
- unless String.method_defined? :ord
30
- def ord
31
- self[0]
32
- end
33
- end
34
-
35
26
  end
@@ -3,10 +3,10 @@ module Processing
3
3
  attr_reader :sketchbook_library_path
4
4
 
5
5
  def initialize
6
- @sketchbook_library_path = File.join(find_sketchbook_path || "", "libraries")
6
+ @sketchbook_library_path = File.join(find_sketchbook_path || '', 'libraries')
7
7
  @loaded_libraries = Hash.new(false)
8
8
  end
9
-
9
+
10
10
  # Detect if a library has been loaded (for conditional loading)
11
11
  def library_loaded?(library_name)
12
12
  @loaded_libraries[library_name.to_sym]
@@ -39,12 +39,11 @@ module Processing
39
39
  end
40
40
  end
41
41
 
42
- path = get_library_paths(library_name, "rb").first
42
+ path = get_library_paths(library_name, 'rb').first
43
43
  return false unless path
44
44
  return @loaded_libraries[library_name] = (require path)
45
45
  end
46
46
 
47
-
48
47
  # For pure java libraries, such as the ones that are available
49
48
  # on this page: http://processing.org/reference/libraries/index.html
50
49
  #
@@ -54,50 +53,50 @@ module Processing
54
53
  def load_java_library(library_name)
55
54
  library_name = library_name.to_sym
56
55
  return true if @loaded_libraries[library_name]
57
- path = get_library_directory_path(library_name, "jar")
58
- jars = get_library_paths(library_name, "jar")
56
+ path = get_library_directory_path(library_name, 'jar')
57
+ jars = get_library_paths(library_name, 'jar')
59
58
  return false if jars.empty?
60
59
  jars.each {|jar| require jar }
61
60
 
62
61
  platform_specific_library_paths = get_platform_specific_library_paths(path)
63
62
  platform_specific_library_paths = platform_specific_library_paths.select do |path|
64
- test(?d, path) && !Dir.glob(File.join(path, "*.{so,dll,jnilib}")).empty?
63
+ test(?d, path) && !Dir.glob(File.join(path, '*.{so,dll,jnilib}')).empty?
65
64
  end
66
65
 
67
66
  if !platform_specific_library_paths.empty?
68
- platform_specific_library_paths << java.lang.System.getProperty("java.library.path")
67
+ platform_specific_library_paths << java.lang.System.getProperty('java.library.path')
69
68
  new_library_path = platform_specific_library_paths.join(java.io.File.pathSeparator)
70
69
 
71
- java.lang.System.setProperty("java.library.path", new_library_path)
70
+ java.lang.System.setProperty('java.library.path', new_library_path)
72
71
 
73
- field = java.lang.Class.for_name("java.lang.ClassLoader").get_declared_field("sys_paths")
72
+ field = java.lang.Class.for_name('java.lang.ClassLoader').get_declared_field('sys_paths')
74
73
  if field
75
74
  field.accessible = true
76
- field.set(java.lang.Class.for_name("java.lang.System").get_class_loader, nil)
75
+ field.set(java.lang.Class.for_name('java.lang.System').get_class_loader, nil)
77
76
  end
78
77
  end
79
78
  return @loaded_libraries[library_name] = true
80
79
  end
81
80
 
82
81
  def get_platform_specific_library_paths(basename)
83
- bits = "universal" # for MacOSX, but does this even work, or does Mac return "64"?
84
- if java.lang.System.getProperty("sun.arch.data.model") == "32" ||
85
- java.lang.System.getProperty("java.vm.name").index("32")
86
- bits = "32"
87
- elsif java.lang.System.getProperty("sun.arch.data.model") == "64" ||
88
- java.lang.System.getProperty("java.vm.name").index("64")
89
- bits = "64"
82
+ bits = 'universal' # for MacOSX, but does this even work, or does Mac return '64'?
83
+ if java.lang.System.getProperty('sun.arch.data.model') == '32' ||
84
+ java.lang.System.getProperty('java.vm.name').index('32')
85
+ bits = '32'
86
+ elsif java.lang.System.getProperty('sun.arch.data.model') == '64' ||
87
+ java.lang.System.getProperty('java.vm.name').index('64')
88
+ bits = '64'
90
89
  end
91
90
 
92
- match_string, platform = {"Mac" => "macosx", "Linux" => "linux", "Windows" => "windows" }.detect do |string, platform_|
93
- java.lang.System.getProperty("os.name").index(string)
91
+ _match_string_, platform = {'Mac' => 'macosx', 'Linux' => 'linux', 'Windows' => 'windows' }.detect do |string, _platform_|
92
+ java.lang.System.getProperty('os.name').index(string)
94
93
  end
95
- platform ||= "other"
96
- [ platform, platform+bits ].collect { |p| File.join(basename, p) }
94
+ platform ||= 'other'
95
+ [platform, platform + bits].collect { |p| File.join(basename, p) }
97
96
  end
98
97
 
99
98
  def get_library_paths(library_name, extension = nil)
100
- dir = get_library_directory_path(library_name, extension)
99
+ dir = get_library_directory_path(library_name, extension)
101
100
  Dir.glob("#{dir}/*.{rb,jar}")
102
101
  end
103
102
 
@@ -107,12 +106,12 @@ module Processing
107
106
  extensions = extension ? [extension] : %w{jar rb}
108
107
  extensions.each do |ext|
109
108
  [ "#{SKETCH_ROOT}/library/#{library_name}",
110
- "#{Processing::CONFIG["PROCESSING_ROOT"]}/modes/java/libraries/#{library_name}/library",
111
- "#{RP5_ROOT}/library/#{library_name}/library",
112
- "#{RP5_ROOT}/library/#{library_name}",
109
+ "#{Processing::RB_CONFIG['PROCESSING_ROOT']}/modes/java/libraries/#{library_name}/library",
110
+ "#{RP5_ROOT}/library/#{library_name}/library",
111
+ "#{RP5_ROOT}/library/#{library_name}",
113
112
  "#{@sketchbook_library_path}/#{library_name}/library",
114
- "#{@sketchbook_library_path}/#{library_name}"
115
- ].each do |path|
113
+ "#{@sketchbook_library_path}/#{library_name}"
114
+ ].each do |path|
116
115
  if File.exist?(path) && !Dir.glob(path + "/*.#{ext}").empty?
117
116
  return path
118
117
  end
@@ -124,14 +123,14 @@ module Processing
124
123
  def find_sketchbook_path
125
124
  preferences_paths = []
126
125
  sketchbook_paths = []
127
- if sketchbook_path = Processing::CONFIG["sketchbook_path"]
126
+ if sketchbook_path = Processing::RB_CONFIG['sketchbook_path']
128
127
  return File.expand_path(sketchbook_path)
129
128
  else
130
- ["'Application Data/Processing'", "AppData/Roaming/Processing",
131
- "Library/Processing", "Documents/Processing",
132
- ".processing", "sketchbook"].each do |prefix|
133
- path = "#{ENV["HOME"]}/#{prefix}"
134
- pref_path = path+"/preferences.txt"
129
+ ["'Application Data/Processing'", 'AppData/Roaming/Processing',
130
+ 'Library/Processing', 'Documents/Processing',
131
+ '.processing', 'sketchbook'].each do |prefix|
132
+ path = "#{ENV['HOME']}/#{prefix}"
133
+ pref_path = path+'/preferences.txt'
135
134
  if test(?f, pref_path)
136
135
  preferences_paths << pref_path
137
136
  end
@@ -148,6 +147,5 @@ module Processing
148
147
  return sketchbook_path
149
148
  end
150
149
  end
151
-
152
150
  end
153
151
  end