ruby-processing 1.0.1
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 +137 -0
- data/LICENSE +37 -0
- data/README +61 -0
- data/bin/rp5 +4 -0
- data/lib/core/core.jar +0 -0
- data/lib/core/jruby-complete.jar +0 -0
- data/lib/ruby-processing.rb +27 -0
- data/lib/ruby-processing/app.rb +358 -0
- data/lib/ruby-processing/exporters/applet_exporter.rb +75 -0
- data/lib/ruby-processing/exporters/application_exporter.rb +87 -0
- data/lib/ruby-processing/exporters/base_exporter.rb +133 -0
- data/lib/ruby-processing/exporters/creator.rb +46 -0
- data/lib/ruby-processing/helpers/string.rb +27 -0
- data/lib/ruby-processing/runner.rb +143 -0
- data/lib/ruby-processing/runners/base.rb +5 -0
- data/lib/ruby-processing/runners/live.rb +11 -0
- data/lib/ruby-processing/runners/run.rb +5 -0
- data/lib/ruby-processing/runners/watch.rb +42 -0
- data/lib/templates/applet/images/built_with.jpg +0 -0
- data/lib/templates/applet/images/ruby.jpg +0 -0
- data/lib/templates/applet/images/top.png +0 -0
- data/lib/templates/applet/index.html.erb +111 -0
- data/lib/templates/applet/library/library.txt +1 -0
- data/lib/templates/application/Contents/Info.plist.erb +58 -0
- data/lib/templates/application/Contents/MacOS/JavaApplicationStub +0 -0
- data/lib/templates/application/Contents/PkgInfo +1 -0
- data/lib/templates/application/Contents/Resources/sketch.icns +0 -0
- data/lib/templates/application/lib/MANIFEST.MF +3 -0
- data/lib/templates/application/lib/args.txt.erb +3 -0
- data/lib/templates/application/lib/library/library.txt +1 -0
- data/lib/templates/application/run.erb +4 -0
- data/lib/templates/application/run.exe +0 -0
- data/lib/templates/create/blank_sketch.rb.erb +15 -0
- data/library/boids/boids.rb +222 -0
- data/library/control_panel/control_panel.rb +149 -0
- data/library/dxf/bin/processing/dxf/RawDXF.class +0 -0
- data/library/dxf/dxfviewer.jar +0 -0
- data/library/dxf/library/dxf.jar +0 -0
- data/library/javascript/library/export.txt +6 -0
- data/library/javascript/library/javascript.jar +0 -0
- data/library/minim/library/jl1.0.jar +0 -0
- data/library/minim/library/jsminim.jar +0 -0
- data/library/minim/library/minim-spi.jar +0 -0
- data/library/minim/library/minim.jar +0 -0
- data/library/minim/library/mp3spi1.9.4.jar +0 -0
- data/library/minim/library/tritonus_aos.jar +0 -0
- data/library/minim/library/tritonus_share.jar +0 -0
- data/library/minim/license.txt +339 -0
- data/library/minim/version.txt +1 -0
- data/library/net/bin/processing/net/Client.class +0 -0
- data/library/net/bin/processing/net/Server.class +0 -0
- data/library/net/library/net.jar +0 -0
- data/library/opengl/bin/processing/opengl/PGraphicsOpenGL$ImageCache.class +0 -0
- data/library/opengl/bin/processing/opengl/PGraphicsOpenGL$TessCallback.class +0 -0
- data/library/opengl/bin/processing/opengl/PGraphicsOpenGL.class +0 -0
- data/library/opengl/library/export.txt +13 -0
- data/library/opengl/library/gluegen-rt-natives-linux-amd64.jar +0 -0
- data/library/opengl/library/gluegen-rt-natives-linux-i586.jar +0 -0
- data/library/opengl/library/gluegen-rt-natives-macosx-ppc.jar +0 -0
- data/library/opengl/library/gluegen-rt-natives-macosx-universal.jar +0 -0
- data/library/opengl/library/gluegen-rt-natives-windows-amd64.jar +0 -0
- data/library/opengl/library/gluegen-rt-natives-windows-i586.jar +0 -0
- data/library/opengl/library/gluegen-rt.dll +0 -0
- data/library/opengl/library/gluegen-rt.jar +0 -0
- data/library/opengl/library/gluegen-rt.jar.pack.gz +0 -0
- data/library/opengl/library/jogl-natives-linux-amd64.jar +0 -0
- data/library/opengl/library/jogl-natives-linux-i586.jar +0 -0
- data/library/opengl/library/jogl-natives-macosx-ppc.jar +0 -0
- data/library/opengl/library/jogl-natives-macosx-universal.jar +0 -0
- data/library/opengl/library/jogl-natives-windows-amd64.jar +0 -0
- data/library/opengl/library/jogl-natives-windows-i586.jar +0 -0
- data/library/opengl/library/jogl.dll +0 -0
- data/library/opengl/library/jogl.jar +0 -0
- data/library/opengl/library/jogl.jar.pack.gz +0 -0
- data/library/opengl/library/jogl_awt.dll +0 -0
- data/library/opengl/library/jogl_cg.dll +0 -0
- data/library/opengl/library/libgluegen-rt.jnilib +0 -0
- data/library/opengl/library/libgluegen-rt.so +0 -0
- data/library/opengl/library/libjogl.jnilib +0 -0
- data/library/opengl/library/libjogl.so +0 -0
- data/library/opengl/library/libjogl_awt.jnilib +0 -0
- data/library/opengl/library/libjogl_awt.so +0 -0
- data/library/opengl/library/libjogl_cg.jnilib +0 -0
- data/library/opengl/library/libjogl_cg.so +0 -0
- data/library/opengl/library/opengl.jar +0 -0
- data/library/pdf/bin/processing/pdf/PGraphicsPDF.class +0 -0
- data/library/pdf/library/itext.jar +0 -0
- data/library/pdf/library/pdf.jar +0 -0
- data/library/pdf/notes.txt +9 -0
- data/library/serial/bin/processing/serial/Serial.class +0 -0
- data/library/serial/library/RXTXcomm.jar +0 -0
- data/library/serial/library/export.txt +3 -0
- data/library/serial/library/librxtxSerial.jnilib +0 -0
- data/library/serial/library/librxtxSerial.so +0 -0
- data/library/serial/library/rxtxSerial.dll +0 -0
- data/library/serial/library/serial.jar +0 -0
- data/library/video/bin/processing/video/Capture.class +0 -0
- data/library/video/bin/processing/video/Movie.class +0 -0
- data/library/video/bin/processing/video/MovieMaker.class +0 -0
- data/library/video/library/video.jar +0 -0
- data/samples/animator.rb +47 -0
- data/samples/circle_collision.rb +213 -0
- data/samples/fern.rb +49 -0
- data/samples/flight_patterns.rb +64 -0
- data/samples/full_screen.rb +35 -0
- data/samples/getting_started.rb +43 -0
- data/samples/jwishy.rb +85 -0
- data/samples/kinetic_type.rb +100 -0
- data/samples/learning_processing/ABOUT +11 -0
- data/samples/learning_processing/chapter_01/1_stroke_and_fill.rb +34 -0
- data/samples/learning_processing/chapter_01/2_nofill.rb +25 -0
- data/samples/learning_processing/chapter_01/3_rgb_color.rb +31 -0
- data/samples/learning_processing/chapter_01/4_alpha_transparency.rb +36 -0
- data/samples/learning_processing/chapter_01/5_zoog.rb +37 -0
- data/samples/learning_processing/chapter_02/1_zoog_again.rb +39 -0
- data/samples/learning_processing/chapter_03/1_zoog_as_dynamic_sketch.rb +44 -0
- data/samples/learning_processing/chapter_03/2_mouse_x_and_mouse_y.rb +26 -0
- data/samples/learning_processing/chapter_03/3_zoog_as_dynamic_sketch_with_variation.rb +41 -0
- data/samples/learning_processing/chapter_03/4_drawing_a_continuous_line.rb +18 -0
- data/samples/learning_processing/chapter_03/5_mouse_pressed_and_key_pressed.rb +29 -0
- data/samples/learning_processing/chapter_03/6_interactive_zoog.rb +50 -0
- data/samples/learning_processing/chapter_04/1_variable_declaration.rb +24 -0
- data/samples/learning_processing/chapter_04/2_using_variables.rb +27 -0
- data/samples/learning_processing/chapter_04/3_varying_variables.rb +27 -0
- data/samples/learning_processing/chapter_04/4_many_variables.rb +38 -0
- data/samples/learning_processing/chapter_04/5_using_system_variables.rb +28 -0
- data/samples/learning_processing/chapter_04/6_ellipse_with_variables.rb +24 -0
- data/samples/learning_processing/chapter_04/7_filling_variables_with_random_values.rb +27 -0
- data/samples/learning_processing/chapter_04/8_variable_zoog.rb +50 -0
- data/samples/learning_processing/chapter_05/01_conditionals.rb +31 -0
- data/samples/learning_processing/chapter_05/02_more_conditionals.rb +38 -0
- data/samples/learning_processing/chapter_05/03_rollovers.rb +34 -0
- data/samples/learning_processing/chapter_05/04_hold_down_the_button.rb +33 -0
- data/samples/learning_processing/chapter_05/05_button_as_switch.rb +39 -0
- data/samples/learning_processing/chapter_05/06_bouncing_ball.rb +33 -0
- data/samples/learning_processing/chapter_05/07_bouncing_color.rb +37 -0
- data/samples/learning_processing/chapter_05/08_square_following_edge.rb +59 -0
- data/samples/learning_processing/chapter_05/09_simple_gravity.rb +43 -0
- data/samples/learning_processing/chapter_05/10_zoog_and_conditionals.rb +53 -0
- data/samples/learning_processing/chapter_06/01_many_lines.rb +29 -0
- data/samples/learning_processing/chapter_06/02_many_lines_with_variables.rb +53 -0
- data/samples/learning_processing/chapter_06/03_while_loop.rb +30 -0
- data/samples/learning_processing/chapter_06/04_infinite_loop.rb +25 -0
- data/samples/learning_processing/chapter_06/05_another_infinite_loop.rb +33 -0
- data/samples/learning_processing/chapter_06/06_legs_with_a_for_loop.rb +41 -0
- data/samples/learning_processing/chapter_06/07_local_variables.rb +39 -0
- data/samples/learning_processing/chapter_06/08_lines_one_at_a_time.rb +30 -0
- data/samples/learning_processing/chapter_06/09_simple_while_loop_with_interactivity.rb +41 -0
- data/samples/learning_processing/chapter_06/10_zoog_with_arms.rb +56 -0
- data/samples/learning_processing/chapter_06/11_multiple_zoogs.rb +46 -0
- data/samples/learning_processing/chapter_07/01_defining_a_function.rb +22 -0
- data/samples/learning_processing/chapter_07/02_calling_a_function.rb +22 -0
- data/samples/learning_processing/chapter_07/03_bouncing_ball_with_functions.rb +49 -0
- data/samples/learning_processing/chapter_07/04_function_returns_distance.rb +48 -0
- data/samples/learning_processing/chapter_07/05_zoog_with_functions.rb +71 -0
- data/samples/learning_processing/chapter_08/01_car_class_and_car_variable.rb +45 -0
- data/samples/learning_processing/chapter_08/02_two_car_objects.rb +60 -0
- data/samples/learning_processing/chapter_08/03_object_oriented_zoog.rb +81 -0
- data/samples/learning_processing/chapter_10/01_catcher.rb +35 -0
- data/samples/learning_processing/chapter_10/02_bouncing_ball.rb +44 -0
- data/samples/learning_processing/chapter_10/03_bouncing_balls_with_intersection.rb +69 -0
- data/samples/learning_processing/chapter_10/04_a_timer.rb +24 -0
- data/samples/learning_processing/chapter_10/05_object_oriented_timer.rb +42 -0
- data/samples/learning_processing/chapter_10/06_simple_raindrop.rb +23 -0
- data/samples/learning_processing/chapter_10/07_drops_one_at_a_time.rb +63 -0
- data/samples/learning_processing/chapter_13/02_random_number_distribution.rb +24 -0
- data/samples/learning_processing/chapter_13/03_probabilities.rb +33 -0
- data/samples/learning_processing/chapter_13/04_perlin_noise.rb +22 -0
- data/samples/learning_processing/chapter_13/06_oscillation.rb +29 -0
- data/samples/learning_processing/chapter_13/07_wave.rb +31 -0
- data/samples/learning_processing/chapter_13/08_recursion.rb +30 -0
- data/samples/learning_processing/chapter_13/09_two_dimensional_array.rb +21 -0
- data/samples/learning_processing/chapter_13/10_two_dimensional_array_with_objects.rb +54 -0
- data/samples/learning_processing/chapter_14/01_growing_rectangle.rb +26 -0
- data/samples/learning_processing/chapter_14/02_multiple_translations.rb +37 -0
- data/samples/learning_processing/chapter_14/03_depth_rectangle.rb +29 -0
- data/samples/learning_processing/chapter_14/04_pyramid_using_beingshape.rb +55 -0
- data/samples/learning_processing/chapter_14/05_rotate_rectangle_around_center.rb +28 -0
- data/samples/learning_processing/chapter_14/06_rotate_z.rb +24 -0
- data/samples/learning_processing/chapter_14/07_rotate_x.rb +24 -0
- data/samples/learning_processing/chapter_14/08_rotate_y.rb +24 -0
- data/samples/learning_processing/chapter_14/09_rotate_all.rb +24 -0
- data/samples/learning_processing/chapter_14/10_draw_pyramid.rb +59 -0
- data/samples/learning_processing/chapter_14/12_rotating_one_square.rb +25 -0
- data/samples/learning_processing/chapter_14/13_rotating_another_square.rb +25 -0
- data/samples/learning_processing/chapter_14/14_rotating_both_squares.rb +43 -0
- data/samples/learning_processing/chapter_14/15_rotating_many_things.rb +56 -0
- data/samples/learning_processing/chapter_14/16_simple_solar_system.rb +53 -0
- data/samples/learning_processing/chapter_14/17_nested_push_and_pop.rb +50 -0
- data/samples/learning_processing/chapter_14/18_object_oriented_solar_system.rb +69 -0
- data/samples/learning_processing/chapter_15/01_hello_world_image.rb +20 -0
- data/samples/learning_processing/chapter_15/02_image_sprite.rb +29 -0
- data/samples/learning_processing/chapter_15/03_swapping_images.rb +25 -0
- data/samples/learning_processing/chapter_15/04_image_sequence.rb +22 -0
- data/samples/learning_processing/chapter_15/05_setting_pixels.rb +19 -0
- data/samples/learning_processing/chapter_15/06_pixels_2d.rb +29 -0
- data/samples/learning_processing/chapter_15/07_image_pixels.rb +40 -0
- data/samples/learning_processing/chapter_15/08_image_brightness.rb +29 -0
- data/samples/learning_processing/chapter_15/09_flashlight_effect.rb +42 -0
- data/samples/learning_processing/chapter_15/10_brightness_threshold.rb +33 -0
- data/samples/learning_processing/chapter_15/11_brightness_threshold_with_filter.rb +20 -0
- data/samples/learning_processing/chapter_15/12_pixel_neighbour_differences.rb +43 -0
- data/samples/learning_processing/chapter_15/14_pointillism.rb +34 -0
- data/samples/learning_processing/chapter_15/15_2d_image_mapped_to_3d.rb +43 -0
- 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 +25 -0
- data/samples/learning_processing/chapter_16/02_manipulate_video_image.rb +24 -0
- data/samples/reflection.rb +26 -0
- data/samples/simple_buffer.rb +49 -0
- data/samples/tree.rb +83 -0
- metadata +348 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
require 'ruby-processing'
|
|
2
|
+
|
|
3
|
+
class RotatingOneSquareSketch < Processing::App
|
|
4
|
+
|
|
5
|
+
def setup
|
|
6
|
+
render_mode P3D
|
|
7
|
+
rect_mode CENTER
|
|
8
|
+
@theta1 = 0
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def draw
|
|
12
|
+
background 255
|
|
13
|
+
stroke 0
|
|
14
|
+
fill 175
|
|
15
|
+
|
|
16
|
+
translate 50, 50
|
|
17
|
+
rotate_z @theta1
|
|
18
|
+
rect 0, 0, 60, 60
|
|
19
|
+
@theta1 += 0.02
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
RotatingOneSquareSketch.new :title => "Rotating One Square", :width => 200, :height => 200
|
|
25
|
+
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
require 'ruby-processing'
|
|
2
|
+
|
|
3
|
+
class RotatingAnotherSquareSketch < Processing::App
|
|
4
|
+
|
|
5
|
+
def setup
|
|
6
|
+
render_mode P3D
|
|
7
|
+
rect_mode CENTER
|
|
8
|
+
@theta2 = 0
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def draw
|
|
12
|
+
background 255
|
|
13
|
+
stroke 0
|
|
14
|
+
fill 175
|
|
15
|
+
|
|
16
|
+
translate 150, 150
|
|
17
|
+
rotate_y @theta2
|
|
18
|
+
rect 0, 0, 60, 60
|
|
19
|
+
@theta2 += 0.02
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
RotatingAnotherSquareSketch.new :title => "Rotating Another Square", :width => 200, :height => 200
|
|
25
|
+
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
require 'ruby-processing'
|
|
2
|
+
|
|
3
|
+
class RotatingBothSquaresSketch < Processing::App
|
|
4
|
+
|
|
5
|
+
def setup
|
|
6
|
+
render_mode P3D
|
|
7
|
+
rect_mode CENTER
|
|
8
|
+
@theta1 = @theta2 = 0
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def draw
|
|
12
|
+
background 255
|
|
13
|
+
stroke 0
|
|
14
|
+
fill 175
|
|
15
|
+
|
|
16
|
+
# Save the current transformation matrix.
|
|
17
|
+
# This is where we started, with (0,0) in the top left corner of the window and no rotation.
|
|
18
|
+
push_matrix
|
|
19
|
+
|
|
20
|
+
# Translate and rotate the first rectangle.
|
|
21
|
+
translate 50, 50
|
|
22
|
+
rotate_z @theta1
|
|
23
|
+
# Display the first rectangle.
|
|
24
|
+
rect 0, 0, 60, 60
|
|
25
|
+
# Restore matrix from Step 1 so that it isn't affected by Steps 2 and 3!
|
|
26
|
+
pop_matrix
|
|
27
|
+
|
|
28
|
+
push_matrix
|
|
29
|
+
# Translate and rotate the second rectangle.
|
|
30
|
+
translate 150, 150
|
|
31
|
+
rotate_y @theta2
|
|
32
|
+
# Display the second rectangle.
|
|
33
|
+
rect 0, 0, 60, 60
|
|
34
|
+
pop_matrix
|
|
35
|
+
|
|
36
|
+
@theta1 += 0.02
|
|
37
|
+
@theta2 += 0.02
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
RotatingBothSquaresSketch.new :title => "Rotating Both Squares", :width => 200, :height => 200
|
|
43
|
+
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
require 'ruby-processing'
|
|
2
|
+
|
|
3
|
+
# A Rotater class
|
|
4
|
+
class Rotater
|
|
5
|
+
|
|
6
|
+
def initialize(x, y, speed, width)
|
|
7
|
+
@x, @y = x, y
|
|
8
|
+
# Angle is always initialized to 0
|
|
9
|
+
@theta = 0
|
|
10
|
+
@speed = speed
|
|
11
|
+
@w = width
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
# Increment angle
|
|
15
|
+
def spin
|
|
16
|
+
@theta += @speed
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# Display rectangle
|
|
20
|
+
def display
|
|
21
|
+
# push_matrix and pop_matrix are called inside the class' display method.
|
|
22
|
+
# This way, every Rotater object is rendered with its own independent translation and rotation!
|
|
23
|
+
$app.push_matrix
|
|
24
|
+
$app.translate @x, @y
|
|
25
|
+
$app.rotate @theta
|
|
26
|
+
$app.rect 0, 0, @w, @w
|
|
27
|
+
$app.pop_matrix
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
class RotatingManyThingsSketch < Processing::App
|
|
33
|
+
|
|
34
|
+
def setup
|
|
35
|
+
rect_mode CENTER
|
|
36
|
+
stroke 0
|
|
37
|
+
fill 0, 100
|
|
38
|
+
@rotaters = Array.new(20) do
|
|
39
|
+
Rotater.new(rand(width), rand(height), random(-0.1, 0.1), rand(48))
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def draw
|
|
44
|
+
background 255
|
|
45
|
+
|
|
46
|
+
# All Rotaters spin and are displayed
|
|
47
|
+
@rotaters.each do |r|
|
|
48
|
+
r.spin
|
|
49
|
+
r.display
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
RotatingManyThingsSketch.new :title => "Rotating Many Things", :width => 200, :height => 200
|
|
56
|
+
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
require 'ruby-processing'
|
|
2
|
+
|
|
3
|
+
class SimpleSolarSystemSketch < Processing::App
|
|
4
|
+
|
|
5
|
+
def setup
|
|
6
|
+
smooth
|
|
7
|
+
@theta = 0 # Angle of rotation around sun and planets
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def draw
|
|
11
|
+
background 255
|
|
12
|
+
stroke 0
|
|
13
|
+
|
|
14
|
+
# Translate to center of window to draw the sun.
|
|
15
|
+
translate width/2, height/2
|
|
16
|
+
fill 255, 200, 50
|
|
17
|
+
ellipse 0, 0, 20, 20
|
|
18
|
+
|
|
19
|
+
# The earth rotates around the sun
|
|
20
|
+
push_matrix
|
|
21
|
+
rotate @theta
|
|
22
|
+
translate 50, 0
|
|
23
|
+
fill 50, 200, 255
|
|
24
|
+
ellipse 0, 0, 10, 10
|
|
25
|
+
|
|
26
|
+
# Moon #1 rotates around the earth
|
|
27
|
+
# push_matrix is called to save the transformation state before drawing moon #1.
|
|
28
|
+
# This way we can pop and return to earth before drawing moon #2.
|
|
29
|
+
# Both moons rotate around the earth which itself is rotating around the sun).
|
|
30
|
+
push_matrix
|
|
31
|
+
rotate -@theta*4
|
|
32
|
+
translate 15, 0
|
|
33
|
+
fill 50, 255, 200
|
|
34
|
+
ellipse 0, 0, 6, 6
|
|
35
|
+
pop_matrix
|
|
36
|
+
|
|
37
|
+
# Moon #2 also rotates around the earth
|
|
38
|
+
push_matrix
|
|
39
|
+
rotate @theta*2
|
|
40
|
+
translate 25, 0
|
|
41
|
+
fill 50, 255, 200
|
|
42
|
+
ellipse 0, 0, 6, 6
|
|
43
|
+
pop_matrix
|
|
44
|
+
|
|
45
|
+
pop_matrix
|
|
46
|
+
|
|
47
|
+
@theta += 0.01;
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
SimpleSolarSystemSketch.new :title => "Simple Solar System", :width => 200, :height => 200
|
|
53
|
+
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
require 'ruby-processing'
|
|
2
|
+
|
|
3
|
+
class NestedPushAndPopSketch < Processing::App
|
|
4
|
+
|
|
5
|
+
def setup
|
|
6
|
+
smooth
|
|
7
|
+
@theta = 0 # angle for rotation
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def draw
|
|
11
|
+
background 255
|
|
12
|
+
stroke 0
|
|
13
|
+
|
|
14
|
+
# Translate to center of window
|
|
15
|
+
translate width/2, height/2
|
|
16
|
+
|
|
17
|
+
# Loop from 0 to 360 degrees (2*PI radians)
|
|
18
|
+
0.step(TWO_PI, 0.2) do |i|
|
|
19
|
+
|
|
20
|
+
# Push, rotate and draw a line!
|
|
21
|
+
# The transformation state is saved at the beginning of each cycle through the for loop and restored at the end.
|
|
22
|
+
# Try commenting out these lines to see the difference!
|
|
23
|
+
push_matrix
|
|
24
|
+
rotate @theta + i
|
|
25
|
+
line 0, 0, 100, 0
|
|
26
|
+
|
|
27
|
+
# Loop from 0 to 360 degrees (2*PI radians)
|
|
28
|
+
0.step(TWO_PI, 0.5) do |j|
|
|
29
|
+
# Push, translate, rotate and draw a line!
|
|
30
|
+
push_matrix
|
|
31
|
+
translate 100, 0
|
|
32
|
+
rotate -@theta - j
|
|
33
|
+
line 0, 0, 50, 0
|
|
34
|
+
# We're done with the inside loop,pop!
|
|
35
|
+
pop_matrix
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# We're done with the outside loop, pop!
|
|
39
|
+
pop_matrix
|
|
40
|
+
end
|
|
41
|
+
end_shape
|
|
42
|
+
|
|
43
|
+
# Increment @theta
|
|
44
|
+
@theta += 0.01
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
NestedPushAndPopSketch.new :title => "Nested Push and Pop", :width => 200, :height => 200
|
|
50
|
+
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
require 'ruby-processing'
|
|
2
|
+
|
|
3
|
+
class Planet
|
|
4
|
+
|
|
5
|
+
# Each planet object keeps track of its own angle of rotation.
|
|
6
|
+
# @theta Rotation around sun
|
|
7
|
+
# @diameter Size of planet
|
|
8
|
+
# @distance Distance from sun
|
|
9
|
+
# @orbit_speed Orbit speed
|
|
10
|
+
def initialize(distance, diameter)
|
|
11
|
+
@distance = distance
|
|
12
|
+
@diameter = diameter
|
|
13
|
+
@theta = 0
|
|
14
|
+
@orbit_speed = rand * 0.02 + 0.01
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def update
|
|
18
|
+
# Increment the angle to rotate
|
|
19
|
+
@theta += @orbit_speed
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def display
|
|
23
|
+
# Before rotation and translation, the state of the matrix is saved with push_matrix.
|
|
24
|
+
$app.push_matrix
|
|
25
|
+
# Rotate orbit
|
|
26
|
+
$app.rotate @theta
|
|
27
|
+
# translate out @distance
|
|
28
|
+
$app.translate @distance, 0
|
|
29
|
+
$app.stroke 0
|
|
30
|
+
$app.fill 175
|
|
31
|
+
$app.ellipse 0, 0, @diameter, @diameter
|
|
32
|
+
# Once the planet is drawn, the matrix is restored with pop_matrix so that the next planet is not affected.
|
|
33
|
+
$app.pop_matrix
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
class ObjectOrientedSolarSystemSketch < Processing::App
|
|
40
|
+
|
|
41
|
+
def setup
|
|
42
|
+
smooth
|
|
43
|
+
@planets = Array.new(8) { |i| Planet.new(20+i*10, i+8) }
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def draw
|
|
47
|
+
background 255
|
|
48
|
+
|
|
49
|
+
# Drawing the Sun
|
|
50
|
+
push_matrix
|
|
51
|
+
# Translate to center of window
|
|
52
|
+
translate width/2, height/2
|
|
53
|
+
stroke 0
|
|
54
|
+
fill 255
|
|
55
|
+
ellipse 0, 0, 20, 20
|
|
56
|
+
|
|
57
|
+
# Drawing all Planets
|
|
58
|
+
@planets.each do |p|
|
|
59
|
+
p.update
|
|
60
|
+
p.display
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
pop_matrix
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
ObjectOrientedSolarSystemSketch.new :title => "Object Oriented Solar System", :width => 200, :height => 200
|
|
69
|
+
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
require 'ruby-processing'
|
|
2
|
+
|
|
3
|
+
class HelloWorldImageSketch < Processing::App
|
|
4
|
+
|
|
5
|
+
def setup
|
|
6
|
+
# the image file must be in the data directory
|
|
7
|
+
@img = load_image("mysummervacation.jpg")
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def draw
|
|
11
|
+
background 0
|
|
12
|
+
|
|
13
|
+
#The image function displays the image at a location-in this case the point (0,0).
|
|
14
|
+
image @img, 0, 0
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
HelloWorldImageSketch.new :title => "Hello World Image", :width => 320, :height => 240
|
|
20
|
+
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
require 'ruby-processing'
|
|
2
|
+
|
|
3
|
+
class ImageSpriteSketch < Processing::App
|
|
4
|
+
|
|
5
|
+
def setup
|
|
6
|
+
@head = load_image("face.jpg") # variable for the image file
|
|
7
|
+
@x, @y = 0, width/2 # variables for image location
|
|
8
|
+
@rot = 0.0 # variable for image rotation
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def draw
|
|
12
|
+
background 255
|
|
13
|
+
|
|
14
|
+
translate @x, @y
|
|
15
|
+
rotate @rot
|
|
16
|
+
|
|
17
|
+
# Images can be animated just like regular shapes using variables, translate, rotate, and so on.
|
|
18
|
+
image @head, 0, 0
|
|
19
|
+
# Adjust variables for animation
|
|
20
|
+
@x += 1.0
|
|
21
|
+
@rot += 0.02
|
|
22
|
+
@x = -@head.width if @x > width + @head.width
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
ImageSpriteSketch.new :title => "Image Sprite", :width => 200, :height => 200
|
|
28
|
+
|
|
29
|
+
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
require 'ruby-processing'
|
|
2
|
+
|
|
3
|
+
class SwappingImagesSketch < Processing::App
|
|
4
|
+
|
|
5
|
+
def setup
|
|
6
|
+
@index = 0
|
|
7
|
+
@count = 7
|
|
8
|
+
# loading the images into the array
|
|
9
|
+
@images = (0...@count).map { |i| load_image("animal#{i}.jpg") }
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def draw
|
|
13
|
+
# displaying one images
|
|
14
|
+
image @images[@index], 0, 0
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def mouse_pressed
|
|
18
|
+
# A new image is picked randomly when the mouse is clicked
|
|
19
|
+
@index = rand(@images.size)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
SwappingImagesSketch.new :title => "Swapping Images", :width => 200, :height => 200
|
|
25
|
+
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
require 'ruby-processing'
|
|
2
|
+
|
|
3
|
+
class ImageSequence < Processing::App
|
|
4
|
+
|
|
5
|
+
def setup
|
|
6
|
+
@index = 0
|
|
7
|
+
@count = 7
|
|
8
|
+
# loading the images into the array
|
|
9
|
+
@images = (0...@count).map { |i| load_image("animal#{i}.jpg") }
|
|
10
|
+
frame_rate 5
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def draw
|
|
14
|
+
# displaying one images
|
|
15
|
+
image @images[@index], 0, 0
|
|
16
|
+
@index = (@index + 1) % @images.size
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
ImageSequence.new :title => "Image Sequence", :width => 200, :height => 200
|
|
22
|
+
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
require 'ruby-processing'
|
|
2
|
+
|
|
3
|
+
class SettingPixelsSketch < Processing::App
|
|
4
|
+
|
|
5
|
+
def setup
|
|
6
|
+
# load the pixels array
|
|
7
|
+
load_pixels
|
|
8
|
+
background 0
|
|
9
|
+
# loop through the pixels and set each one to a random greyscale color
|
|
10
|
+
pixels.size.times { |i| pixels[i] = color(rand 255) }
|
|
11
|
+
# update the pixels on screen
|
|
12
|
+
update_pixels
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
SettingPixelsSketch.new :title => "Setting Pixels", :width => 200, :height => 200
|
|
19
|
+
|