ruby-processing 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. data/CHANGELOG +12 -0
  2. data/README +3 -0
  3. data/lib/core/core.jar +0 -0
  4. data/lib/core/jruby-complete.jar +0 -0
  5. data/lib/patches/JRubyApplet.diff +24 -0
  6. data/lib/patches/PATCHES.txt +3 -0
  7. data/lib/patches/PApplet.diff +27 -0
  8. data/lib/ruby-processing.rb +4 -1
  9. data/lib/ruby-processing/app.rb +121 -75
  10. data/lib/ruby-processing/exporters/applet_exporter.rb +1 -1
  11. data/lib/ruby-processing/exporters/base_exporter.rb +21 -16
  12. data/lib/ruby-processing/exporters/creator.rb +12 -6
  13. data/lib/ruby-processing/runner.rb +2 -2
  14. data/lib/ruby-processing/runners/base.rb +59 -0
  15. data/lib/ruby-processing/runners/live.rb +2 -2
  16. data/lib/ruby-processing/runners/run.rb +2 -1
  17. data/lib/ruby-processing/runners/watch.rb +47 -11
  18. data/lib/templates/applet/index.html.erb +6 -6
  19. data/lib/templates/create/bare_sketch.rb.erb +7 -0
  20. data/lib/templates/create/blank_sketch.rb.erb +2 -2
  21. data/library/control_panel/control_panel.rb +6 -2
  22. data/library/opengl/library/export.txt +0 -0
  23. data/library/opengl/library/opengl.jar +0 -0
  24. data/library/pdf/library/itext.jar +0 -0
  25. data/library/pdf/library/pdf.jar +0 -0
  26. data/library/pdf/notes.txt +3 -4
  27. data/samples/animator.rb +35 -39
  28. data/samples/bezier_playground.rb +2 -4
  29. data/samples/fern.rb +34 -42
  30. data/samples/flight_patterns.rb +48 -54
  31. data/samples/full_screen.rb +20 -25
  32. data/samples/getting_started.rb +19 -39
  33. data/samples/learning_processing/chapter_01/1_stroke_and_fill.rb +14 -30
  34. data/samples/learning_processing/chapter_01/2_nofill.rb +18 -23
  35. data/samples/learning_processing/chapter_01/3_rgb_color.rb +16 -28
  36. data/samples/learning_processing/chapter_01/4_alpha_transparency.rb +7 -1
  37. data/samples/learning_processing/chapter_01/5_zoog.rb +20 -33
  38. data/samples/learning_processing/chapter_02/1_zoog_again.rb +3 -1
  39. data/samples/learning_processing/chapter_03/6_interactive_zoog.rb +34 -42
  40. data/samples/learning_processing/chapter_16/03_adjust_video_brightness.rb +49 -0
  41. data/samples/learning_processing/chapter_17/01_simple_displaying_text.rb +14 -0
  42. data/samples/learning_processing/chapter_17/02_text_align.rb +21 -0
  43. data/samples/learning_processing/chapter_17/03_scrolling_headlines.rb +35 -0
  44. data/samples/learning_processing/chapter_17/04_text_mirror.rb +68 -0
  45. data/samples/learning_processing/chapter_17/05_rotating_text.rb +22 -0
  46. data/samples/learning_processing/chapter_17/06_text_breaking_up.rb +73 -0
  47. data/samples/learning_processing/chapter_17/07_boxes_along_a_curve.rb +49 -0
  48. data/samples/learning_processing/chapter_17/08_characters_along_a_curve.rb +51 -0
  49. data/samples/learning_processing/chapter_17/data/ArialMT-16.vlw +0 -0
  50. data/samples/learning_processing/chapter_17/data/Courier-Bold-20.vlw +0 -0
  51. data/samples/learning_processing/chapter_18/01_user_input.rb +39 -0
  52. data/samples/learning_processing/chapter_18/02_graphing_comma_separated_numbers_from_a_text_file.rb +28 -0
  53. data/samples/learning_processing/chapter_18/03_creating_object_from_a_text_file.rb +64 -0
  54. data/samples/learning_processing/chapter_18/data/data-1.txt +1 -0
  55. data/samples/learning_processing/chapter_18/data/data-2.txt +10 -0
  56. data/samples/orbit.rb +45 -0
  57. data/samples/processing_app/basics/image/pointillism.rb +1 -1
  58. data/samples/processing_app/topics/effects/lens.rb +1 -0
  59. metadata +30 -13
  60. data/library/opengl/bin/processing/opengl/PGraphicsOpenGL$ImageCache.class +0 -0
  61. data/library/opengl/bin/processing/opengl/PGraphicsOpenGL$TessCallback.class +0 -0
  62. data/library/opengl/bin/processing/opengl/PGraphicsOpenGL.class +0 -0
  63. data/library/pdf/bin/processing/pdf/PGraphicsPDF.class +0 -0
