ruby-processing 1.0.4 → 1.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (136) hide show
  1. data/CHANGELOG +8 -0
  2. data/lib/patches/JRubyApplet.diff +0 -0
  3. data/lib/patches/PATCHES.txt +0 -0
  4. data/lib/patches/PApplet.diff +0 -0
  5. data/lib/ruby-processing.rb +1 -1
  6. data/lib/ruby-processing/app.rb +20 -1
  7. data/lib/ruby-processing/exporters/base_exporter.rb +1 -1
  8. data/lib/ruby-processing/exporters/creator.rb +1 -2
  9. data/lib/ruby-processing/runner.rb +4 -3
  10. data/lib/ruby-processing/runners/watch.rb +2 -2
  11. data/lib/templates/applet/index.html.erb +1 -1
  12. metadata +2 -145
  13. data/samples/learning_processing/ABOUT +0 -11
  14. data/samples/learning_processing/chapter_01/1_stroke_and_fill.rb +0 -18
  15. data/samples/learning_processing/chapter_01/2_nofill.rb +0 -20
  16. data/samples/learning_processing/chapter_01/3_rgb_color.rb +0 -19
  17. data/samples/learning_processing/chapter_01/4_alpha_transparency.rb +0 -42
  18. data/samples/learning_processing/chapter_01/5_zoog.rb +0 -24
  19. data/samples/learning_processing/chapter_02/1_zoog_again.rb +0 -41
  20. data/samples/learning_processing/chapter_03/1_zoog_as_dynamic_sketch.rb +0 -44
  21. data/samples/learning_processing/chapter_03/2_mouse_x_and_mouse_y.rb +0 -26
  22. data/samples/learning_processing/chapter_03/3_zoog_as_dynamic_sketch_with_variation.rb +0 -41
  23. data/samples/learning_processing/chapter_03/4_drawing_a_continuous_line.rb +0 -18
  24. data/samples/learning_processing/chapter_03/5_mouse_pressed_and_key_pressed.rb +0 -29
  25. data/samples/learning_processing/chapter_03/6_interactive_zoog.rb +0 -42
  26. data/samples/learning_processing/chapter_04/1_variable_declaration.rb +0 -24
  27. data/samples/learning_processing/chapter_04/2_using_variables.rb +0 -27
  28. data/samples/learning_processing/chapter_04/3_varying_variables.rb +0 -27
  29. data/samples/learning_processing/chapter_04/4_many_variables.rb +0 -38
  30. data/samples/learning_processing/chapter_04/5_using_system_variables.rb +0 -28
  31. data/samples/learning_processing/chapter_04/6_ellipse_with_variables.rb +0 -24
  32. data/samples/learning_processing/chapter_04/7_filling_variables_with_random_values.rb +0 -27
  33. data/samples/learning_processing/chapter_04/8_variable_zoog.rb +0 -50
  34. data/samples/learning_processing/chapter_05/01_conditionals.rb +0 -31
  35. data/samples/learning_processing/chapter_05/02_more_conditionals.rb +0 -38
  36. data/samples/learning_processing/chapter_05/03_rollovers.rb +0 -34
  37. data/samples/learning_processing/chapter_05/04_hold_down_the_button.rb +0 -33
  38. data/samples/learning_processing/chapter_05/05_button_as_switch.rb +0 -39
  39. data/samples/learning_processing/chapter_05/06_bouncing_ball.rb +0 -33
  40. data/samples/learning_processing/chapter_05/07_bouncing_color.rb +0 -37
  41. data/samples/learning_processing/chapter_05/08_square_following_edge.rb +0 -59
  42. data/samples/learning_processing/chapter_05/09_simple_gravity.rb +0 -43
  43. data/samples/learning_processing/chapter_05/10_zoog_and_conditionals.rb +0 -53
  44. data/samples/learning_processing/chapter_06/01_many_lines.rb +0 -29
  45. data/samples/learning_processing/chapter_06/02_many_lines_with_variables.rb +0 -53
  46. data/samples/learning_processing/chapter_06/03_while_loop.rb +0 -30
  47. data/samples/learning_processing/chapter_06/04_infinite_loop.rb +0 -25
  48. data/samples/learning_processing/chapter_06/05_another_infinite_loop.rb +0 -33
  49. data/samples/learning_processing/chapter_06/06_legs_with_a_for_loop.rb +0 -41
  50. data/samples/learning_processing/chapter_06/07_local_variables.rb +0 -39
  51. data/samples/learning_processing/chapter_06/08_lines_one_at_a_time.rb +0 -30
  52. data/samples/learning_processing/chapter_06/09_simple_while_loop_with_interactivity.rb +0 -41
  53. data/samples/learning_processing/chapter_06/10_zoog_with_arms.rb +0 -56
  54. data/samples/learning_processing/chapter_06/11_multiple_zoogs.rb +0 -46
  55. data/samples/learning_processing/chapter_07/01_defining_a_function.rb +0 -22
  56. data/samples/learning_processing/chapter_07/02_calling_a_function.rb +0 -22
  57. data/samples/learning_processing/chapter_07/03_bouncing_ball_with_functions.rb +0 -49
  58. data/samples/learning_processing/chapter_07/04_function_returns_distance.rb +0 -48
  59. data/samples/learning_processing/chapter_07/05_zoog_with_functions.rb +0 -71
  60. data/samples/learning_processing/chapter_08/01_car_class_and_car_variable.rb +0 -45
  61. data/samples/learning_processing/chapter_08/02_two_car_objects.rb +0 -60
  62. data/samples/learning_processing/chapter_08/03_object_oriented_zoog.rb +0 -81
  63. data/samples/learning_processing/chapter_10/01_catcher.rb +0 -35
  64. data/samples/learning_processing/chapter_10/02_bouncing_ball.rb +0 -44
  65. data/samples/learning_processing/chapter_10/03_bouncing_balls_with_intersection.rb +0 -69
  66. data/samples/learning_processing/chapter_10/04_a_timer.rb +0 -24
  67. data/samples/learning_processing/chapter_10/05_object_oriented_timer.rb +0 -42
  68. data/samples/learning_processing/chapter_10/06_simple_raindrop.rb +0 -23
  69. data/samples/learning_processing/chapter_10/07_drops_one_at_a_time.rb +0 -63
  70. data/samples/learning_processing/chapter_13/02_random_number_distribution.rb +0 -24
  71. data/samples/learning_processing/chapter_13/03_probabilities.rb +0 -33
  72. data/samples/learning_processing/chapter_13/04_perlin_noise.rb +0 -22
  73. data/samples/learning_processing/chapter_13/06_oscillation.rb +0 -29
  74. data/samples/learning_processing/chapter_13/07_wave.rb +0 -31
  75. data/samples/learning_processing/chapter_13/08_recursion.rb +0 -30
  76. data/samples/learning_processing/chapter_13/09_two_dimensional_array.rb +0 -21
  77. data/samples/learning_processing/chapter_13/10_two_dimensional_array_with_objects.rb +0 -54
  78. data/samples/learning_processing/chapter_14/01_growing_rectangle.rb +0 -26
  79. data/samples/learning_processing/chapter_14/02_multiple_translations.rb +0 -37
  80. data/samples/learning_processing/chapter_14/03_depth_rectangle.rb +0 -29
  81. data/samples/learning_processing/chapter_14/04_pyramid_using_beingshape.rb +0 -55
  82. data/samples/learning_processing/chapter_14/05_rotate_rectangle_around_center.rb +0 -28
  83. data/samples/learning_processing/chapter_14/06_rotate_z.rb +0 -24
  84. data/samples/learning_processing/chapter_14/07_rotate_x.rb +0 -24
  85. data/samples/learning_processing/chapter_14/08_rotate_y.rb +0 -24
  86. data/samples/learning_processing/chapter_14/09_rotate_all.rb +0 -24
  87. data/samples/learning_processing/chapter_14/10_draw_pyramid.rb +0 -59
  88. data/samples/learning_processing/chapter_14/12_rotating_one_square.rb +0 -25
  89. data/samples/learning_processing/chapter_14/13_rotating_another_square.rb +0 -25
  90. data/samples/learning_processing/chapter_14/14_rotating_both_squares.rb +0 -43
  91. data/samples/learning_processing/chapter_14/15_rotating_many_things.rb +0 -56
  92. data/samples/learning_processing/chapter_14/16_simple_solar_system.rb +0 -53
  93. data/samples/learning_processing/chapter_14/17_nested_push_and_pop.rb +0 -50
  94. data/samples/learning_processing/chapter_14/18_object_oriented_solar_system.rb +0 -69
  95. data/samples/learning_processing/chapter_15/01_hello_world_image.rb +0 -20
  96. data/samples/learning_processing/chapter_15/02_image_sprite.rb +0 -29
  97. data/samples/learning_processing/chapter_15/03_swapping_images.rb +0 -25
  98. data/samples/learning_processing/chapter_15/04_image_sequence.rb +0 -22
  99. data/samples/learning_processing/chapter_15/05_setting_pixels.rb +0 -19
  100. data/samples/learning_processing/chapter_15/06_pixels_2d.rb +0 -29
  101. data/samples/learning_processing/chapter_15/07_image_pixels.rb +0 -40
  102. data/samples/learning_processing/chapter_15/08_image_brightness.rb +0 -29
  103. data/samples/learning_processing/chapter_15/09_flashlight_effect.rb +0 -42
  104. data/samples/learning_processing/chapter_15/10_brightness_threshold.rb +0 -33
  105. data/samples/learning_processing/chapter_15/11_brightness_threshold_with_filter.rb +0 -20
  106. data/samples/learning_processing/chapter_15/12_pixel_neighbour_differences.rb +0 -43
  107. data/samples/learning_processing/chapter_15/14_pointillism.rb +0 -34
  108. data/samples/learning_processing/chapter_15/15_2d_image_mapped_to_3d.rb +0 -43
  109. data/samples/learning_processing/chapter_15/data/animal0.jpg +0 -0
  110. data/samples/learning_processing/chapter_15/data/animal1.jpg +0 -0
  111. data/samples/learning_processing/chapter_15/data/animal2.jpg +0 -0
  112. data/samples/learning_processing/chapter_15/data/animal3.jpg +0 -0
  113. data/samples/learning_processing/chapter_15/data/animal4.jpg +0 -0
  114. data/samples/learning_processing/chapter_15/data/animal5.jpg +0 -0
  115. data/samples/learning_processing/chapter_15/data/animal6.jpg +0 -0
  116. data/samples/learning_processing/chapter_15/data/face.jpg +0 -0
  117. data/samples/learning_processing/chapter_15/data/mysummervacation.jpg +0 -0
  118. data/samples/learning_processing/chapter_15/data/sunflower.jpg +0 -0
  119. data/samples/learning_processing/chapter_16/01_display_video.rb +0 -25
  120. data/samples/learning_processing/chapter_16/02_manipulate_video_image.rb +0 -24
  121. data/samples/learning_processing/chapter_16/03_adjust_video_brightness.rb +0 -49
  122. data/samples/learning_processing/chapter_17/01_simple_displaying_text.rb +0 -14
  123. data/samples/learning_processing/chapter_17/02_text_align.rb +0 -21
  124. data/samples/learning_processing/chapter_17/03_scrolling_headlines.rb +0 -35
  125. data/samples/learning_processing/chapter_17/04_text_mirror.rb +0 -68
  126. data/samples/learning_processing/chapter_17/05_rotating_text.rb +0 -22
  127. data/samples/learning_processing/chapter_17/06_text_breaking_up.rb +0 -73
  128. data/samples/learning_processing/chapter_17/07_boxes_along_a_curve.rb +0 -49
  129. data/samples/learning_processing/chapter_17/08_characters_along_a_curve.rb +0 -51
  130. data/samples/learning_processing/chapter_17/data/ArialMT-16.vlw +0 -0
  131. data/samples/learning_processing/chapter_17/data/Courier-Bold-20.vlw +0 -0
  132. data/samples/learning_processing/chapter_18/01_user_input.rb +0 -39
  133. data/samples/learning_processing/chapter_18/02_graphing_comma_separated_numbers_from_a_text_file.rb +0 -28
  134. data/samples/learning_processing/chapter_18/03_creating_object_from_a_text_file.rb +0 -64
  135. data/samples/learning_processing/chapter_18/data/data-1.txt +0 -1
  136. data/samples/learning_processing/chapter_18/data/data-2.txt +0 -10
