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.
- data/CHANGELOG +8 -0
- data/lib/patches/JRubyApplet.diff +0 -0
- data/lib/patches/PATCHES.txt +0 -0
- data/lib/patches/PApplet.diff +0 -0
- data/lib/ruby-processing.rb +1 -1
- data/lib/ruby-processing/app.rb +20 -1
- data/lib/ruby-processing/exporters/base_exporter.rb +1 -1
- data/lib/ruby-processing/exporters/creator.rb +1 -2
- data/lib/ruby-processing/runner.rb +4 -3
- data/lib/ruby-processing/runners/watch.rb +2 -2
- data/lib/templates/applet/index.html.erb +1 -1
- metadata +2 -145
- data/samples/learning_processing/ABOUT +0 -11
- data/samples/learning_processing/chapter_01/1_stroke_and_fill.rb +0 -18
- data/samples/learning_processing/chapter_01/2_nofill.rb +0 -20
- data/samples/learning_processing/chapter_01/3_rgb_color.rb +0 -19
- data/samples/learning_processing/chapter_01/4_alpha_transparency.rb +0 -42
- data/samples/learning_processing/chapter_01/5_zoog.rb +0 -24
- data/samples/learning_processing/chapter_02/1_zoog_again.rb +0 -41
- data/samples/learning_processing/chapter_03/1_zoog_as_dynamic_sketch.rb +0 -44
- data/samples/learning_processing/chapter_03/2_mouse_x_and_mouse_y.rb +0 -26
- data/samples/learning_processing/chapter_03/3_zoog_as_dynamic_sketch_with_variation.rb +0 -41
- data/samples/learning_processing/chapter_03/4_drawing_a_continuous_line.rb +0 -18
- data/samples/learning_processing/chapter_03/5_mouse_pressed_and_key_pressed.rb +0 -29
- data/samples/learning_processing/chapter_03/6_interactive_zoog.rb +0 -42
- data/samples/learning_processing/chapter_04/1_variable_declaration.rb +0 -24
- data/samples/learning_processing/chapter_04/2_using_variables.rb +0 -27
- data/samples/learning_processing/chapter_04/3_varying_variables.rb +0 -27
- data/samples/learning_processing/chapter_04/4_many_variables.rb +0 -38
- data/samples/learning_processing/chapter_04/5_using_system_variables.rb +0 -28
- data/samples/learning_processing/chapter_04/6_ellipse_with_variables.rb +0 -24
- data/samples/learning_processing/chapter_04/7_filling_variables_with_random_values.rb +0 -27
- data/samples/learning_processing/chapter_04/8_variable_zoog.rb +0 -50
- data/samples/learning_processing/chapter_05/01_conditionals.rb +0 -31
- data/samples/learning_processing/chapter_05/02_more_conditionals.rb +0 -38
- data/samples/learning_processing/chapter_05/03_rollovers.rb +0 -34
- data/samples/learning_processing/chapter_05/04_hold_down_the_button.rb +0 -33
- data/samples/learning_processing/chapter_05/05_button_as_switch.rb +0 -39
- data/samples/learning_processing/chapter_05/06_bouncing_ball.rb +0 -33
- data/samples/learning_processing/chapter_05/07_bouncing_color.rb +0 -37
- data/samples/learning_processing/chapter_05/08_square_following_edge.rb +0 -59
- data/samples/learning_processing/chapter_05/09_simple_gravity.rb +0 -43
- data/samples/learning_processing/chapter_05/10_zoog_and_conditionals.rb +0 -53
- data/samples/learning_processing/chapter_06/01_many_lines.rb +0 -29
- data/samples/learning_processing/chapter_06/02_many_lines_with_variables.rb +0 -53
- data/samples/learning_processing/chapter_06/03_while_loop.rb +0 -30
- data/samples/learning_processing/chapter_06/04_infinite_loop.rb +0 -25
- data/samples/learning_processing/chapter_06/05_another_infinite_loop.rb +0 -33
- data/samples/learning_processing/chapter_06/06_legs_with_a_for_loop.rb +0 -41
- data/samples/learning_processing/chapter_06/07_local_variables.rb +0 -39
- data/samples/learning_processing/chapter_06/08_lines_one_at_a_time.rb +0 -30
- data/samples/learning_processing/chapter_06/09_simple_while_loop_with_interactivity.rb +0 -41
- data/samples/learning_processing/chapter_06/10_zoog_with_arms.rb +0 -56
- data/samples/learning_processing/chapter_06/11_multiple_zoogs.rb +0 -46
- data/samples/learning_processing/chapter_07/01_defining_a_function.rb +0 -22
- data/samples/learning_processing/chapter_07/02_calling_a_function.rb +0 -22
- data/samples/learning_processing/chapter_07/03_bouncing_ball_with_functions.rb +0 -49
- data/samples/learning_processing/chapter_07/04_function_returns_distance.rb +0 -48
- data/samples/learning_processing/chapter_07/05_zoog_with_functions.rb +0 -71
- data/samples/learning_processing/chapter_08/01_car_class_and_car_variable.rb +0 -45
- data/samples/learning_processing/chapter_08/02_two_car_objects.rb +0 -60
- data/samples/learning_processing/chapter_08/03_object_oriented_zoog.rb +0 -81
- data/samples/learning_processing/chapter_10/01_catcher.rb +0 -35
- data/samples/learning_processing/chapter_10/02_bouncing_ball.rb +0 -44
- data/samples/learning_processing/chapter_10/03_bouncing_balls_with_intersection.rb +0 -69
- data/samples/learning_processing/chapter_10/04_a_timer.rb +0 -24
- data/samples/learning_processing/chapter_10/05_object_oriented_timer.rb +0 -42
- data/samples/learning_processing/chapter_10/06_simple_raindrop.rb +0 -23
- data/samples/learning_processing/chapter_10/07_drops_one_at_a_time.rb +0 -63
- data/samples/learning_processing/chapter_13/02_random_number_distribution.rb +0 -24
- data/samples/learning_processing/chapter_13/03_probabilities.rb +0 -33
- data/samples/learning_processing/chapter_13/04_perlin_noise.rb +0 -22
- data/samples/learning_processing/chapter_13/06_oscillation.rb +0 -29
- data/samples/learning_processing/chapter_13/07_wave.rb +0 -31
- data/samples/learning_processing/chapter_13/08_recursion.rb +0 -30
- data/samples/learning_processing/chapter_13/09_two_dimensional_array.rb +0 -21
- data/samples/learning_processing/chapter_13/10_two_dimensional_array_with_objects.rb +0 -54
- data/samples/learning_processing/chapter_14/01_growing_rectangle.rb +0 -26
- data/samples/learning_processing/chapter_14/02_multiple_translations.rb +0 -37
- data/samples/learning_processing/chapter_14/03_depth_rectangle.rb +0 -29
- data/samples/learning_processing/chapter_14/04_pyramid_using_beingshape.rb +0 -55
- data/samples/learning_processing/chapter_14/05_rotate_rectangle_around_center.rb +0 -28
- data/samples/learning_processing/chapter_14/06_rotate_z.rb +0 -24
- data/samples/learning_processing/chapter_14/07_rotate_x.rb +0 -24
- data/samples/learning_processing/chapter_14/08_rotate_y.rb +0 -24
- data/samples/learning_processing/chapter_14/09_rotate_all.rb +0 -24
- data/samples/learning_processing/chapter_14/10_draw_pyramid.rb +0 -59
- data/samples/learning_processing/chapter_14/12_rotating_one_square.rb +0 -25
- data/samples/learning_processing/chapter_14/13_rotating_another_square.rb +0 -25
- data/samples/learning_processing/chapter_14/14_rotating_both_squares.rb +0 -43
- data/samples/learning_processing/chapter_14/15_rotating_many_things.rb +0 -56
- data/samples/learning_processing/chapter_14/16_simple_solar_system.rb +0 -53
- data/samples/learning_processing/chapter_14/17_nested_push_and_pop.rb +0 -50
- data/samples/learning_processing/chapter_14/18_object_oriented_solar_system.rb +0 -69
- data/samples/learning_processing/chapter_15/01_hello_world_image.rb +0 -20
- data/samples/learning_processing/chapter_15/02_image_sprite.rb +0 -29
- data/samples/learning_processing/chapter_15/03_swapping_images.rb +0 -25
- data/samples/learning_processing/chapter_15/04_image_sequence.rb +0 -22
- data/samples/learning_processing/chapter_15/05_setting_pixels.rb +0 -19
- data/samples/learning_processing/chapter_15/06_pixels_2d.rb +0 -29
- data/samples/learning_processing/chapter_15/07_image_pixels.rb +0 -40
- data/samples/learning_processing/chapter_15/08_image_brightness.rb +0 -29
- data/samples/learning_processing/chapter_15/09_flashlight_effect.rb +0 -42
- data/samples/learning_processing/chapter_15/10_brightness_threshold.rb +0 -33
- data/samples/learning_processing/chapter_15/11_brightness_threshold_with_filter.rb +0 -20
- data/samples/learning_processing/chapter_15/12_pixel_neighbour_differences.rb +0 -43
- data/samples/learning_processing/chapter_15/14_pointillism.rb +0 -34
- data/samples/learning_processing/chapter_15/15_2d_image_mapped_to_3d.rb +0 -43
- data/samples/learning_processing/chapter_15/data/animal0.jpg +0 -0
- data/samples/learning_processing/chapter_15/data/animal1.jpg +0 -0
- data/samples/learning_processing/chapter_15/data/animal2.jpg +0 -0
- data/samples/learning_processing/chapter_15/data/animal3.jpg +0 -0
- data/samples/learning_processing/chapter_15/data/animal4.jpg +0 -0
- data/samples/learning_processing/chapter_15/data/animal5.jpg +0 -0
- data/samples/learning_processing/chapter_15/data/animal6.jpg +0 -0
- data/samples/learning_processing/chapter_15/data/face.jpg +0 -0
- data/samples/learning_processing/chapter_15/data/mysummervacation.jpg +0 -0
- data/samples/learning_processing/chapter_15/data/sunflower.jpg +0 -0
- data/samples/learning_processing/chapter_16/01_display_video.rb +0 -25
- data/samples/learning_processing/chapter_16/02_manipulate_video_image.rb +0 -24
- data/samples/learning_processing/chapter_16/03_adjust_video_brightness.rb +0 -49
- data/samples/learning_processing/chapter_17/01_simple_displaying_text.rb +0 -14
- data/samples/learning_processing/chapter_17/02_text_align.rb +0 -21
- data/samples/learning_processing/chapter_17/03_scrolling_headlines.rb +0 -35
- data/samples/learning_processing/chapter_17/04_text_mirror.rb +0 -68
- data/samples/learning_processing/chapter_17/05_rotating_text.rb +0 -22
- data/samples/learning_processing/chapter_17/06_text_breaking_up.rb +0 -73
- data/samples/learning_processing/chapter_17/07_boxes_along_a_curve.rb +0 -49
- data/samples/learning_processing/chapter_17/08_characters_along_a_curve.rb +0 -51
- data/samples/learning_processing/chapter_17/data/ArialMT-16.vlw +0 -0
- data/samples/learning_processing/chapter_17/data/Courier-Bold-20.vlw +0 -0
- data/samples/learning_processing/chapter_18/01_user_input.rb +0 -39
- data/samples/learning_processing/chapter_18/02_graphing_comma_separated_numbers_from_a_text_file.rb +0 -28
- data/samples/learning_processing/chapter_18/03_creating_object_from_a_text_file.rb +0 -64
- data/samples/learning_processing/chapter_18/data/data-1.txt +0 -1
- data/samples/learning_processing/chapter_18/data/data-2.txt +0 -10
@@ -1,41 +0,0 @@
|
|
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
|
-
|
4
|
-
|
5
|
-
class ZoogAgain < Processing::App
|
6
|
-
|
7
|
-
def setup
|
8
|
-
background 255
|
9
|
-
smooth
|
10
|
-
|
11
|
-
# Set ellipses and rects to CENTER mode
|
12
|
-
ellipse_mode CENTER
|
13
|
-
rect_mode CENTER
|
14
|
-
|
15
|
-
# Draw Zoog's body
|
16
|
-
stroke 0
|
17
|
-
fill 150
|
18
|
-
rect 100, 100, 20, 100
|
19
|
-
|
20
|
-
# Draw Zoog's head
|
21
|
-
fill 255
|
22
|
-
ellipse 100, 70, 60, 60
|
23
|
-
|
24
|
-
# Draw Zoog's eyes
|
25
|
-
fill 0
|
26
|
-
ellipse 81, 70, 16, 32
|
27
|
-
ellipse 119, 70, 16, 32
|
28
|
-
|
29
|
-
# Draw Zoog's legs
|
30
|
-
stroke 0
|
31
|
-
line 90, 150, 80, 160
|
32
|
-
line 110, 150, 120, 160
|
33
|
-
end
|
34
|
-
|
35
|
-
def draw
|
36
|
-
|
37
|
-
end
|
38
|
-
|
39
|
-
end
|
40
|
-
|
41
|
-
ZoogAgain.new :title => "Zoog Again", :width => 200, :height => 200
|
@@ -1,44 +0,0 @@
|
|
1
|
-
require 'ruby-processing'
|
2
|
-
|
3
|
-
class ZoogAsDynamicSketch < Processing::App
|
4
|
-
|
5
|
-
# Setup runs first one time.
|
6
|
-
# In Ruby-Processing, you never need to call size(),
|
7
|
-
# just set the width and height when you instantiate the sketch,
|
8
|
-
# at the bottom.
|
9
|
-
def setup
|
10
|
-
|
11
|
-
end
|
12
|
-
|
13
|
-
# Draw loops continuously until you close the sketch window.
|
14
|
-
def draw
|
15
|
-
# Draw a white background
|
16
|
-
background 255
|
17
|
-
|
18
|
-
# Set CENTER mode
|
19
|
-
ellipse_mode CENTER
|
20
|
-
rect_mode CENTER
|
21
|
-
|
22
|
-
# Draw Zoog's body
|
23
|
-
stroke 0
|
24
|
-
fill 150
|
25
|
-
rect 100, 100, 20, 100
|
26
|
-
|
27
|
-
# Draw Zoog's head
|
28
|
-
fill 255
|
29
|
-
ellipse 100, 70, 60, 60
|
30
|
-
|
31
|
-
# Draw Zoog's eyes
|
32
|
-
fill 0
|
33
|
-
ellipse 81, 70, 16, 32
|
34
|
-
ellipse 119, 70, 16, 32
|
35
|
-
|
36
|
-
# Draw Zoog's legs
|
37
|
-
stroke 0
|
38
|
-
line 90, 150, 80, 160
|
39
|
-
line 110, 150, 120, 160
|
40
|
-
end
|
41
|
-
|
42
|
-
end
|
43
|
-
|
44
|
-
ZoogAsDynamicSketch.new :title => "Zoog As Dynamic Sketch", :width => 200, :height => 200
|
@@ -1,26 +0,0 @@
|
|
1
|
-
require 'ruby-processing'
|
2
|
-
|
3
|
-
class MouseXAndMouseY < Processing::App
|
4
|
-
|
5
|
-
def setup
|
6
|
-
|
7
|
-
end
|
8
|
-
|
9
|
-
def draw
|
10
|
-
# Try moving background to setup and see the difference!
|
11
|
-
background 255
|
12
|
-
|
13
|
-
# Body
|
14
|
-
stroke 0
|
15
|
-
fill 175
|
16
|
-
rect_mode CENTER
|
17
|
-
|
18
|
-
# mouse_x is a keyword that the sketch replaces with the
|
19
|
-
# horizontal position of the mouse.
|
20
|
-
# mouse_y gets the vertical position.
|
21
|
-
rect mouse_x, mouse_y, 50, 50
|
22
|
-
end
|
23
|
-
|
24
|
-
end
|
25
|
-
|
26
|
-
MouseXAndMouseY.new :title => "Mouse X And Mouse Y", :width => 200, :height => 200
|
@@ -1,41 +0,0 @@
|
|
1
|
-
require 'ruby-processing'
|
2
|
-
|
3
|
-
class ZoogAsDynamicSketchWithVariation < Processing::App
|
4
|
-
|
5
|
-
def setup
|
6
|
-
smooth
|
7
|
-
end
|
8
|
-
|
9
|
-
def draw
|
10
|
-
background 255 # Draw a white background
|
11
|
-
|
12
|
-
# Set ellipses and rects to CENTER mode
|
13
|
-
ellipse_mode CENTER
|
14
|
-
rect_mode CENTER
|
15
|
-
|
16
|
-
# Draw Zoog's body
|
17
|
-
stroke 0
|
18
|
-
fill 150
|
19
|
-
# Zoog's body is drawn at the location (mouse_x, mouse_y)
|
20
|
-
rect mouse_x, mouse_y, 20, 100
|
21
|
-
|
22
|
-
# Draw Zoog's head
|
23
|
-
stroke 0
|
24
|
-
fill 255
|
25
|
-
# Zoog's head is drawn above the body at the location (mouse_x, mouse_y - 30)
|
26
|
-
ellipse mouse_x, mouse_y - 30, 60, 60
|
27
|
-
|
28
|
-
# Draw Zoog's eyes
|
29
|
-
fill 0
|
30
|
-
ellipse 81, 70, 16, 32
|
31
|
-
ellipse 119, 70, 16, 32
|
32
|
-
|
33
|
-
# Draw Zoog's legs
|
34
|
-
stroke 0
|
35
|
-
line 90, 150, 80, 160
|
36
|
-
line 110, 150, 120, 160
|
37
|
-
end
|
38
|
-
|
39
|
-
end
|
40
|
-
|
41
|
-
ZoogAsDynamicSketchWithVariation.new :title => "Zoog As Dynamic Sketch With Variation", :width => 200, :height => 200
|
@@ -1,18 +0,0 @@
|
|
1
|
-
require 'ruby-processing'
|
2
|
-
|
3
|
-
class DrawingAContinuousLine < Processing::App
|
4
|
-
|
5
|
-
def setup
|
6
|
-
background 255
|
7
|
-
smooth
|
8
|
-
end
|
9
|
-
|
10
|
-
def draw
|
11
|
-
stroke 0
|
12
|
-
# Draw a line from the previous mouse location to the current location.
|
13
|
-
line pmouse_x, pmouse_y, mouse_x, mouse_y
|
14
|
-
end
|
15
|
-
|
16
|
-
end
|
17
|
-
|
18
|
-
DrawingAContinuousLine.new :title => "Drawing A Continuous Line", :width => 200, :height => 200
|
@@ -1,29 +0,0 @@
|
|
1
|
-
require 'ruby-processing'
|
2
|
-
|
3
|
-
# Click the mouse to draw a square. Hit the space bar to clear the window.
|
4
|
-
class MousePressedAndKeyPressed < Processing::App
|
5
|
-
|
6
|
-
def setup
|
7
|
-
background 255
|
8
|
-
end
|
9
|
-
|
10
|
-
def draw
|
11
|
-
# Nothing happens in draw in this example!
|
12
|
-
end
|
13
|
-
|
14
|
-
# Whenever the mouse is clicked, the code inside mouse_pressed runs.
|
15
|
-
def mouse_pressed
|
16
|
-
stroke 0
|
17
|
-
fill 175
|
18
|
-
rect_mode CENTER
|
19
|
-
rect mouse_x, mouse_y, 16, 16
|
20
|
-
end
|
21
|
-
|
22
|
-
# Whenever a key is pressed, the code inside key_pressed runs.
|
23
|
-
def key_pressed
|
24
|
-
background 255
|
25
|
-
end
|
26
|
-
|
27
|
-
end
|
28
|
-
|
29
|
-
MousePressedAndKeyPressed.new :title => "Mouse Pressed And Key Pressed", :width => 200, :height => 200
|
@@ -1,42 +0,0 @@
|
|
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
|
6
|
-
|
7
|
-
def draw
|
8
|
-
# draw a white background
|
9
|
-
background 255
|
10
|
-
|
11
|
-
# Set ellipses and rects to CENTER mode
|
12
|
-
ellipse_mode CENTER
|
13
|
-
rect_mode CENTER
|
14
|
-
|
15
|
-
# Draw Zoog's body
|
16
|
-
stroke 0
|
17
|
-
fill 150
|
18
|
-
rect mouse_x, mouse_y, 20, 100
|
19
|
-
|
20
|
-
# Draw Zoog's head
|
21
|
-
stroke 0
|
22
|
-
fill 255
|
23
|
-
ellipse mouse_x, mouse_y - 30, 60, 60
|
24
|
-
|
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
|
30
|
-
|
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
|
36
|
-
end
|
37
|
-
|
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
|
@@ -1,24 +0,0 @@
|
|
1
|
-
require 'ruby-processing'
|
2
|
-
|
3
|
-
# Ruby has dynamic typing, so you don't have to say
|
4
|
-
# what kind of thing a variable is before using it.
|
5
|
-
class VariableDeclaration < Processing::App
|
6
|
-
|
7
|
-
def setup
|
8
|
-
count = 0 # count gets assigned 0, an integer (Fixnum)
|
9
|
-
letter = 'a' # letter gets the letter 'a', a String
|
10
|
-
d = 132.32 # d gets the decimal 132.32, a Float (floating-point number)
|
11
|
-
happy = false # happy gets false, a Boolean (true or false)
|
12
|
-
x = 4.0 # x gets 4.0, another Float
|
13
|
-
y = nil # y gets nil, which stands for nothing
|
14
|
-
y = x + 5.2 # assign the value of x plus 5.2 to y
|
15
|
-
z = x * y + 15.0 # z gets the value of x times y plus 15.0 (or 51.8)
|
16
|
-
end
|
17
|
-
|
18
|
-
def draw
|
19
|
-
|
20
|
-
end
|
21
|
-
|
22
|
-
end
|
23
|
-
|
24
|
-
VariableDeclaration.new :title => "Variable Declaration and Initialization Examples", :width => 200, :height => 200
|
@@ -1,27 +0,0 @@
|
|
1
|
-
require 'ruby-processing'
|
2
|
-
|
3
|
-
class UsingVariables < Processing::App
|
4
|
-
|
5
|
-
def setup
|
6
|
-
# Create two variables, holding integers.
|
7
|
-
# These will be instance variables, meaning that you can
|
8
|
-
# get at them from any method within this class.
|
9
|
-
# Instance variables in Ruby begin with '@'.
|
10
|
-
|
11
|
-
@circle_x = 100
|
12
|
-
@circle_y = 100
|
13
|
-
smooth
|
14
|
-
end
|
15
|
-
|
16
|
-
def draw
|
17
|
-
background 255
|
18
|
-
stroke 0
|
19
|
-
fill 175
|
20
|
-
# We use the instance variables from setup for the circle.
|
21
|
-
# They are available in this method too.
|
22
|
-
ellipse @circle_x, @circle_y, 50, 50
|
23
|
-
end
|
24
|
-
|
25
|
-
end
|
26
|
-
|
27
|
-
UsingVariables.new :title => "Using Variables", :width => 200, :height => 200
|
@@ -1,27 +0,0 @@
|
|
1
|
-
require 'ruby-processing'
|
2
|
-
|
3
|
-
class VaryingVariables < Processing::App
|
4
|
-
|
5
|
-
def setup
|
6
|
-
# Declare and initialize two integer instance variables.
|
7
|
-
@circle_x = 0
|
8
|
-
@circle_y = 100
|
9
|
-
|
10
|
-
smooth
|
11
|
-
end
|
12
|
-
|
13
|
-
def draw
|
14
|
-
background 255
|
15
|
-
stroke 0
|
16
|
-
fill 175
|
17
|
-
|
18
|
-
# Use the variables to specify the location of the circle
|
19
|
-
ellipse @circle_x, @circle_y, 50, 50
|
20
|
-
|
21
|
-
# An assignment operation that increments the value of circle_x by 1.
|
22
|
-
@circle_x += 1
|
23
|
-
end
|
24
|
-
|
25
|
-
end
|
26
|
-
|
27
|
-
VaryingVariables.new :title => "Varying Variables", :width => 200, :height => 200
|
@@ -1,38 +0,0 @@
|
|
1
|
-
require 'ruby-processing'
|
2
|
-
|
3
|
-
class ManyVariables < Processing::App
|
4
|
-
|
5
|
-
def setup
|
6
|
-
# We've got 8 variables now! They're all Floats.
|
7
|
-
@circle_x, @circle_y = 0.0, 0.0
|
8
|
-
@circle_w, @circle_h = 50.0, 100.0
|
9
|
-
@circle_stroke = 255.0
|
10
|
-
@circle_fill = 0.0
|
11
|
-
@background_color = 255.0
|
12
|
-
@change = 0.5
|
13
|
-
|
14
|
-
smooth
|
15
|
-
end
|
16
|
-
|
17
|
-
def draw
|
18
|
-
# Draw the background and the ellipse.
|
19
|
-
# Variables are used for everything:
|
20
|
-
# background, stroke, fill, location and size.
|
21
|
-
background @background_color
|
22
|
-
stroke @circle_stroke
|
23
|
-
fill @circle_fill
|
24
|
-
ellipse @circle_x, @circle_y, @circle_w, @circle_h
|
25
|
-
|
26
|
-
# Change the values of all variables.
|
27
|
-
# The variable change is used to update the others.
|
28
|
-
@circle_x += @change
|
29
|
-
@circle_y += @change
|
30
|
-
@circle_w += @change
|
31
|
-
@circle_h -= @change
|
32
|
-
@circle_stroke -= @change
|
33
|
-
@circle_fill += @change
|
34
|
-
end
|
35
|
-
|
36
|
-
end
|
37
|
-
|
38
|
-
ManyVariables.new :title => "Many Variables", :width => 200, :height => 200
|
@@ -1,28 +0,0 @@
|
|
1
|
-
require 'ruby-processing'
|
2
|
-
|
3
|
-
class UsingSystemVariables < Processing::App
|
4
|
-
|
5
|
-
def setup
|
6
|
-
smooth
|
7
|
-
end
|
8
|
-
|
9
|
-
def draw
|
10
|
-
background 100
|
11
|
-
stroke 255
|
12
|
-
|
13
|
-
# frame_count is used to color a rectangle
|
14
|
-
fill(frame_count / 2)
|
15
|
-
rect_mode CENTER
|
16
|
-
|
17
|
-
# The rectangle will always be in the middle of the window
|
18
|
-
# if it is located at (width/2, height/2)
|
19
|
-
rect(width/2, height/2, mouse_x + 10, mouse_y + 10)
|
20
|
-
end
|
21
|
-
|
22
|
-
def key_pressed
|
23
|
-
puts key
|
24
|
-
end
|
25
|
-
|
26
|
-
end
|
27
|
-
|
28
|
-
UsingSystemVariables.new :title => "Using System Variables", :width => 200, :height => 200
|
@@ -1,24 +0,0 @@
|
|
1
|
-
require 'ruby-processing'
|
2
|
-
|
3
|
-
class EllipseWithVariables < Processing::App
|
4
|
-
|
5
|
-
def setup
|
6
|
-
# Initialize your variables (you don't have to declare 'em)
|
7
|
-
@r, @g, @b, @a = 100, 150, 200, 200
|
8
|
-
@x, @y = 100, 100
|
9
|
-
@diam = 20
|
10
|
-
|
11
|
-
background 255
|
12
|
-
smooth
|
13
|
-
end
|
14
|
-
|
15
|
-
def draw
|
16
|
-
# Use the variables to draw an ellipse
|
17
|
-
stroke 0
|
18
|
-
fill @r, @g, @b, @a # Remember, the fourth argument for a color means opacity.
|
19
|
-
ellipse @x, @y, @diam, @diam
|
20
|
-
end
|
21
|
-
|
22
|
-
end
|
23
|
-
|
24
|
-
EllipseWithVariables.new :title => "Ellipse With Variables", :width => 200, :height => 200
|
@@ -1,27 +0,0 @@
|
|
1
|
-
require 'ruby-processing'
|
2
|
-
|
3
|
-
class FillingVariablesWithRandomValues < Processing::App
|
4
|
-
|
5
|
-
def setup
|
6
|
-
background 255
|
7
|
-
smooth
|
8
|
-
end
|
9
|
-
|
10
|
-
def draw
|
11
|
-
# Each time through draw, new random numbers
|
12
|
-
# are picked for a new ellipse.
|
13
|
-
# We're using local variables here, not instance variables,
|
14
|
-
# because we only need them in the draw method.
|
15
|
-
r, g, b, a = random(255), random(255), random(255), random(255)
|
16
|
-
diam = random(20)
|
17
|
-
x, y = random(width), random(height)
|
18
|
-
|
19
|
-
# Use the values to draw an ellipse
|
20
|
-
no_stroke
|
21
|
-
fill r, g, b, a
|
22
|
-
ellipse x, y, diam, diam
|
23
|
-
end
|
24
|
-
|
25
|
-
end
|
26
|
-
|
27
|
-
FillingVariablesWithRandomValues.new :title => "Filling Variables With Random Values", :width => 200, :height => 200
|