@@ -1,10 +1,7 @@
1
- require 'ruby-processing'
2
-
3
1
  # A Bezier playground. Click to shape the curve. Drag to move it.
4
2
  # Arrows toggle between curves, delete removes them.
5
3
  # You can print out the parametric equations for t = 0..1
6
4
 
7
-
8
5
  module Math
9
6
 
10
7
  def self.overlaps(x, y, point_x, point_y)
@@ -75,6 +72,7 @@ class Bezier < Processing::App
75
72
  load_library :control_panel
76
73
 
77
74
  def setup
75
+ size 700, 700
78
76
  smooth
79
77
  @curves = []
80
78
 
@@ -240,4 +238,4 @@ class Bezier < Processing::App
240
238
 
241
239
  end
242
240
 
243
- Bezier.new :title => "Bezier", :width => 700, :height => 700
241
+ Bezier.new
data/samples/fern.rb CHANGED
@@ -1,49 +1,41 @@
1
1
  # The Fern Fractal
2
2
  # by Luis Correia
3
- #
4
- # port by omygawshkenas
5
-
6
- require 'ruby-processing'
3
+
4
+ def setup
5
+ size 500, 500
6
+ no_loop
7
+ puts "Be patient. This takes about 10 seconds to render."
8
+ end
7
9
 
8
- class Fern < Processing::App
10
+ def draw
11
+ background 0
12
+ load_pixels
13
+ x0, y0 = 0.0, 0.0
14
+ x, y, r = 0.0, 0.0, 0.0
15
+ i, j = 0, 0
16
+ max_iterations = 200000
9
17
 
10
- def setup
11
- no_loop
12
- puts "Be patient. This takes about 10 seconds to render."
13
- end
14
-
15
- def draw
16
- background 0
17
- load_pixels
18
- x0, y0 = 0.0, 0.0
19
- x, y, r = 0.0, 0.0, 0.0
20
- i, j = 0, 0
21
- max_iterations = 200000
22
-
23
- max_iterations.times do
24
- r = rand * 100
25
- if r <= 1
26
- x = 0.0
27
- y = 0.16 * y0
28
- elsif r <= 7
29
- x = 0.2 * x0 - 0.26 * y0
30
- y = 0.23 * x0 + 0.22 * y0
31
- elsif r <= 14
32
- x = -0.15 * x0 + 0.28 * y0
33
- y = 0.26 * x0 + 0.24 * y0
34
- else
35
- x = 0.85 * x0 + 0.04 * y0
36
- y = -0.004 * x0 + 0.85 * y0 + 1.6
37
- end
38
-
39
- i = height - (y * 45).to_i
40
- j = width / 2 + (x * 45).to_i
41
- pixels[i * height + j] += 2560 if (i >=0 && i < height && j >= 0 && j < width)
42
- x0, y0 = x, y
18
+ max_iterations.times do
19
+ r = rand * 100
20
+ if r <= 1
21
+ x = 0.0
22
+ y = 0.16 * y0
23
+ elsif r <= 7
24
+ x = 0.2 * x0 - 0.26 * y0
25
+ y = 0.23 * x0 + 0.22 * y0
26
+ elsif r <= 14
27
+ x = -0.15 * x0 + 0.28 * y0
28
+ y = 0.26 * x0 + 0.24 * y0
29
+ else
30
+ x = 0.85 * x0 + 0.04 * y0
31
+ y = -0.004 * x0 + 0.85 * y0 + 1.6
43
32
  end
44
33
 
45
- update_pixels
34
+ i = height - (y * 45).to_i
35
+ j = width / 2 + (x * 45).to_i
36
+ pixels[i * height + j] += 2560 if (i >=0 && i < height && j >= 0 && j < width)
37
+ x0, y0 = x, y
46
38
  end
