ruby-processing 1.0.3 → 1.0.4

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 (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,5 +1,9 @@
1
- require 'ruby-processing'
1
+ # This sketch introduces the fuller version of a Ruby-Processing sketch,
2
+ # and demonstrates what's really going on behind the scenes when you make
3
+ # one of the simpler sketches, with just a setup method.
2
4
 
5
+ # A sketch is a class that inherits from the Processing::App, which works
6
+ # very much along the lines of a PApplet in Processing.
3
7
  class AlphaTransparency < Processing::App
4
8
 
5
9
  def setup
@@ -33,4 +37,6 @@ class AlphaTransparency < Processing::App
33
37
 
34
38
  end
35
39
 
40
+ # After defining your sketch, you create one.
41
+ # If you prefer, you may set the width, height, and title as you create it.
36
42
  AlphaTransparency.new :title => "Alpha Transparency", :width => 200, :height => 200
@@ -1,37 +1,24 @@
1
- require 'ruby-processing'
1
+ size 200, 200
2
+ background 255
3
+ smooth
4
+ ellipse_mode CENTER
5
+ rect_mode CENTER
2
6
 
3
- class Zoog < Processing::App
7
+ # Body
8
+ stroke 0
9
+ fill 150
10
+ rect 100, 100, 20, 100
4
11
 
5
- def setup
6
- background 255
7
- smooth
8
- ellipse_mode CENTER
9
- rect_mode CENTER
12
+ # Head
13
+ fill 255
14
+ ellipse 100, 70, 60, 60
10
15
 
11
- # Body
12
- stroke 0
13
- fill 150
14
- rect 100, 100, 20, 100
16
+ # Eyes
17
+ fill 0
18
+ ellipse 81, 70, 16, 32
19
+ ellipse 119, 70, 16, 32
15
20
 
16
- # Head
17
- fill 255
18
- ellipse 100, 70, 60, 60
19
-
20
- # Eyes
21
- fill 0
22
- ellipse 81, 70, 16, 32
23
- ellipse 119, 70, 16, 32
24
-
25
- # Legs
26
- stroke 0
27
- line 90, 150, 80, 160
28
- line 110, 150, 120, 160
29
- end
30
-
31
- def draw
32
-
33
- end
34
-
35
- end
36
-
37
- Zoog.new :title => "Zoog", :width => 200, :height => 200
21
+ # Legs
22
+ stroke 0
23
+ line 90, 150, 80, 160
24
+ line 110, 150, 120, 160
@@ -1,4 +1,6 @@
1
- require 'ruby-processing'
1
+ # Let's do Zoog again, as part of a complete sketch, showing the class for it,
2
+ # with setup and draw methods, and sketch creation at the bottom.
3
+
2
4
 
3
5
  class ZoogAgain < Processing::App
4
6
 
@@ -1,50 +1,42 @@
1
- require 'ruby-processing'
2
-
3
- class InteractiveZoog < Processing::App
1
+ def setup
2
+ smooth
3
+ # The frame rate (like a movie) is set to 30 frames per second
4
+ frame_rate 30
5
+ end
4
6
 
5
- def setup
6
- smooth
7
- # The frame rate (like a movie) is set to 30 frames per second
8
- frame_rate 30
9
- end
7
+ def draw
8
+ # draw a white background
9
+ background 255
10
10
 
11
- def draw
12
- # draw a white background
13
- background 255
14
-
15
- # Set ellipses and rects to CENTER mode
16
- ellipse_mode CENTER
17
- rect_mode CENTER
11
+ # Set ellipses and rects to CENTER mode
12
+ ellipse_mode CENTER
13
+ rect_mode CENTER
18
14
 
19
- # Draw Zoog's body
20
- stroke 0
21
- fill 150
22
- rect mouse_x, mouse_y, 20, 100
15
+ # Draw Zoog's body
16
+ stroke 0
17
+ fill 150
18
+ rect mouse_x, mouse_y, 20, 100
23
19
 
24
- # Draw Zoog's head
25
- stroke 0
26
- fill 255
27
- ellipse mouse_x, mouse_y - 30, 60, 60
20
+ # Draw Zoog's head
21
+ stroke 0
22
+ fill 255
23
+ ellipse mouse_x, mouse_y - 30, 60, 60
28
24
 
29
- # Draw Zoog's eyes
30
- # The eye color is determined by mouse location.
31
- fill mouse_x, 0, mouse_y
32
- ellipse mouse_x - 19, mouse_y - 30, 16, 32
33
- ellipse mouse_x + 19, mouse_y - 30, 16, 32
25
+ # Draw Zoog's eyes
26
+ # The eye color is determined by mouse location.
27
+ fill mouse_x, 0, mouse_y
28
+ ellipse mouse_x - 19, mouse_y - 30, 16, 32
29
+ ellipse mouse_x + 19, mouse_y - 30, 16, 32
34
30
 
35
- # Draw Zoog's legs
36
- stroke 0
37
- # The legs are drawn according to where the mouse is now and where it used to be.
38
- line mouse_x - 10, mouse_y + 50, pmouse_x - 10, pmouse_y + 60
39
- line mouse_x + 10, mouse_y + 50, pmouse_x + 10, pmouse_y + 60
40
- end
41
-
42
- def mouse_pressed
43
- # In Ruby, you can call 'puts' to print to the console.
44
- # 'print' also works (but doesn't make a new line).
45
- puts 'Take me to your leader!'
46
- end
47
-
31
+ # Draw Zoog's legs
32
+ stroke 0
33
+ # The legs are drawn according to where the mouse is now and where it used to be.
34
+ line mouse_x - 10, mouse_y + 50, pmouse_x - 10, pmouse_y + 60
35
+ line mouse_x + 10, mouse_y + 50, pmouse_x + 10, pmouse_y + 60
48
36
  end
49
37
 
50
- InteractiveZoog.new :title => "Interactive Zoog?", :width => 200, :height => 200
38
+ def mouse_pressed
39
+ # In Ruby, you can call 'puts' to print to the console.
40
+ # 'print' also works (but doesn't make a new line).
41
+ puts 'Take me to your leader!'
42
+ end
@@ -0,0 +1,49 @@
1
+ # Example 16-3: Adjust video brightness
2
+ require 'ruby-processing'
3
+
4
+ class AdjustVideoBrightness < Processing::App
5
+ load_library "video"
6
+ import "processing.video"
7
+
8
+ def setup
9
+ size 240, 180, P3D
10
+
11
+ # Initialize Capture object via Constructor
12
+ # video is 320 x 240, @15 fps
13
+ @video = Capture.new self, 240, 180, 15
14
+ background 0
15
+ end
16
+
17
+ def draw
18
+ # Check to see if a new frame is available
19
+ # If so, read it.
20
+ @video.read if @video.available?
21
+
22
+ load_pixels
23
+ @video.load_pixels
24
+ pixs = @video.pixels
25
+ mx, my = mouse_x, mouse_y
26
+ max_dist = 100
27
+ vid_width, vid_height = @video.width, @video.height
28
+
29
+ vid_width.times do |x|
30
+ vid_height.times do |y|
31
+ # Calculate the 1D location from a 2D grid
32
+ loc = x + y * vid_width
33
+ pix = pixs[loc]
34
+
35
+ # Calculate an amount to change brightness based on proximity to the mouse
36
+ d = dist(x, y, mx, my)
37
+ fudge = (max_dist - d) / max_dist
38
+ r, g, b = red(pix) * fudge, green(pix) * fudge, blue(pix) * fudge
39
+
40
+ # Make a new color and set pixel in the window
41
+ pixels[loc] = color(r, g, b)
42
+ end
43
+ end
44
+ update_pixels
45
+ end
46
+
47
+ end
48
+
49
+ AdjustVideoBrightness.new :title => "Adjust Video Brightness"
@@ -0,0 +1,14 @@
1
+ def setup
2
+ size 200, 200
3
+ # Load Font
4
+ @font = loadFont "ArialMT-16.vlw"
5
+ end
6
+
7
+ def draw
8
+ background 255
9
+ text_font @font, 16 # Specify font to be used
10
+ fill 0 # Specify font color
11
+
12
+ # Display Text
13
+ text "Mmmmm ... Strings ..." , 10, 100
14
+ end
@@ -0,0 +1,21 @@
1
+ def setup
2
+ size 400, 200
3
+ @font = create_font "Arial", 16, true
4
+ end
5
+
6
+ def draw
7
+ background 255
8
+ stroke 175
9
+ line width/2, 0, width/2, height
10
+ text_font @font
11
+ fill 0
12
+
13
+ # text_align sets the alignment for displaying text.
14
+ # It takes one argument: CENTER, LEFT, or RIGHT.
15
+ text_align CENTER
16
+ text "This text is centered.", width / 2, 60
17
+ text_align LEFT
18
+ text "This text is left aligned.", width/2, 100
19
+ text_align RIGHT
20
+ text "This text is right aligned.", width / 2, 140
21
+ end
@@ -0,0 +1,35 @@
1
+ HEADLINES = "Processing downloads break downloading record.",
2
+ "New study shows computer programming lowers cholesterol."
3
+
4
+ def setup
5
+ size 400, 200
6
+ @f = create_font "Arial" ,16, true
7
+ @x = width
8
+ @index = 0
9
+ end
10
+
11
+ def draw
12
+ background 255
13
+ fill 0
14
+
15
+ # Display headline at x location
16
+ text_font @f, 16
17
+ text_align LEFT
18
+
19
+ # A specific string from the array is displayed according to the value
20
+ # of the "index" variable.
21
+ text HEADLINES[@index], @x, 180
22
+
23
+ # Decrement x
24
+ @x = @x - 3
25
+
26
+ # If x is less than the negative width, then it is off the screen
27
+ # text_width is used to calculate the width of the current string.
28
+ w = text_width(HEADLINES[@index])
29
+ if (@x < -w)
30
+ @x = width
31
+ # @index is incremented when the current string has left
32
+ # the screen in order to display a new string.
33
+ @index = (@index + 1) % HEADLINES.length
34
+ end
35
+ end
@@ -0,0 +1,68 @@
1
+ # This example demonstrates how to use the video library. You'll need a
2
+ # video camera hooked in to your computer.
3
+
4
+ class TextMirror < Processing::App
5
+ load_library "video"
6
+ import "processing.video"
7
+
8
+ # Size of each cell in the grid, ratio of window size to video size
9
+ VIDEOSCALE = 14
10
+
11
+ # The source text used in the mosaic pattern.
12
+ # A longer String might produce more interesting results.
13
+ CHARS = "thetextmirror"
14
+
15
+ def setup
16
+ size 640, 480
17
+ smooth
18
+ # Set up columns and rows
19
+ @cols = width / VIDEOSCALE # Number of columns and...
20
+ @rows = height / VIDEOSCALE # rows in our system
21
+ @video = Capture.new(self, @cols, @rows, 15)
22
+
23
+ # Load the font
24
+ # Using a fixed-width font. In most fonts, individual characters have different widths.
25
+ # In a fixed-width font, all characters have the same width.
26
+ # This is useful here since we intend to display the letters one at a time spaced out evenly.
27
+ # See Section 17.7 for how to display text character by character with a nonfixed width font.
28
+ @f = load_font "Courier-Bold-20.vlw"
29
+ end
30
+
31
+ def draw
32
+ background 0
33
+
34
+ # Read image from the camera
35
+ @video.read if @video.available?
36
+ @video.load_pixels
37
+
38
+ # Use a variable to count through chars in String
39
+ charcount = 0
40
+ # Begin loop for rows
41
+ @rows.times do |j|
42
+ # Begin loop for columns
43
+ @cols.times do |i|
44
+
45
+ # Where are we, pixel-wise?
46
+ x = i * VIDEOSCALE
47
+ y = j * VIDEOSCALE
48
+
49
+ # Looking up the appropriate color in the pixel array
50
+ c = @video.pixels[i + j * @video.width]
51
+
52
+ # Displaying an individual character from the String instead of a rectangle
53
+ text_font @f
54
+ fill c
55
+
56
+ # One character from the source text is displayed colored accordingly to the pixel location.
57
+ # A counter variableâ charcountâ is used to walk through the source String one character at a time.
58
+ text CHARS[charcount].chr, x, y
59
+
60
+ # Go on to the next character
61
+ charcount = (charcount + 1) % CHARS.length
62
+ end
63
+ end
64
+ end
65
+
66
+ end
67
+
68
+ TextMirror.new :title => "Text Mirror"
@@ -0,0 +1,22 @@
1
+ def setup
2
+ size 200, 200
3
+ @message = "this text is spinning"
4
+ @theta = 0.0
5
+ @f = create_font "Arial", 20, true
6
+ end
7
+
8
+ def draw
9
+ background 255
10
+ fill 0
11
+ text_font @f # Set the font
12
+ translate width / 2, height / 2 # Translate to the center
13
+ rotate @theta # Rotate by theta
14
+ text_align CENTER
15
+
16
+ # The text is center aligned and displayed at 0,0) after translating and rotating.
17
+ # See Chapter 14 or a review of translation and rotation.
18
+ text @message, 0, 0
19
+
20
+ # Increase rotation
21
+ @theta += 0.05;
22
+ end
@@ -0,0 +1,73 @@
1
+ require 'ruby-processing'
2
+
3
+ class TextBreakingUp < Processing::App
4
+
5
+ def setup
6
+ size 260, 200
7
+ fill 0
8
+ text_align LEFT
9
+ text_font create_font("Arial", 20, true)
10
+ @message = "click mouse to shake it up"
11
+
12
+ # Create the array
13
+ @letters = []
14
+
15
+ # Initialize Letters at the correct x location
16
+ x = 16
17
+ @message.each do |letter|
18
+ # Letter objects are initialized with their location within
19
+ # the String as well as what character they should display.
20
+ @letters << Letter.new(x, 100, letter)
21
+ x += text_width(letter)
22
+ end
23
+ end
24
+
25
+ def draw
26
+ background 255
27
+ @letters.each do |letter|
28
+ letter.display
29
+ # If the mouse is pressed the letters shake
30
+ # If not, they return to their original location
31
+ mouse_pressed? ? letter.shake : letter.home
32
+ end
33
+ end
34
+
35
+ end
36
+
37
+ # A class to describe a single Letter
38
+ class Letter
39
+ # The letter that this instance represents
40
+ attr_reader :letter
41
+
42
+ # The object knows its original "home" location...
43
+ attr_reader :homex, :homey
44
+
45
+ # As well as its current location
46
+ attr_reader :x, :y
47
+
48
+ def initialize(x, y, letter)
49
+ @home_x = @x = x
50
+ @home_y = @y = y
51
+ @letter = letter
52
+ end
53
+
54
+ # Display the letter
55
+ def display
56
+ $app.text @letter, @x, @y
57
+ end
58
+
59
+ # Move the letter randomly
60
+ def shake
61
+ @x += rand * 4 - 2
62
+ @y += rand * 4 - 2
63
+ end
64
+
65
+ # At any point, the current location can be set back to
66
+ # the home location by calling the home() method.
67
+ def home
68
+ @x = @home_x
69
+ @y = @home_y
70
+ end
71
+ end
72
+
73
+ TextBreakingUp.new :title => "Text Breaking Up"