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,29 +0,0 @@
|
|
1
|
-
require 'ruby-processing'
|
2
|
-
|
3
|
-
class ManyLines < Processing::App
|
4
|
-
|
5
|
-
def setup
|
6
|
-
background 255
|
7
|
-
|
8
|
-
# Legs
|
9
|
-
stroke 0
|
10
|
-
line 50, 60, 50, 80
|
11
|
-
line 60, 60, 60, 80
|
12
|
-
line 70, 60, 70, 80
|
13
|
-
line 80, 60, 80, 80
|
14
|
-
line 90, 60, 90, 80
|
15
|
-
line 100, 60, 100, 80
|
16
|
-
line 110, 60, 110, 80
|
17
|
-
line 120, 60, 120, 80
|
18
|
-
line 130, 60, 130, 80
|
19
|
-
line 140, 60, 140, 80
|
20
|
-
line 150, 60, 150, 80
|
21
|
-
end
|
22
|
-
|
23
|
-
def draw
|
24
|
-
|
25
|
-
end
|
26
|
-
|
27
|
-
end
|
28
|
-
|
29
|
-
ManyLines.new :title => "Many Lines", :width => 200, :height => 200
|
@@ -1,53 +0,0 @@
|
|
1
|
-
require 'ruby-processing'
|
2
|
-
|
3
|
-
class ManyLinesWithVariables < Processing::App
|
4
|
-
|
5
|
-
def setup
|
6
|
-
background 255
|
7
|
-
|
8
|
-
# Legs
|
9
|
-
stroke 0
|
10
|
-
y = 80 # Vertical location of each line
|
11
|
-
x = 50 # Initial horizontal location for first line
|
12
|
-
spacing = 10 # How far apart is each line
|
13
|
-
len = 20 # Length of each line
|
14
|
-
|
15
|
-
# Draw the first leg.
|
16
|
-
line x, y, x, y + len
|
17
|
-
# Add spacing so the next leg appears 10 pixels to the right.
|
18
|
-
x = x + spacing
|
19
|
-
|
20
|
-
# You could continue this process for each leg, like in the original
|
21
|
-
# example, but it's pretty silly to repeat any chunk of code so many times:
|
22
|
-
|
23
|
-
line x, y, x, y + len
|
24
|
-
x = x + spacing
|
25
|
-
line x, y, x, y + len
|
26
|
-
x = x + spacing
|
27
|
-
line x, y, x, y + len
|
28
|
-
x = x + spacing
|
29
|
-
line x, y, x, y + len
|
30
|
-
x = x + spacing
|
31
|
-
line x, y, x, y + len
|
32
|
-
x = x + spacing
|
33
|
-
line x, y, x, y + len
|
34
|
-
x = x + spacing
|
35
|
-
line x, y, x, y + len
|
36
|
-
x = x + spacing
|
37
|
-
line x, y, x, y + len
|
38
|
-
x = x + spacing
|
39
|
-
line x, y, x, y + len
|
40
|
-
x = x + spacing
|
41
|
-
line x, y, x, y + len
|
42
|
-
|
43
|
-
# A nicer way is to repeat that chunk of code with a block,
|
44
|
-
# you can see how in example 06.
|
45
|
-
end
|
46
|
-
|
47
|
-
def draw
|
48
|
-
|
49
|
-
end
|
50
|
-
|
51
|
-
end
|
52
|
-
|
53
|
-
ManyLinesWithVariables.new :title => "Many Lines With Variables", :width => 200, :height => 200
|
@@ -1,30 +0,0 @@
|
|
1
|
-
require 'ruby-processing'
|
2
|
-
|
3
|
-
class WhileLoop < Processing::App
|
4
|
-
|
5
|
-
def setup
|
6
|
-
background 255
|
7
|
-
|
8
|
-
y = 80 # Vertical location of each line
|
9
|
-
x = 50 # Initial horizontal location for first line
|
10
|
-
spacing = 10 # How far apart is each line
|
11
|
-
len = 20 # Length of each line
|
12
|
-
|
13
|
-
# A variable to mark where the legs end.
|
14
|
-
end_legs = 150
|
15
|
-
stroke 0
|
16
|
-
|
17
|
-
# Draw each leg inside a while loop.
|
18
|
-
while x <= end_legs
|
19
|
-
line x, y, x, y + len
|
20
|
-
x = x + spacing
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
def draw
|
25
|
-
|
26
|
-
end
|
27
|
-
|
28
|
-
end
|
29
|
-
|
30
|
-
WhileLoop.new :title => "While Loop", :width => 200, :height => 200
|
@@ -1,25 +0,0 @@
|
|
1
|
-
require 'ruby-processing'
|
2
|
-
|
3
|
-
class InfiniteLoop < Processing::App
|
4
|
-
|
5
|
-
def setup
|
6
|
-
|
7
|
-
end
|
8
|
-
|
9
|
-
def draw
|
10
|
-
|
11
|
-
x = 0
|
12
|
-
while x < 10
|
13
|
-
puts x
|
14
|
-
# Decrementing x results in an infinite loop here because the value of x will never be 10 or greater.
|
15
|
-
# Be careful!
|
16
|
-
x = x - 1
|
17
|
-
end
|
18
|
-
|
19
|
-
# This example does not include the break function.
|
20
|
-
# To stop the runaway loop, close the window or use control-c in the terminal.
|
21
|
-
end
|
22
|
-
|
23
|
-
end
|
24
|
-
|
25
|
-
InfiniteLoop.new :title => "Infinite Loop (Don't do this)", :width => 200, :height => 200
|
@@ -1,33 +0,0 @@
|
|
1
|
-
require 'ruby-processing'
|
2
|
-
|
3
|
-
class AnotherInfiniteLoop < Processing::App
|
4
|
-
|
5
|
-
def setup
|
6
|
-
@y = 80 # Vertical location of each line
|
7
|
-
@x = 0 # Horizontal location of first line
|
8
|
-
@spacing = 10 # How far apart is each line
|
9
|
-
@len = 20 # Length of each line
|
10
|
-
@end_legs = 150 # Where should the lines stop?
|
11
|
-
end
|
12
|
-
|
13
|
-
def draw
|
14
|
-
# The spacing variable, which sets the distance in between each line,
|
15
|
-
# is assigned a value equal to mouseX divided by two.
|
16
|
-
# THIS LINE IS COMMENTED OUT SO THAT THE SKETCH DOES NOT CRASH
|
17
|
-
# IF YOU PUT IT BACK IN THIS SKETCH WILL CRASH!
|
18
|
-
# @spacing = mouse_x / 2
|
19
|
-
|
20
|
-
# Exit Condition: when x is greater than endlegs.
|
21
|
-
while @x <= @end_legs
|
22
|
-
line @x, @y, @x, @y + @len
|
23
|
-
# Incrementation of x.
|
24
|
-
# x always increases by the value of spacing.
|
25
|
-
# What is the range of possible values for spacing?
|
26
|
-
@x = @x + @spacing
|
27
|
-
end
|
28
|
-
|
29
|
-
end
|
30
|
-
|
31
|
-
end
|
32
|
-
|
33
|
-
AnotherInfiniteLoop.new :title => "Another Infinite Loop", :width => 200, :height => 200
|
@@ -1,41 +0,0 @@
|
|
1
|
-
require 'ruby-processing'
|
2
|
-
|
3
|
-
class LegsWithAForLoop < Processing::App
|
4
|
-
|
5
|
-
def setup
|
6
|
-
background 255
|
7
|
-
end
|
8
|
-
|
9
|
-
def reset_values
|
10
|
-
@x = 50 # Horizontal location of first line
|
11
|
-
@y = 80 # Vertical location of each line
|
12
|
-
@spacing = 10 # How far apart is each line
|
13
|
-
@len = 20 # Length of each line
|
14
|
-
end
|
15
|
-
|
16
|
-
def draw
|
17
|
-
reset_values
|
18
|
-
|
19
|
-
# In ruby numbers also have methods.
|
20
|
-
# The times method allows you to run a given block of code
|
21
|
-
# a certain number of times:
|
22
|
-
|
23
|
-
10.times do
|
24
|
-
line @x, @y, @x, @y + @len
|
25
|
-
@x += @spacing
|
26
|
-
end
|
27
|
-
|
28
|
-
# There's also an alternative method called step,
|
29
|
-
# You call it on the number you'd like to start with,
|
30
|
-
# passing it the end number, and the size of the steps to take:
|
31
|
-
# start_num.step(stop_num, step_size) { |value| do_something_with value ...
|
32
|
-
|
33
|
-
50.step(150, @spacing) { |x| line x, @y, x, @y + @len }
|
34
|
-
|
35
|
-
# The curly braces are an alternative form for writing do ... end.
|
36
|
-
# So, I guess this isn't much of a demonstration of the for loop...
|
37
|
-
end
|
38
|
-
|
39
|
-
end
|
40
|
-
|
41
|
-
LegsWithAForLoop.new :title => "Legs With A For Loop", :width => 200, :height => 200
|
@@ -1,39 +0,0 @@
|
|
1
|
-
require 'ruby-processing'
|
2
|
-
|
3
|
-
class LocalVariables < Processing::App
|
4
|
-
|
5
|
-
def setup
|
6
|
-
# x is not available! It is local to the draw block of code.
|
7
|
-
end
|
8
|
-
|
9
|
-
def draw
|
10
|
-
background 0
|
11
|
-
x = 0
|
12
|
-
# x is available! Since it is declared within the draw
|
13
|
-
# block of code, it is available here.
|
14
|
-
# Notice, however, that it is not available inside draw
|
15
|
-
# above where it is declared.
|
16
|
-
# Also, it is available inside the while block of code
|
17
|
-
# because while is inside of draw.
|
18
|
-
|
19
|
-
while x < width
|
20
|
-
stroke 255
|
21
|
-
line x, 0, x, height
|
22
|
-
x += 5
|
23
|
-
end
|
24
|
-
|
25
|
-
# This could also be written with until:
|
26
|
-
# until x > width ...
|
27
|
-
# Or it could be written with step:
|
28
|
-
# 0.step(width, 5) do ...
|
29
|
-
|
30
|
-
end
|
31
|
-
|
32
|
-
def mouse_pressed
|
33
|
-
# x is not available! It is local to the draw block of code.
|
34
|
-
puts "The mouse was pressed!"
|
35
|
-
end
|
36
|
-
|
37
|
-
end
|
38
|
-
|
39
|
-
LocalVariables.new :title => "Local Variables", :width => 200, :height => 200
|
@@ -1,30 +0,0 @@
|
|
1
|
-
require 'ruby-processing'
|
2
|
-
|
3
|
-
class LinesOneAtATime < Processing::App
|
4
|
-
|
5
|
-
# No for loop here. Instead, a global variable.
|
6
|
-
# In ruby, global variables start with $.
|
7
|
-
$y = 0
|
8
|
-
|
9
|
-
def setup
|
10
|
-
background 255
|
11
|
-
# Slowing down the frame rate so we can easily see the effect.
|
12
|
-
frame_rate 5
|
13
|
-
end
|
14
|
-
|
15
|
-
def draw
|
16
|
-
# Draw a line
|
17
|
-
stroke 0
|
18
|
-
# Only one line is drawn each time through draw.
|
19
|
-
line 0, $y, width, $y
|
20
|
-
# Increment y
|
21
|
-
$y += 10
|
22
|
-
|
23
|
-
# Reset y back to 0 when it gets to the bottom of window
|
24
|
-
# In ruby, you can put if statements at the end, like speaking.
|
25
|
-
$y = 0 if $y > height
|
26
|
-
end
|
27
|
-
|
28
|
-
end
|
29
|
-
|
30
|
-
LinesOneAtATime.new :title => "Lines One At A Time", :width => 200, :height => 200
|
@@ -1,41 +0,0 @@
|
|
1
|
-
require 'ruby-processing'
|
2
|
-
|
3
|
-
class SimpleWhileLoopWithInteractivity < Processing::App
|
4
|
-
|
5
|
-
def setup
|
6
|
-
# no_stroke can go inside setup, because it only needs to be called once.
|
7
|
-
no_stroke
|
8
|
-
end
|
9
|
-
|
10
|
-
def draw
|
11
|
-
background 0
|
12
|
-
|
13
|
-
# Start with i as 0
|
14
|
-
i = 0
|
15
|
-
|
16
|
-
# While i is less than the width of the window
|
17
|
-
while i < width
|
18
|
-
# The distance between the current rectangle and the mouse
|
19
|
-
# is equal to the absolute value of the difference between i and mouseX.
|
20
|
-
distance = (mouse_x - i).abs
|
21
|
-
# That distance is used to fill the color of a rectangle at horizontal location i.
|
22
|
-
fill distance
|
23
|
-
rect i, 0, 10, height
|
24
|
-
# Increase i by 10
|
25
|
-
i += 10
|
26
|
-
end
|
27
|
-
|
28
|
-
# Un-comment the following lines to perform the same procedure
|
29
|
-
# for the height of the sketch, at half opacity.
|
30
|
-
# Uses a slightly different technique:
|
31
|
-
|
32
|
-
# (height/10).times do |j|
|
33
|
-
# distance = (mouse_y - j*10).abs
|
34
|
-
# fill distance, 128
|
35
|
-
# rect 0, j*10, width, 10
|
36
|
-
# end
|
37
|
-
end
|
38
|
-
|
39
|
-
end
|
40
|
-
|
41
|
-
SimpleWhileLoopWithInteractivity.new :title => "Simple While Loop With Interactivity", :width => 255, :height => 255
|
@@ -1,56 +0,0 @@
|
|
1
|
-
require 'ruby-processing'
|
2
|
-
|
3
|
-
class ZoogwithArms < Processing::App
|
4
|
-
|
5
|
-
def setup
|
6
|
-
@x, @y = 100, 100
|
7
|
-
@w, @h = 60, 60
|
8
|
-
@eye_size = 16
|
9
|
-
@speed = 1
|
10
|
-
smooth
|
11
|
-
|
12
|
-
# Set ellipses and rects to CENTER mode
|
13
|
-
# We can do this in setup because we only need to do it once
|
14
|
-
ellipseMode CENTER
|
15
|
-
rectMode CENTER
|
16
|
-
end
|
17
|
-
|
18
|
-
def draw
|
19
|
-
# Change the x location of Zoog by speed
|
20
|
-
@x += @speed
|
21
|
-
|
22
|
-
# If we've reached an edge, reverse speed i.e. multiply it by -1
|
23
|
-
# Note if speed is a + number, square moves to the right, - to the left
|
24
|
-
@speed *= -1 if @x > @width || @x < 0
|
25
|
-
|
26
|
-
background 255 # Draw a white background
|
27
|
-
stroke 0 # Set the stroke color to black
|
28
|
-
|
29
|
-
# Arms are incorporated into Zoog's design with a times loop.
|
30
|
-
6.times do |i|
|
31
|
-
y = i * 10 + @y + 5
|
32
|
-
line @x-@w/3, y, @x+@w/3, y
|
33
|
-
end
|
34
|
-
|
35
|
-
# Draw Zoog's body
|
36
|
-
fill 175
|
37
|
-
rect @x, @y, @w/6, @h*2
|
38
|
-
|
39
|
-
# Draw Zoog's head
|
40
|
-
fill 255
|
41
|
-
ellipse @x, @y-@h/2, @w, @h
|
42
|
-
|
43
|
-
# Draw Zoog's eyes
|
44
|
-
fill 0
|
45
|
-
ellipse @x-@w/3+1, @y-@h/2, @eye_size, @eye_size*2
|
46
|
-
ellipse @x+@w/3-1, @y-@h/2, @eye_size, @eye_size*2
|
47
|
-
|
48
|
-
# Draw Zoog's legs
|
49
|
-
line @x-@w/12, @y+@h, @x-@w/4, @y+@h+10
|
50
|
-
line @x+@w/12, @y+@h, @x+@w/4, @y+@h+10
|
51
|
-
|
52
|
-
end
|
53
|
-
|
54
|
-
end
|
55
|
-
|
56
|
-
ZoogwithArms.new :title => "Zoog with Arms", :width => 200, :height => 200
|
@@ -1,46 +0,0 @@
|
|
1
|
-
require 'ruby-processing'
|
2
|
-
|
3
|
-
class MultipleZoogs < Processing::App
|
4
|
-
|
5
|
-
def setup
|
6
|
-
@w, @h = 60, 60
|
7
|
-
@eye_size = 16
|
8
|
-
@y = height/2
|
9
|
-
smooth
|
10
|
-
ellipseMode CENTER
|
11
|
-
rectMode CENTER
|
12
|
-
end
|
13
|
-
|
14
|
-
def draw
|
15
|
-
background 255
|
16
|
-
stroke 0
|
17
|
-
|
18
|
-
# Multiple versions of Zoog
|
19
|
-
# If we want to show four Zoogs, let's draw it four times:
|
20
|
-
|
21
|
-
4.times do |i|
|
22
|
-
x = i * 80 + 80
|
23
|
-
|
24
|
-
# Draw Zoog's body
|
25
|
-
fill 175
|
26
|
-
rect x, @y, @w/6, @h*2
|
27
|
-
|
28
|
-
# Draw Zoog's head
|
29
|
-
fill 255
|
30
|
-
ellipse x, @y-@h/2, @w, @h
|
31
|
-
|
32
|
-
# Draw Zoog's eyes
|
33
|
-
fill 0
|
34
|
-
ellipse x-@w/3+1, @y-@h/2, @eye_size, @eye_size*2
|
35
|
-
ellipse x+@w/3-1, @y-@h/2, @eye_size, @eye_size*2
|
36
|
-
|
37
|
-
# Draw Zoog's legs
|
38
|
-
line x-@w/12, @y+@h, x-@w/4, @y+@h+10
|
39
|
-
line x+@w/12, @y+@h, x+@w/4, @y+@h+10
|
40
|
-
end
|
41
|
-
|
42
|
-
end
|
43
|
-
|
44
|
-
end
|
45
|
-
|
46
|
-
MultipleZoogs.new :title => "Multiple Zoogs", :width => 400, :height => 200
|
@@ -1,22 +0,0 @@
|
|
1
|
-
require 'ruby-processing'
|
2
|
-
|
3
|
-
class DefiningAFunction < Processing::App
|
4
|
-
|
5
|
-
def setup
|
6
|
-
|
7
|
-
end
|
8
|
-
|
9
|
-
def draw
|
10
|
-
|
11
|
-
end
|
12
|
-
|
13
|
-
# This example defines a function, but it is
|
14
|
-
# not called. So nothing happens.
|
15
|
-
def draw_black_circle
|
16
|
-
fill 0
|
17
|
-
ellipse 50, 50, 20, 20
|
18
|
-
end
|
19
|
-
|
20
|
-
end
|
21
|
-
|
22
|
-
DefiningAFunction.new :title => "Defining A Function", :width => 200, :height => 200
|