47
- end
48
-
49
- Fern.new :title => "Fern", :width => 500, :height => 500
39
+
40
+ update_pixels
41
+ end
@@ -1,64 +1,58 @@
1
1
  # Description:
2
2
  # Flight Patterns is that ol' Euruko 2008 demo.
3
3
 
4
- require 'ruby-processing'
4
+ full_screen
5
+ load_libraries 'boids', 'opengl'
6
+ import "processing.opengl" if library_loaded? "opengl"
5
7
 
6
- class FlightPatterns < Processing::App
7
- load_libraries 'boids', 'opengl'
8
- import "processing.opengl" if library_loaded? "opengl"
8
+ def setup
9
+ library_loaded?(:opengl) ? setup_opengl : render_mode(P3D)
10
+ sphere_detail 8
11
+ color_mode RGB, 1.0
12
+ no_stroke
13
+ frame_rate 30
14
+ shininess 1.0
15
+ specular 0.3, 0.1, 0.1
16
+ emissive 0.03, 0.03, 0.1
9
17
 
10
- def setup
11
- library_loaded?(:opengl) ? setup_opengl : render_mode(P3D)
12
- sphere_detail 8
13
- color_mode RGB, 1.0
14
- no_stroke
15
- frame_rate 30
16
- shininess 1.0
17
- specular 0.3, 0.1, 0.1
18
- emissive 0.03, 0.03, 0.1
19
-
20
- @click = false
21
- @flocks = []
22
- 3.times do |i|
23
- flock = Boids.flock 20, 0, 0, width, height
24
- flock.goal width/2, height/2, 0
25
- @flocks << flock
26
- end
27
- end
28
-
29
- def setup_opengl
30
- render_mode OPENGL
31
- hint ENABLE_OPENGL_4X_SMOOTH
18
+ @click = false
19
+ @flocks = []
20
+ 3.times do |i|
21
+ flock = Boids.flock 20, 0, 0, width, height
22
+ flock.goal width/2, height/2, 0
23
+ @flocks << flock
32
24
  end
33
-
34
- def mouse_pressed
35
- @click = !@click
36
- end
37
-
38
- def draw
39
- background 0.05
40
- ambient_light 0.01, 0.01, 0.01
41
- light_specular 0.4, 0.2, 0.2
42
- point_light 1.0, 1.0, 1.0, mouse_x, mouse_y, 190
43
- @flocks.each_with_index do |flock, i|
44
- flock.goal mouse_x, mouse_y, 0, @flee
45
- flock.update(:goal => 185, :limit => 13.5)
46
- for boid in flock do
47
- r = 20 + (boid.z * 0.15)
48
- alpha = 0.5 + (boid.z * 0.01)
49
- case i
50
- when 0 then fill 0.55, 0.35, 0.35
51
- when 1 then fill 0.35, 0.55, 0.35
52
- when 2 then fill 0.35, 0.35, 0.55
53
- end
54
- push_matrix
55
- translate boid.x-r/2, boid.y-r/2, boid.z-r/2
56
- @click ? sphere(r/2) : oval(0, 0, r, r)
57
- pop_matrix
25
+ end
26
+
27
+ def setup_opengl
28
+ render_mode(OPENGL)
29
+ hint ENABLE_OPENGL_4X_SMOOTH
30
+ end
31
+
32
+ def mouse_pressed
33
+ @click = !@click
34
+ end
35
+
36
+ def draw
37
+ background 0.05
38
+ ambient_light 0.01, 0.01, 0.01
39
+ light_specular 0.4, 0.2, 0.2
40
+ point_light 1.0, 1.0, 1.0, mouse_x, mouse_y, 190
41
+ @flocks.each_with_index do |flock, i|
42
+ flock.goal mouse_x, mouse_y, 0, @flee
43
+ flock.update(:goal => 185, :limit => 13.5)
44
+ for boid in flock do
45
+ r = 20 + (boid.z * 0.15)
46
+ alpha = 0.5 + (boid.z * 0.01)
47
+ case i
48
+ when 0 then fill 0.55, 0.35, 0.35
49
+ when 1 then fill 0.35, 0.55, 0.35
50
+ when 2 then fill 0.35, 0.35, 0.55
58
51
  end
52
+ push_matrix
53
+ translate boid.x-r/2, boid.y-r/2, boid.z-r/2
54
+ @click ? sphere(r/2) : oval(0, 0, r, r)
55
+ pop_matrix
59
56
  end
