ruby-processing 1.0.4 → 1.0.5

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 (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
- require 'ruby-processing'
2
-
3
- class CallingAFunction < Processing::App
4
-
5
- def setup
6
- smooth
7
- draw_black_circle
8
- end
9
-
10
- def draw
11
- background 255
12
- draw_black_circle
13
- end
14
-
15
- def draw_black_circle
16
- fill 0
17
- ellipse 50, 50, 20, 20
18
- end
19
-
20
- end
21
-
22
- CallingAFunction.new :title => "Calling A Function", :width => 100, :height => 100
@@ -1,49 +0,0 @@
1
- require 'ruby-processing'
2
-
3
- class BouncingBallWithFunctions < Processing::App
4
-
5
- def setup
6
- # Declare variables
7
- @x = 1
8
- @speed = 1
9
- smooth
10
- end
11
-
12
- def draw
13
- background 255
14
- # Instead of writing out all the code about the ball
15
- # in draw, we simply call three functions. How do
16
- # we know the names of these functions? We made them up!
17
- move
18
- bounce
19
- display
20
- end
21
-
22
- # Where should functions be placed?
23
- # You can define your functions anywhere in the code outside of setup and draw.
24
- # However, the convention is to place your function definitions below draw.
25
-
26
- # A function to move the ball
27
- def move
28
- # Change the x location by speed
29
- @x += @speed
30
- end
31
-
32
- # A function to bounce the ball
33
- def bounce
34
- # If we’ve reached an edge, reverse speed
35
- # (0..width) is a Ruby range, representing the numbers from 0 to width (aka 200).
36
- # You can ask a range if it includes another number or not.
37
- @speed *= -1 unless (0..width).include? @x
38
- end
39
-
40
- # A function to display the ball
41
- def display
42
- stroke 0
43
- fill 175
44
- ellipse @x, 100, 32, 32
45
- end
46
-
47
- end
48
-
49
- BouncingBallWithFunctions.new :title => "Bouncing Ball With Functions", :width => 200, :height => 200
@@ -1,48 +0,0 @@
1
- require 'ruby-processing'
2
-
3
- class FunctionReturnsDistance < Processing::App
4
-
5
- def setup
6
-
7
- end
8
-
9
- def draw
10
- background 0
11
- stroke 0
12
-
13
- # Set up width/2-1 and height/2-1 variables, for convenience.
14
- w1, h1 = width/2-1, height/2-1
15
-
16
- # Top left square
17
- # Our distance function is used to calculate a brightness value
18
- # for each quadrant. We could use the built-in function dist
19
- # instead, but we are learning how to write our own functions.
20
- fill distance(0, 0, mouse_x ,mouse_y)
21
- rect 0, 0, w1, h1
22
-
23
- # Top right square
24
- fill distance(width, 0, mouse_x, mouse_y)
25
- rect width/2, 0, w1, h1
26
-
27
- # Bottom left square
28
- fill distance(0, height, mouse_x, mouse_y)
29
- rect 0, height/2, w1, h1
30
-
31
- # Bottom right square
32
- fill distance(width, height, mouse_x, mouse_y)
33
- rect width/2, height/2, w1, h1
34
-
35
- end
36
-
37
- # Defining the distance method.
38
- # In Ruby we don't have to write "return", because Ruby implicitly
39
- # returns the last thing that was evaluated from any method.
40
- def distance x1, y1, x2, y2
41
- dx = x1 - x2
42
- dy = y1 - y2
43
- sqrt(dx*dx + dy*dy)
44
- end
45
-
46
- end
47
-
48
- FunctionReturnsDistance.new :title => "Function Returns Distance", :width => 200, :height => 200
@@ -1,71 +0,0 @@
1
- require 'ruby-processing'
2
-
3
- class ZoogWithFunctions < Processing::App
4
-
5
- def setup
6
- @x, @y = 100, 100
7
- @w, @h = 60, 60
8
- @eye_size = 16
9
- @speed = 1
10
- ellipse_mode CENTER
11
- rect_mode CENTER
12
- stroke 0
13
- smooth
14
- end
15
-
16
- def draw
17
- background 255 # Draw a black background
18
-
19
- # mouse_x position determines speed factor for moveZoog function
20
- factor = constrain mouse_x/10, 0, 5
21
-
22
- # The code for changing the variables associated with Zoog and
23
- # displaying Zoog is moved outside of draw and into functions
24
- # called here. The functions are given arguments, such as
25
- # "Jiggle Zoog by the following factor" and "draw Zoog with
26
- # the following eye color".
27
- jiggle_zoog factor
28
-
29
- # pass in a color to the draw_zoog function for eye color
30
- d = dist(@x, @y, mouse_x, mouse_y)
31
- c = color(d)
32
- draw_zoog c
33
- end
34
-
35
- def jiggle_zoog speed
36
- # Change the x and y location of Zoog randomly
37
- @x = @x + random(-1, 1) * speed
38
- @y = @y + random(-1, 1) * speed
39
- # Constrain Zoog to window
40
- @x = constrain @x, 0, width
41
- @y = constrain @y, 0, height
42
- end
43
-
44
- def draw_zoog eye_color
45
- # Arms are incorporated into Zoog's design with a times loop.
46
- 6.times do |i|
47
- y = i * 10 + @y + 5
48
- line @x-@w/3, y, @x+@w/3, y
49
- end
50
-
51
- # Draw Zoog's body
52
- fill 175
53
- rect @x, @y, @w/6, @h*2
54
-
55
- # Draw Zoog's head
56
- fill 255
57
- ellipse @x, @y-@h/2, @w, @h
58
-
59
- # Draw Zoog's eyes
60
- fill eye_color
61
- ellipse @x-@w/3+1, @y-@h/2, @eye_size, @eye_size*2
62
- ellipse @x+@w/3-1, @y-@h/2, @eye_size, @eye_size*2
63
-
64
- # Draw Zoog's legs
65
- line @x-@w/12, @y+@h, @x-@w/4, @y+@h+10
66
- line @x+@w/12, @y+@h, @x+@w/4, @y+@h+10
67
- end
68
-
69
- end
70
-
71
- ZoogWithFunctions.new :title => "Zoog With Functions", :width => 200, :height => 200
@@ -1,45 +0,0 @@
1
- require 'ruby-processing'
2
-
3
- class CarClassAndCarVariable < Processing::App
4
-
5
- def setup
6
- # Initialize a car object
7
- @my_car = Car.new(self)
8
- rect_mode CENTER
9
- end
10
-
11
- def draw
12
- background 255
13
-
14
- # Operate the car object in draw
15
- # by calling object methods using the dots syntax.
16
- @my_car.move
17
- @my_car.display_car
18
- end
19
-
20
- end
21
-
22
-
23
- class Car # Define a class below the rest of the program.
24
-
25
- def initialize(app)
26
- @app = app
27
- @c = @app.color 175
28
- @xpos = @app.width/2
29
- @ypos = @app.height/2
30
- @xspeed = 1
31
- end
32
-
33
- def display_car # A new function of class Car
34
- @app.stroke 0
35
- @app.fill @c
36
- @app.rect @xpos, @ypos, 20, 10
37
- end
38
-
39
- def move
40
- @xpos = @xpos + @xspeed
41
- @xpos = 0 if @xpos > @app.width
42
- end
43
- end
44
-
45
- CarClassAndCarVariable.new :title => "Car Class And Car Variable", :width => 200, :height => 200
@@ -1,60 +0,0 @@
1
- require 'ruby-processing'
2
-
3
- class TwoCarObjects < Processing::App
4
- load_library :control_panel
5
-
6
- def setup
7
- control_panel do |c|
8
- c.slider :red_car_speed, -5..15
9
- c.slider :blue_car_speed, -5..15
10
- end
11
-
12
- # Initialize car objects
13
- @red_car = Car.new(self, color(255,0,0), 0, 100)
14
- @blue_car = Car.new(self, color(0,0,255), 0, 10)
15
- @red_car_speed = 1
16
- @blue_car_speed = 2
17
- rect_mode CENTER
18
- end
19
-
20
- def draw
21
- background 255
22
-
23
- # Operate the car object in draw
24
- # by calling object methods using the dots syntax.
25
- @red_car.move(@red_car_speed)
26
- @red_car.display_car
27
- @blue_car.move(@blue_car_speed)
28
- @blue_car.display_car
29
- end
30
-
31
- end
32
-
33
-
34
- class Car # Define a class below the rest of the program.
35
- attr_accessor :temp_color, :temp_x_position, :temp_y_position, :temp_x_speed
36
- LENGTH = 20
37
- HEIGHT = 10
38
-
39
- def initialize(app, temp_color, temp_x_position, temp_y_position)
40
- @app = app
41
- @c = temp_color
42
- @xpos = temp_x_position
43
- @ypos = temp_y_position
44
- end
45
-
46
- def display_car # A new function of class Car
47
- @app.stroke 0
48
- @app.fill @c
49
- @app.rect @xpos, @ypos, LENGTH, HEIGHT
50
- end
51
-
52
- def move(speed)
53
- @xpos += speed
54
- @xpos = 0 if @xpos > @app.width + LENGTH/2
55
- @xpos = @app.width if @xpos < -LENGTH/2
56
- end
57
- end
58
-
59
- TwoCarObjects.new :title => "Car Class And Car Variable", :width => 200, :height => 200
60
-
@@ -1,81 +0,0 @@
1
- require 'ruby-processing'
2
-
3
- class ObjectOrientedZoog < Processing::App
4
- load_library "control_panel"
5
-
6
- def setup
7
- smooth
8
- control_panel do |c|
9
- c.slider :zoog_jiggle_factor, 0..width/10
10
- end
11
-
12
- # Initalize zoog
13
- @zoog = Zoog.new(self, 100, 125, 60, 60, 16)
14
- @zoog_jiggle_factor = 10
15
-
16
- rect_mode CENTER
17
- ellipse_mode CENTER
18
- end
19
-
20
- def draw
21
- background 255
22
-
23
- # mouse_x position determines speed factor
24
- # factor = constrain(mouse_x/10, 0, 5)
25
-
26
- @zoog.jiggle(@zoog_jiggle_factor)
27
- @zoog.display
28
- end
29
-
30
- end
31
-
32
- class Zoog
33
- attr_accessor :temp_x_position, :temp_y_position, :temp_width, :temp_height, :temp_eye_size
34
-
35
- def initialize(app, temp_x_position, temp_y_position, temp_zoog_width, temp_zoog_height, temp_eye_size)
36
- @app = app
37
- @x, @y = temp_x_position, temp_y_position
38
- @w, @h = temp_zoog_width, temp_zoog_height
39
- @eye_size = temp_eye_size
40
- end
41
-
42
- # Move zoog
43
- def jiggle(speed)
44
- @x = @x + speed * @app.random(-1,1)
45
- @y = @y + speed * @app.random(-1,1)
46
-
47
- @x = @app.constrain(@x, 0, @app.width)
48
- @y = @app.constrain(@y, 0, @app.height)
49
- end
50
-
51
- def display
52
- # Draw zoog's arms
53
- (@y - @h/3).step((@y + @h/2), 10) do |i|
54
- @app.stroke 0
55
- @app.line @x-@w/4, i, @x+@w/4, i
56
- end
57
-
58
- # Draw zoog's body
59
- @app.stroke 0
60
- @app.fill 255
61
- @app.rect @x, @y, @w/6, @h
62
-
63
- # Draw zoog's head
64
- @app.stroke 0
65
- @app.fill 255
66
- @app.ellipse @x, @y-@h, @w, @h
67
-
68
- # Draw zoog's eyes
69
- @app.fill 0
70
- @app.ellipse @x-@w/3, @y-@h, @eye_size, @eye_size*2
71
- @app.ellipse @x+@w/3, @y-@h, @eye_size, @eye_size*2
72
-
73
- # Draw zoog's legs
74
- @app.stroke 0
75
- @app.line @x-@w/12, @y+@h/2, @x-@w/4, @y+@h/2+10
76
- @app.line @x+@w/12, @y+@h/2, @x+@w/4, @y+@h/2+10
77
- end
78
-
79
- end
80
-
81
- ObjectOrientedZoog.new :title => "Object Oriented Zoog", :width => 200, :height => 200
@@ -1,35 +0,0 @@
1
- require 'ruby-processing'
2
-
3
- class CatcherSketch < Processing::App
4
- def setup
5
- @catcher = Catcher.new(32)
6
- smooth
7
- end
8
-
9
- def draw
10
- background 255
11
- @catcher.set_location mouse_x, mouse_y
12
- @catcher.display
13
- end
14
- end
15
-
16
-
17
- class Catcher
18
- def initialize(temp_r)
19
- @r = temp_r
20
- @x, @y = 0, 0
21
- end
22
-
23
- def set_location(temp_x, temp_y)
24
- @x, @y = temp_x, temp_y
25
- end
26
-
27
- # In Ruby-Processing, you can always find the sketch in $app.
28
- def display
29
- $app.stroke 0
30
- $app.fill 175
31
- $app.ellipse @x, @y, @r*2, @r*2
32
- end
33
- end
34
-
35
- CatcherSketch.new :title => "CatcherSketch", :width => 400, :height => 400
@@ -1,44 +0,0 @@
1
- require 'ruby-processing'
2
-
3
- class BouncingBallSketch < Processing::App
4
- def setup
5
- smooth
6
-
7
- # Create two balls.
8
- @ball_1, @ball_2 = Ball.new(64), Ball.new(32)
9
- end
10
-
11
- def draw
12
- background 255
13
- @ball_1.move
14
- @ball_2.move
15
- @ball_1.display
16
- @ball_2.display
17
- end
18
- end
19
-
20
-
21
- class Ball
22
- def initialize(temp_r)
23
- @r = temp_r
24
- @x, @y = rand($app.width), rand($app.height)
25
- @x_speed, @y_speed = (rand * 10 - 5), (rand * 10 - 5)
26
- end
27
-
28
- def move
29
- @x += @x_speed # Move the ball horizontally
30
- @y += @y_speed # Move the ball vertically
31
-
32
- # Check for the edges of the sketch
33
- @x_speed *= -1 unless (0..$app.width).include?(@x)
34
- @y_speed *= -1 unless (0..$app.height).include?(@y)
35
- end
36
-
37
- def display
38
- $app.stroke 0
39
- $app.fill 0, 50
40
- $app.ellipse @x, @y, @r*2, @r*2
41
- end
42
- end
43
-
44
- BouncingBallSketch.new :title => "Bouncing Ball", :width => 400, :height => 400