@@ -1,22 +0,0 @@
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
@@ -1,73 +0,0 @@
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"
@@ -1,49 +0,0 @@
1
- def setup
2
- size 320, 320
3
- rect_mode CENTER
4
- smooth
5
- @r = 100 # The radius of a circle
6
- @w, @h = 40, 40 # The width and height of the boxes
7
- end
8
-
9
- def draw
10
- background 255
11
-
12
- # Start in the center and draw the circle
13
- translate width/2, height/2
14
- no_fill
15
- stroke 0
16
-
17
- # Our curve is a circle with radius r in the center of the window.
18
- ellipse 0, 0, @r*2, @r*2
19
-
20
- # 10 boxes along the curve
21
- total_boxes = 10
22
-
23
- # @we must keep track of our position along the curve
24
- arc_length = 0
25
-
26
- # For every box
27
- total_boxes.times do |i|
28
- # Each box is centered so we move half the width
29
- arc_length += @w / 2.0
30
-
31
- # Angle in radians is the arclength divided by the radius
32
- theta = arc_length / @r
33
-
34
- push_matrix
35
- # Polar to cartesian coordinate conversion
36
- translate @r * cos(theta), @r * sin(theta)
37
-
38
- # @rotate the box
39
- rotate theta
40
-
41
- # Display the box
42
- fill 0, 100
43
- rect 0, 0, @w, @h
44
- pop_matrix
45
-
46
- # Move halfway again
47
- arc_length += @w / 2
48
- end
49
- end
@@ -1,51 +0,0 @@
1
- def setup
2
- size 320, 320
3
- @message = "text along a curve" # The message to be displayed
4
- @r = 100 # The radius of a circle
5
- text_font create_font("Georgia", 40, true)
6
- text_align CENTER # The text must be centered!
7
- smooth
8
- end
9
-
10
- def draw
11
- background 255
12
-
13
- # Start in the center and draw the circle
14
- translate width/2, height/2
15
- no_fill
16
- ellipse 0, 0, @r*2, @r*2
17
-
18
- # We must keep track of our position along the curve
19
- arc_length = 0
20
-
21
- # For every box
22
- @message.each_byte do |char|
23
- # Instead of a constant width, we check the width of each character.
24
- w = text_width(char.chr)
25
-
26
- # Each box is centered so we move half the width
27
- arc_length += w / 2
28
-
29
- # Angle in radians is the arc_length divided by the radius
30
- # Starting on the left side of the circle by adding PI
31
- theta = PI + arc_length / @r
32
-
33
- push_matrix
34
-
35
- # Polar to Cartesian conversion allows us to find the point along the curve.
36
- # See Chapter 13 for a review of this concept.
37
- translate @r * cos(theta), @r * sin(theta)
38
-
39
- # Rotate the box (rotation is offset by 90 degrees)
40
- rotate theta + PI / 2
41
-
42
- # Display the character
43
- fill 0
44
- text char, 0, 0
45
-
46
- pop_matrix
47
-
48
- # Move halfway again
49
- arc_length += w / 2
50
- end
51
- end
@@ -1,39 +0,0 @@
1
- # Example 18-1: User input
2
- require 'ruby-processing'
3
-
4
- class UserInput < Processing::App
5
-
6
- def setup
7
- size 300, 200
8
- @typing = ""
9
- @saved = ""
10
- textFont createFont "Arial", 16, true # set the font for text
11
- end
12
-
13
- def draw
14
- background 255
15
- indent = 25
16
- fill 0 # Set the fill for text
17
-
18
- # Display everything
19
- text "Click in this applet and type. \nHit return to save what you typed. ", indent, 40
20
- text @typing, indent, 90
21
- text @saved, indent, 130
22
- end
23
-
24
- def keyPressed
25
- # If the return key is pressed, save the String and clear it
26
- if key == "\n"
27
- @saved = @typing
28
- @typing = "" # A String can be cleared by setting it equal to ""
29
- else
30
- # Otherwise, concatenate the String
31
- # Each character typed by the user is added to the
32
- # end of the String variable.
33
- @typing = @typing + key
34
- end
35
- end
36
-
37
- end
38
-
39
- UserInput.new :title => "01 User Input"
@@ -1,28 +0,0 @@
1
- # Example 18-2: Graphing comma separated numbers from a text file
2
- require 'ruby-processing'
3
-
4
- class GraphingCommaSeparatedNumbersFromATextFile < Processing::App
5
-
6
- def setup
7
- size 200, 200
8
- # The text from the file is loaded into an array.
9
- stuff = loadStrings("data-1.txt")
10
-
11
- # This array has one element because the file only has one line.
12
- # Convert String into an array of integers using ',' as a delimiter
13
- @data = stuff[0].split(",").collect{ |n| n.to_i } # XXX: int(split(stuff[0], ","))
14
- end
15
-
16
- def draw
17
- background 255
18
- stroke 0
19
- @data.each_with_index do |data, i|
20
- # The array of ints is used to set the color and height of each rectangle.
21
- fill data
22
- rect i * 20, 0, 20, data
23
- end
24
- end
25
-
26
- end
27
-
28
- GraphingCommaSeparatedNumbersFromATextFile.new :title => "02 Graphing Comma Separated Numbers From A Text File"
@@ -1,64 +0,0 @@
1
- # Example 18-3: Creating objects from a text file
2
- require 'ruby-processing'
3
-
4
- class CreatingObjectFromATextFile < Processing::App
5
-
6
- def setup
7
- size 200, 200
8
- smooth
9
-
10
- # Load text file as an array of Strings
11
- data = loadStrings("data-2.txt")
12
-
13
- # The size of the array of Bubble objects is determined by the
14
- # total number of lines in the text file.
15
- @bubbles = []
16
- data.each do |datum|
17
- # Each line is split into an array of floating point numbers.
18
- values = datum.split(",").collect{ |n| n.to_f } # XXX: float[] values = float(split(datum, "," ))
19
- # The values in the array are passed into the Bubble class constructor.
20
- @bubbles << Bubble.new(*values)
21
- end
22
- end
23
-
24
- def draw
25
- background 255
26
- # Display and move all bubbles
27
- @bubbles.each do |bubble|
28
- bubble.display
29
- bubble.drift
30
- end
31
- end
32
-
33
- end
34
-
35
- # A Class to describe a "Bubble"
36
- class Bubble
37
- # The constructor initializes color and size
38
- # Location is filled randomly
39
- def initialize(r, g, diameter)
40
- @x = $app.random($app.width)
41
- @y = $app.height
42
- @r = r
43
- @g = g
44
- @diameter = diameter
45
- end
46
-
47
- # Display the Bubble
48
- def display
49
- $app.stroke 0
50
- $app.fill @r, @g, 255, 150
51
- $app.ellipse @x, @y, @diameter, @diameter
52
- end
53
-
54
- # Move the bubble
55
- def drift
56
- @y += $app.random(-3, -0.1)
57
- @x += $app.random(-1, 1)
58
- if @y < -@diameter * 2
59
- @y = $app.height + @diameter * 2
60
- end
61
- end
62
- end
63
-
64
- CreatingObjectFromATextFile.new :title => " Creating Object From A Text File"
@@ -1 +0,0 @@
1
- 102,75,192,178,78,23,144,181,125,55
@@ -1,10 +0,0 @@
1
- 88,149,22
2
- 193,78,8
3
- 90,152,56
4
- 136,18,37
5
- 47,2,55
6
- 36,142,57
7
- 10,61,31
8
- 9,121,49
9
- 156,60,12
10
- 71,200,21