60
57
  end
61
-
62
58
  end
63
-
64
- FlightPatterns.new(:title => "Flight Patterns", :width => 1100, :height => 800, :full_screen => true)
@@ -4,32 +4,27 @@
4
4
  # have the OpenGL library installed, you'll get *much*
5
5
  # smoother and faster drawing.
6
6
 
7
- require 'ruby-processing'
7
+ full_screen
8
+ load_library :opengl
8
9
 
9
- class FullScreen < Processing::App
10
- load_library :opengl
11
-
12
- def setup
13
- library_loaded?(:opengl) ? render_mode(OPENGL) : render_mode(P3D)
14
- no_stroke
15
- end
16
-
17
- def draw
18
- lights
19
- background 0
20
- fill 120, 160, 220
21
- (width/100).times do |x|
22
- (height/100).times do |y|
23
- new_x, new_y = x * 100, y * 100
24
- push_matrix
25
- translate new_x + 50, new_y + 50
26
- rotate_y(((mouse_x.to_f + new_x) / width) * Math::PI)
27
- rotate_x(((mouse_y.to_f + new_y) / height) * Math::PI)
28
- box 90
29
- pop_matrix
30
- end
10
+ def setup
11
+ library_loaded?(:opengl) ? render_mode(OPENGL) : render_mode(P3D)
12
+ no_stroke
13
+ end
14
+
15
+ def draw
16
+ lights
17
+ background 0
18
+ fill 120, 160, 220
19
+ (width/100).times do |x|
20
+ (height/100).times do |y|
21
+ new_x, new_y = x * 100, y * 100
22
+ push_matrix
23
+ translate new_x + 50, new_y + 50
24
+ rotate_y(((mouse_x.to_f + new_x) / width) * Math::PI)
25
+ rotate_x(((mouse_y.to_f + new_y) / height) * Math::PI)
26
+ box 90
27
+ pop_matrix
31
28
  end
32
29
  end
33
30
  end
34
-
35
- FullScreen.new(:full_screen => true, :title => "Full Screen", :width => 600, :height => 600)
@@ -1,43 +1,23 @@
1
- # So, let's get started: The first thing you may notice is
2
- # that there is a bunch more code around the edges here
3
- # than in vanilla Processing sketches. Ruby-Processing
4
- # doesn't perform any special code munging or pre-processing,
5
- # so what you see here is *just Ruby* taking advantage
6
- # of the Processing library.
7
-
8
- # Hence, this line, which loads in Processing.
9
- require 'ruby-processing'
10
-
11
- # Here we begin to define the Sketch by making it a
12
- # Processing App.
13
- class SampleApplication < Processing::App
1
+ # Let's define a setup method, for code that gets
2
+ # run one time when the app is started.
3
+ def setup
4
+ background 0
5
+ no_stroke
6
+ smooth
7
+ @rotation = 0
8
+ end
14
9
 
15
- # Now we define a setup method, for code that gets
16
- # run one time when the app is started.
17
- def setup
18
- background 0
19
- no_stroke
20
- smooth
21
- @rotation = 0
22
- end
10
+ # And the draw method which will be called repeatedly.
11
+ # Delete this if you don't need animation.
12
+ def draw
13
+ fill 0, 20
14
+ rect 0, 0, width, height
23
15
 
24
- # And the draw method which will be called repeatedly.
25
- # Delete this if you don't need animation.
26
- def draw
27
- fill 0, 20
28
- rect 0, 0, width, height
29
-
30
- translate width/2, height/2
31
- rotate @rotation
16
+ translate width/2, height/2
17
+ rotate @rotation
32
18
 
33
- fill 255
34
- ellipse 0, -60, 20, 20
35
-
36
- @rotation += 0.1
37
- end
38
-
39
- end
19
+ fill 255
20
+ ellipse 0, -60, 20, 20
40
21
 
41
- # Now that the sketch is defined, we can start one up.
42
- # The following line does this, passing in the title, width, and height.
43
- SampleApplication.new(:width => 200, :height => 200, :title => "SampleApplication")
22
+ @rotation += 0.1
23
+ end
@@ -1,34 +1,18 @@
1
- # So, let's get started: The first thing you may notice is
2
- # that there is a bunch more code around the edges here
3
- # than in the Learning Processing example. Ruby-Processing
4
- # doesn't perform any special munging or pre-processing,
5
- # so what you see here is *just Ruby* taking advantage
6
- # of the Processing library.
1
+ # This is the simplest form of a Ruby-Processing sketch. A simple sequence
2
+ # of instructions that are run a single time to paint a picture.
7
3
 
