ruby-processing 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- 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,30 @@
|
|
1
|
+
require 'ruby-processing'
|
2
|
+
|
3
|
+
class RecursionSketch < Processing::App
|
4
|
+
|
5
|
+
def setup
|
6
|
+
smooth
|
7
|
+
end
|
8
|
+
|
9
|
+
def draw
|
10
|
+
background 255
|
11
|
+
stroke 0
|
12
|
+
no_fill
|
13
|
+
|
14
|
+
draw_circle width/2, height/2, width/2
|
15
|
+
end
|
16
|
+
|
17
|
+
def draw_circle(x, y, radius)
|
18
|
+
ellipse x, y, radius, radius
|
19
|
+
# It's important to establish an end-point to recursion, or else it
|
20
|
+
# would go forever. Comment out the following line to break the sketch.
|
21
|
+
return if radius < 2
|
22
|
+
# draw_circle calls itself twice, creating a branching effect.
|
23
|
+
# For every circle, a smaller circle is drawn to the left and right.
|
24
|
+
draw_circle x+radius/2, y, radius/2
|
25
|
+
draw_circle x-radius/2, y, radius/2
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
RecursionSketch.new :title => "Recursion", :width => 200, :height => 200
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'ruby-processing'
|
2
|
+
|
3
|
+
class TwoDimensionalArraySketch < Processing::App
|
4
|
+
|
5
|
+
def setup
|
6
|
+
smooth
|
7
|
+
# initialize array with random values
|
8
|
+
@my_array = Array.new(width) { Array.new(height) { rand 255 }}
|
9
|
+
|
10
|
+
# draw the points
|
11
|
+
width.times do |i|
|
12
|
+
height.times do |j|
|
13
|
+
stroke @my_array[i][j]
|
14
|
+
point i, j
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
TwoDimensionalArraySketch.new :title => "Two Dimensional Array", :width => 200, :height => 200
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'ruby-processing'
|
2
|
+
|
3
|
+
# Let's start by defining the cell class.
|
4
|
+
class Cell
|
5
|
+
|
6
|
+
def initialize(x, y, w, h, angle)
|
7
|
+
@x, @y = x, y
|
8
|
+
@w, @h = w, h
|
9
|
+
@angle = angle
|
10
|
+
end
|
11
|
+
|
12
|
+
# we oscillate by increasing the angle, here.
|
13
|
+
def oscillate
|
14
|
+
@angle += 0.02
|
15
|
+
end
|
16
|
+
|
17
|
+
def display
|
18
|
+
$app.stroke 255
|
19
|
+
# calculate color using sine wave
|
20
|
+
$app.fill 127 + 127 * Math.sin(@angle)
|
21
|
+
$app.rect @x, @y, @w, @h
|
22
|
+
end
|
23
|
+
|
24
|
+
def oscillate_and_display
|
25
|
+
oscillate
|
26
|
+
display
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
# And then the sketch that holds many cells.
|
33
|
+
class ArrayWithObjectsSketch < Processing::App
|
34
|
+
|
35
|
+
def setup
|
36
|
+
smooth
|
37
|
+
@cols = @rows = 20
|
38
|
+
|
39
|
+
# initialize array with random values
|
40
|
+
@grid = Array.new(@cols) do |i|
|
41
|
+
Array.new(@rows) do |j|
|
42
|
+
Cell.new(i*20, j*20, 20, 20, i+j)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def draw
|
48
|
+
background 0
|
49
|
+
@grid.each { |array| array.each { |cell| cell.oscillate_and_display } }
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
ArrayWithObjectsSketch.new :title => "Two Dimensional Array with Objects", :width => 200, :height => 200
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'ruby-processing'
|
2
|
+
|
3
|
+
class GrowingRectangleSketch < Processing::App
|
4
|
+
|
5
|
+
def setup
|
6
|
+
rect_mode CENTER
|
7
|
+
@r = 8
|
8
|
+
end
|
9
|
+
|
10
|
+
def draw
|
11
|
+
background 255
|
12
|
+
# Display a rectangle in the middle of the screen
|
13
|
+
stroke 0
|
14
|
+
fill 175
|
15
|
+
rect width/2, height/2, @r, @r
|
16
|
+
|
17
|
+
# Increase the rectangle size
|
18
|
+
@r += 1
|
19
|
+
|
20
|
+
# Start rectangle over
|
21
|
+
@r = 0 if @r > width
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
GrowingRectangleSketch.new :title => "Growing Rectangle", :width => 200, :height => 200
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'ruby-processing'
|
2
|
+
|
3
|
+
class MultipleTranslationsSketch < Processing::App
|
4
|
+
|
5
|
+
def setup
|
6
|
+
smooth
|
7
|
+
end
|
8
|
+
|
9
|
+
def draw
|
10
|
+
background 255
|
11
|
+
stroke 0
|
12
|
+
fill 175
|
13
|
+
|
14
|
+
# Grab mouse coordinates, constrained to window
|
15
|
+
mx = constrain(mouse_x, 0, width)
|
16
|
+
my = constrain(mouse_y, 0, height)
|
17
|
+
|
18
|
+
# Translate to the mouse location
|
19
|
+
translate mx, my
|
20
|
+
ellipse 0, 0, 8, 8
|
21
|
+
|
22
|
+
# Translate 100 pixels to the right
|
23
|
+
translate 100, 0
|
24
|
+
ellipse 0, 0, 8, 8
|
25
|
+
|
26
|
+
# Translate 100 pixels down
|
27
|
+
translate 0, 100
|
28
|
+
ellipse 0, 0, 8, 8
|
29
|
+
|
30
|
+
# Translate 100 pixels left
|
31
|
+
translate -100, 0
|
32
|
+
ellipse 0, 0, 8, 8
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
MultipleTranslationsSketch.new :title => "Multiple Translations", :width => 200, :height => 200
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'ruby-processing'
|
2
|
+
|
3
|
+
class DepthRectangleSketch < Processing::App
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@z = 0 # A variable for the z (depth) coordinate
|
7
|
+
rect_mode CENTER
|
8
|
+
render_mode P3D
|
9
|
+
end
|
10
|
+
|
11
|
+
def draw
|
12
|
+
background 255
|
13
|
+
stroke 0
|
14
|
+
fill 175
|
15
|
+
|
16
|
+
# Translate to a point before displaying a shape there
|
17
|
+
translate width/2, height/2, @z
|
18
|
+
rect 0, 0, 8, 8
|
19
|
+
|
20
|
+
# Increment z (i.e. move the shape toward the viewer)
|
21
|
+
@z += 1
|
22
|
+
|
23
|
+
# Start rectangle over
|
24
|
+
@z = 0 if @z > 200
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
DepthRectangleSketch.new :title => "Depth Rectangle", :width => 200, :height => 200
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'ruby-processing'
|
2
|
+
|
3
|
+
class PyramidUsingBeginshape < Processing::App
|
4
|
+
|
5
|
+
def setup
|
6
|
+
render_mode P3D
|
7
|
+
end
|
8
|
+
|
9
|
+
def draw
|
10
|
+
background 255
|
11
|
+
stroke 0
|
12
|
+
|
13
|
+
# The pyramid's vertices are drawn relative to a centerpoint.
|
14
|
+
# Therefore, we call translate to place the pyramid properly in the window.
|
15
|
+
# A slightly better option might be to include the translate in the draw_pyramid function and pass in x,y,z as arguments
|
16
|
+
translate 100, 100, 0
|
17
|
+
draw_pyramid 150
|
18
|
+
end
|
19
|
+
|
20
|
+
|
21
|
+
# The function sets the vertices for the pyramid around the centerpoint at a flexible distance,
|
22
|
+
# depending on the number passed in as an argument.
|
23
|
+
def draw_pyramid(t)
|
24
|
+
# this pyramid has 4 sides, each drawn as a separate triangle
|
25
|
+
# each side has 3 vertices, making up a triangle shape
|
26
|
+
# the parameter " t " determines the size of the pyramid
|
27
|
+
begin_shape TRIANGLES
|
28
|
+
|
29
|
+
fill 255, 150 # Note that each polygon can have its own color.
|
30
|
+
vertex -t,-t,-t
|
31
|
+
vertex t,-t,-t
|
32
|
+
vertex 0, 0, t
|
33
|
+
|
34
|
+
fill 150, 150
|
35
|
+
vertex t,-t,-t
|
36
|
+
vertex t, t,-t
|
37
|
+
vertex 0, 0, t
|
38
|
+
|
39
|
+
fill 255, 150
|
40
|
+
vertex t, t,-t
|
41
|
+
vertex -t, t,-t
|
42
|
+
vertex 0, 0, t
|
43
|
+
|
44
|
+
fill 150, 150
|
45
|
+
vertex -t, t,-t
|
46
|
+
vertex -t,-t,-t
|
47
|
+
vertex 0, 0, t
|
48
|
+
|
49
|
+
end_shape
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
PyramidUsingBeginshape.new :title => "Draw Pyramid Using BeginShape", :width => 200, :height => 200
|
55
|
+
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'ruby-processing'
|
2
|
+
|
3
|
+
class RotateRectangleAroundCenterSketch < Processing::App
|
4
|
+
|
5
|
+
def setup
|
6
|
+
render_mode P3D
|
7
|
+
rect_mode CENTER
|
8
|
+
end
|
9
|
+
|
10
|
+
def draw
|
11
|
+
background 255
|
12
|
+
stroke 0
|
13
|
+
fill 175
|
14
|
+
|
15
|
+
# translate to center
|
16
|
+
translate width/2, height/2
|
17
|
+
# The greek letter "theta" is often used as the name of a variable to store an angle
|
18
|
+
# The angle ranges from 0 to PI, based on the ratio of mouse_x location to the sketch's width.
|
19
|
+
theta = PI * mouse_x / width
|
20
|
+
|
21
|
+
rotate theta
|
22
|
+
rect 0, 0, 100, 100
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
RotateRectangleAroundCenterSketch.new :title => "Rotate Rectangle Around Center", :width => 200, :height => 200
|
28
|
+
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'ruby-processing'
|
2
|
+
|
3
|
+
class RotateZSketch < Processing::App
|
4
|
+
|
5
|
+
def setup
|
6
|
+
rect_mode CENTER
|
7
|
+
render_mode P3D
|
8
|
+
@theta = 0
|
9
|
+
end
|
10
|
+
|
11
|
+
def draw
|
12
|
+
background 255
|
13
|
+
stroke 0
|
14
|
+
fill 175
|
15
|
+
|
16
|
+
translate width/2, height/2
|
17
|
+
rotate_z @theta
|
18
|
+
rect 0, 0, 100, 100
|
19
|
+
@theta += 0.02
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
RotateZSketch.new :title => "Rotate Z", :width => 200, :height => 200
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'ruby-processing'
|
2
|
+
|
3
|
+
class RotateXSketch < Processing::App
|
4
|
+
|
5
|
+
def setup
|
6
|
+
render_mode P3D
|
7
|
+
rect_mode CENTER
|
8
|
+
@theta = 0
|
9
|
+
end
|
10
|
+
|
11
|
+
def draw
|
12
|
+
background 255
|
13
|
+
stroke 0
|
14
|
+
fill 175
|
15
|
+
|
16
|
+
translate width/2, height/2
|
17
|
+
rotate_x @theta
|
18
|
+
rect 0, 0, 100, 100
|
19
|
+
@theta += 0.02
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
RotateXSketch.new :title => "Rotate X", :width => 200, :height => 200
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'ruby-processing'
|
2
|
+
|
3
|
+
class RotateYSketch < Processing::App
|
4
|
+
|
5
|
+
def setup
|
6
|
+
render_mode P3D
|
7
|
+
rect_mode CENTER
|
8
|
+
@theta = 0
|
9
|
+
end
|
10
|
+
|
11
|
+
def draw
|
12
|
+
background 255
|
13
|
+
stroke 0
|
14
|
+
fill 175
|
15
|
+
|
16
|
+
translate width/2, height/2
|
17
|
+
rotate_y @theta
|
18
|
+
rect 0, 0, 100, 100
|
19
|
+
@theta += 0.02
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
RotateYSketch.new :title => "Rotate Y", :width => 200, :height => 200
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'ruby-processing'
|
2
|
+
|
3
|
+
class RotateAllSketch < Processing::App
|
4
|
+
|
5
|
+
def setup
|
6
|
+
render_mode P3D
|
7
|
+
rect_mode CENTER
|
8
|
+
end
|
9
|
+
|
10
|
+
def draw
|
11
|
+
background 255
|
12
|
+
stroke 0
|
13
|
+
fill 175
|
14
|
+
|
15
|
+
translate width/2, height/2
|
16
|
+
rotate_x PI * mouse_x / height
|
17
|
+
rotate_y PI * mouse_x / height
|
18
|
+
rect 0, 0, 100, 100
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
RotateAllSketch.new :title => "Rotate All", :width => 200, :height => 200
|
24
|
+
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'ruby-processing'
|
2
|
+
|
3
|
+
class DrawPyramidSketch < Processing::App
|
4
|
+
|
5
|
+
def setup
|
6
|
+
render_mode P3D
|
7
|
+
@theta = 0.0
|
8
|
+
end
|
9
|
+
|
10
|
+
def draw
|
11
|
+
background 255
|
12
|
+
@theta += 0.01
|
13
|
+
|
14
|
+
translate 100, 100, 0
|
15
|
+
rotate_x @theta
|
16
|
+
rotate_y @theta
|
17
|
+
draw_pyramid 50
|
18
|
+
|
19
|
+
# translate the scene again
|
20
|
+
translate 50, 50, 20
|
21
|
+
# call the pyramid drawing function
|
22
|
+
draw_pyramid 10
|
23
|
+
end
|
24
|
+
|
25
|
+
def draw_pyramid(t)
|
26
|
+
stroke 0
|
27
|
+
|
28
|
+
# this pyramid has 4 sides, each drawn as a separate triangle
|
29
|
+
# each side has 3 vertices, making up a triangle shape
|
30
|
+
# the parameter "t" determines the size of the pyramid
|
31
|
+
begin_shape TRIANGLES
|
32
|
+
|
33
|
+
fill 150, 0, 0, 127
|
34
|
+
vertex -t, -t, -t
|
35
|
+
vertex t, -t, -t
|
36
|
+
vertex 0, 0, t
|
37
|
+
|
38
|
+
fill 0, 150, 0, 127
|
39
|
+
vertex t, -t, -t
|
40
|
+
vertex t, t, -t
|
41
|
+
vertex 0, 0, t
|
42
|
+
|
43
|
+
fill 0, 0, 150, 127
|
44
|
+
vertex t, t, -t
|
45
|
+
vertex -t, t, -t
|
46
|
+
vertex 0, 0, t
|
47
|
+
|
48
|
+
fill 150, 0, 150, 127
|
49
|
+
vertex -t, t, -t
|
50
|
+
vertex -t, -t, -t
|
51
|
+
vertex 0, 0, t
|
52
|
+
|
53
|
+
end_shape
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
|
59
|
+
DrawPyramidSketch.new :title => "Draw Pyramid", :width => 200, :height => 200
|