8
- # Hence, this line, which loads in Processing.
9
- require 'ruby-processing'
4
+ # Stretch the canvas to 200 pixels wide by 200 pixels tall.
5
+ size 200, 200
10
6
 
11
- # Here we begin to define the Sketch by making it a
12
- # Processing App.
13
- class StrokeAndFill < Processing::App
7
+ # Paint the background white.
8
+ background 255
14
9
 
15
- # Now we define a setup method, for code that gets
16
- # run one time when the app is started.
17
- def setup
18
- background 255
19
- stroke 0
20
- fill 150
21
- rect 50, 50, 75, 100
22
- end
23
-
24
- # And the draw method has nothing inside of it.
25
- # If it did, the code inside would be run repeatedly.
26
- def draw
27
-
28
- end
29
-
30
- end
10
+ # Set the color of strokes to black.
11
+ stroke 0
31
12
 
32
- # Now that the sketch is defined, we can start one up.
33
- # The following line does this, passing in the title, width, and height.
34
- StrokeAndFill.new :title => "Stroke And Fill", :width => 200, :height => 200
13
+ # Set the color of fills to middle gray.
14
+ fill 150
15
+
16
+ # Draw a rectangle 50 pixels over and 50 pixels down from the top left corner,
17
+ # with a width of 75 pixels and a height of 100.
18
+ rect 50, 50, 75, 100
@@ -1,25 +1,20 @@
1
- require 'ruby-processing'
2
-
3
- class NofillApp < Processing::App
4
-
5
- def setup
6
- smooth
7
- background 255
8
- # In Ruby, methods and variables are under_scored instead of camelCased
9
- no_fill
10
- stroke 0
11
- # You might notice that there are no parenthesis or semicolons.
12
- # That's because they're optional.
13
- ellipse 60, 60, 100, 100
14
- # This line works too:
15
- ellipse(60, 60, 100, 100);
16
- end
17
-
18
- def draw
19
-
20
- end
21
-
1
+ # Here we introduce a slightly more sophisticated version of a Ruby-Processing
2
+ # sketch. The code inside of the setup is run a single time, at the beginning.
3
+ def setup
4
+ size 200, 200
5
+ smooth
6
+ background 255
7
+ # In Ruby, methods and variables are under_scored instead of camelCased
8
+ no_fill
9
+ stroke 0
10
+ # You might notice that there are no parenthesis or semicolons.
11
+ # That's because they're optional.
12
+ ellipse 60, 60, 100, 100
13
+ # This line works too:
14
+ ellipse(60, 60, 100, 100);
22
15
  end
23
16
 
24
- # The names of classes are still camel cased.
25
- NofillApp.new :title => "Nofill", :width => 200, :height => 200
17
+ # And the code inside of draw, if there were any, would be drawn over and over.
18
+ def draw
19
+
20
+ end
@@ -1,31 +1,19 @@
1
- require 'ruby-processing'
2
-
3
1
  # RGB color is specified by intensity of red, then green, then blue.
4
- class RgbColor < Processing::App
5
2
 
6
- def setup
7
- smooth
8
-
9
- background 255
10
- no_stroke
11
-
12
- # Bright red
13
- fill 255, 0, 0
14
- ellipse 20, 20, 16, 16
15
-
16
- # Dark red
17
- fill 127, 0, 0
18
- ellipse 40, 20, 16, 16
19
-
20
- # Pink
21
- fill 255, 200, 200
22
- ellipse 60, 20, 16, 16
23
- end
24
-
25
- def draw
26
-
27
- end
28
-
29
- end
3
+ size 200, 200
4
+ smooth
5
+
6
+ background 255
7
+ no_stroke
8
+
9
+ # Bright red
10
+ fill 255, 0, 0
11
+ ellipse 20, 20, 16, 16
12
+
13
+ # Dark red
14
+ fill 127, 0, 0
15
+ ellipse 40, 20, 16, 16
30
16
 
31
- RgbColor.new :title => "Rgb Color", :width => 200, :height => 200
17
+ # Pink
18
+ fill 255, 200, 200
19
+ ellipse 60, 20, 16, 16