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,64 @@
|
|
1
|
+
# Description:
|
2
|
+
# Flight Patterns is that ol' Euruko 2008 demo.
|
3
|
+
|
4
|
+
require 'ruby-processing'
|
5
|
+
|
6
|
+
class FlightPatterns < Processing::App
|
7
|
+
load_libraries 'boids', 'opengl'
|
8
|
+
include_package "processing.opengl" if library_loaded? "opengl"
|
9
|
+
|
10
|
+
def setup
|
11
|
+
library_loaded?(:opengl) ? setup_opengl : render_mode(P3D)
|
12
|
+
sphere_detail 8
|
13
|
+
color_mode RGB, 1.0
|
14
|
+
no_stroke
|
15
|
+
frame_rate 30
|
16
|
+
shininess 1.0
|
17
|
+
specular 0.3, 0.1, 0.1
|
18
|
+
emissive 0.03, 0.03, 0.1
|
19
|
+
|
20
|
+
@click = false
|
21
|
+
@flocks = []
|
22
|
+
3.times do |i|
|
23
|
+
flock = Boids.flock 20, 0, 0, width, height
|
24
|
+
flock.goal width/2, height/2, 0
|
25
|
+
@flocks << flock
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def setup_opengl
|
30
|
+
render_mode OPENGL
|
31
|
+
hint ENABLE_OPENGL_4X_SMOOTH
|
32
|
+
end
|
33
|
+
|
34
|
+
def mouse_pressed
|
35
|
+
@click = !@click
|
36
|
+
end
|
37
|
+
|
38
|
+
def draw
|
39
|
+
background 0.05
|
40
|
+
ambient_light 0.01, 0.01, 0.01
|
41
|
+
light_specular 0.4, 0.2, 0.2
|
42
|
+
point_light 1.0, 1.0, 1.0, mouse_x, mouse_y, 190
|
43
|
+
@flocks.each_with_index do |flock, i|
|
44
|
+
flock.goal mouse_x, mouse_y, 0, @flee
|
45
|
+
flock.update(:goal => 185, :limit => 13.5)
|
46
|
+
for boid in flock do
|
47
|
+
r = 20 + (boid.z * 0.15)
|
48
|
+
alpha = 0.5 + (boid.z * 0.01)
|
49
|
+
case i
|
50
|
+
when 0 then fill 0.55, 0.35, 0.35
|
51
|
+
when 1 then fill 0.35, 0.55, 0.35
|
52
|
+
when 2 then fill 0.35, 0.35, 0.55
|
53
|
+
end
|
54
|
+
push_matrix
|
55
|
+
translate boid.x-r/2, boid.y-r/2, boid.z-r/2
|
56
|
+
@click ? sphere(r/2) : oval(0, 0, r, r)
|
57
|
+
pop_matrix
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
FlightPatterns.new(:title => "Flight Patterns", :width => 1100, :height => 800, :full_screen => true)
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# Description:
|
2
|
+
# This full-screen demo can demonstrate the kinds of speedups
|
3
|
+
# that are possible with OpenGL-accelerated rendering. If you
|
4
|
+
# have the OpenGL library installed, you'll get *much*
|
5
|
+
# smoother and faster drawing.
|
6
|
+
|
7
|
+
require 'ruby-processing'
|
8
|
+
|
9
|
+
class FullScreen < Processing::App
|
10
|
+
load_library :opengl
|
11
|
+
|
12
|
+
def setup
|
13
|
+
library_loaded?(:opengl) ? render_mode(OPENGL) : render_mode(P3D)
|
14
|
+
no_stroke
|
15
|
+
end
|
16
|
+
|
17
|
+
def draw
|
18
|
+
lights
|
19
|
+
background 0
|
20
|
+
fill 120, 160, 220
|
21
|
+
(width/100).times do |x|
|
22
|
+
(height/100).times do |y|
|
23
|
+
new_x, new_y = x * 100, y * 100
|
24
|
+
push_matrix
|
25
|
+
translate new_x + 50, new_y + 50
|
26
|
+
rotate_y(((mouse_x.to_f + new_x) / width) * Math::PI)
|
27
|
+
rotate_x(((mouse_y.to_f + new_y) / height) * Math::PI)
|
28
|
+
box 90
|
29
|
+
pop_matrix
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
FullScreen.new(:full_screen => true, :title => "Full Screen", :width => 600, :height => 600)
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# So, let's get started: The first thing you may notice is
|
2
|
+
# that there is a bunch more code around the edges here
|
3
|
+
# than in vanilla Processing sketches. Ruby-Processing
|
4
|
+
# doesn't perform any special code munging or pre-processing,
|
5
|
+
# so what you see here is *just Ruby* taking advantage
|
6
|
+
# of the Processing library.
|
7
|
+
|
8
|
+
# Hence, this line, which loads in Processing.
|
9
|
+
require 'ruby-processing'
|
10
|
+
|
11
|
+
# Here we begin to define the Sketch by making it a
|
12
|
+
# Processing App.
|
13
|
+
class SampleApplication < Processing::App
|
14
|
+
|
15
|
+
# Now we define a setup method, for code that gets
|
16
|
+
# run one time when the app is started.
|
17
|
+
def setup
|
18
|
+
background 0
|
19
|
+
no_stroke
|
20
|
+
smooth
|
21
|
+
@rotation = 0
|
22
|
+
end
|
23
|
+
|
24
|
+
# And the draw method which will be called repeatedly.
|
25
|
+
# Delete this if you don't need animation.
|
26
|
+
def draw
|
27
|
+
fill 0, 20
|
28
|
+
rect 0, 0, width, height
|
29
|
+
|
30
|
+
translate width/2, height/2
|
31
|
+
rotate @rotation
|
32
|
+
|
33
|
+
fill 255
|
34
|
+
ellipse 0, -60, 20, 20
|
35
|
+
|
36
|
+
@rotation += 0.1
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
# Now that the sketch is defined, we can start one up.
|
42
|
+
# The following line does this, passing in the title, width, and height.
|
43
|
+
SampleApplication.new(:width => 200, :height => 200, :title => "SampleApplication")
|
data/samples/jwishy.rb
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
# This one has a long lineage:
|
2
|
+
# It was originally adapted to Shoes in Ruby,
|
3
|
+
# from a Python example for Nodebox, and then, now
|
4
|
+
# to Ruby-Processing.
|
5
|
+
|
6
|
+
# For fun, try running it via jirb, and
|
7
|
+
# playing with the attr_accessors, as
|
8
|
+
# well as the background.
|
9
|
+
|
10
|
+
# This example now demonstrates the use of the control_panel.
|
11
|
+
|
12
|
+
# -- omygawshkenas
|
13
|
+
|
14
|
+
require 'ruby-processing'
|
15
|
+
|
16
|
+
class Sketch < Processing::App
|
17
|
+
load_libraries :control_panel, :net
|
18
|
+
|
19
|
+
attr_accessor :x_wiggle, :y_wiggle, :magnitude, :bluish
|
20
|
+
|
21
|
+
def setup
|
22
|
+
control_panel do |c|
|
23
|
+
c.slider :bluish, 0.0..1.0
|
24
|
+
c.slider :alpha, 0.0..1.0
|
25
|
+
c.checkbox :go_big
|
26
|
+
c.button :reset
|
27
|
+
end
|
28
|
+
|
29
|
+
@x_wiggle, @y_wiggle = 10.0, 0
|
30
|
+
@magnitude = 8.15
|
31
|
+
@bluish = 0.9
|
32
|
+
@background = [0.06, 0.03, 0.18]
|
33
|
+
@alpha = 1.0
|
34
|
+
color_mode RGB, 1
|
35
|
+
smooth
|
36
|
+
end
|
37
|
+
|
38
|
+
def background=(*args)
|
39
|
+
@background = args.flatten
|
40
|
+
end
|
41
|
+
|
42
|
+
def draw_background
|
43
|
+
@background[3] = @alpha
|
44
|
+
fill *@background if @background[0]
|
45
|
+
rect 0, 0, width, height
|
46
|
+
end
|
47
|
+
|
48
|
+
def reset
|
49
|
+
@y_wiggle = 0
|
50
|
+
end
|
51
|
+
|
52
|
+
def draw
|
53
|
+
draw_background
|
54
|
+
|
55
|
+
# Seed the random numbers for consistent placement from frame to frame
|
56
|
+
srand(0)
|
57
|
+
horiz, vert, mag = @x_wiggle, @y_wiggle, @magnitude
|
58
|
+
|
59
|
+
if @go_big
|
60
|
+
mag *= 2
|
61
|
+
vert /= 2
|
62
|
+
end
|
63
|
+
|
64
|
+
blu = bluish
|
65
|
+
x, y = (self.width / 2), -27
|
66
|
+
c = 0.0
|
67
|
+
|
68
|
+
64.times do |i|
|
69
|
+
x += cos(horiz)*mag
|
70
|
+
y += log10(vert)*mag + sin(vert) * 2
|
71
|
+
fill(sin(@y_wiggle + c), rand * 0.2, rand * blu, 0.5)
|
72
|
+
s = 42 + cos(vert) * 17
|
73
|
+
oval(x-s/2, y-s/2, s, s)
|
74
|
+
vert += rand * 0.25
|
75
|
+
horiz += rand * 0.25
|
76
|
+
c += 0.1
|
77
|
+
end
|
78
|
+
|
79
|
+
@x_wiggle += 0.05
|
80
|
+
@y_wiggle += 0.1
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
# Try setting full screen to true.
|
85
|
+
Sketch.new(:width => 600, :height => 600, :title => "WishyWorm", :full_screen => false)
|
@@ -0,0 +1,100 @@
|
|
1
|
+
# From the Processing Examples
|
2
|
+
# by Zach Lieberman
|
3
|
+
# Ruby version thanks to Nick Sieger
|
4
|
+
|
5
|
+
require 'ruby-processing'
|
6
|
+
|
7
|
+
class KineticType < Processing::App
|
8
|
+
load_library :opengl
|
9
|
+
|
10
|
+
WORDS = ["sometimes it's like", "the lines of text", "are so happy", "that they want to dance",
|
11
|
+
"or leave the page or jump", "can you blame them?", "living on the page like that",
|
12
|
+
"waiting to be read..."]
|
13
|
+
|
14
|
+
def setup
|
15
|
+
library_loaded?(:opengl) ? render_mode(OPENGL) : render_mode(P3D)
|
16
|
+
|
17
|
+
frame_rate 30
|
18
|
+
|
19
|
+
# Array of line objects
|
20
|
+
@lns = [];
|
21
|
+
|
22
|
+
# Try to create the font from scratch.
|
23
|
+
hint(ENABLE_NATIVE_FONTS)
|
24
|
+
f = create_font("Monospaced", 66)
|
25
|
+
text_font f, 1.0
|
26
|
+
|
27
|
+
# White type, black background
|
28
|
+
fill 255
|
29
|
+
|
30
|
+
# Creating the line objects
|
31
|
+
i = -1
|
32
|
+
@lines = WORDS.map do |ln|
|
33
|
+
i += 1
|
34
|
+
Line.new self, ln, 0, i * 70, f
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def draw
|
39
|
+
background 0
|
40
|
+
|
41
|
+
translate (width / 2.0) - 350, (height / 2.0) - 240, -450
|
42
|
+
rotateY 0.3
|
43
|
+
|
44
|
+
# Now animate every line object & draw it...
|
45
|
+
@lines.each_with_index do |line,i|
|
46
|
+
f1 = sin((i + 1.0) * (millis() / 10000.0) * TWO_PI)
|
47
|
+
f2 = sin((8.0 - i) * (millis() / 10000.0) * TWO_PI)
|
48
|
+
push_matrix
|
49
|
+
translate 0.0, line.ypos, 0.0
|
50
|
+
0.upto(line.letters.length - 1) do |j|
|
51
|
+
if j != 0
|
52
|
+
translate(text_width(line.letters[j - 1].char)*75, 0.0, 0.0)
|
53
|
+
end
|
54
|
+
rotate_y(f1 * 0.035 * f2)
|
55
|
+
push_matrix
|
56
|
+
scale(75.0, 75.0, 75.0)
|
57
|
+
text(line.letters[j].char, 0.0, 0.0)
|
58
|
+
pop_matrix
|
59
|
+
end
|
60
|
+
pop_matrix
|
61
|
+
end
|
62
|
+
rescue => e
|
63
|
+
puts e.to_s, *e.backtrace
|
64
|
+
raise e
|
65
|
+
end
|
66
|
+
|
67
|
+
# Any class inheriting from this app object
|
68
|
+
# can use all the plain Processing calls.
|
69
|
+
class AppObject
|
70
|
+
attr_accessor :app
|
71
|
+
def method_missing(meth, *args, &block)
|
72
|
+
app.send(meth, *args, &block)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
class Line < AppObject
|
77
|
+
attr_accessor :string, :xpos, :ypos, :highlight_num,
|
78
|
+
:font, :speed, :curl_in_x, :letters
|
79
|
+
|
80
|
+
def initialize(app, s, i, j, bagelfont)
|
81
|
+
@app, @string, @xpos, @ypos, @font = app, s, i, j, bagelfont
|
82
|
+
@letters = []
|
83
|
+
f1 = 0.0
|
84
|
+
s.each_byte do |c|
|
85
|
+
f1 += text_width c
|
86
|
+
@letters << Letter.new(c, f1, 0.0)
|
87
|
+
end
|
88
|
+
@curl_in_x = 0.1
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
class Letter
|
93
|
+
attr_accessor :char, :x, :y
|
94
|
+
def initialize(c, x, y)
|
95
|
+
@char, @x, @y = c, x, y
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
KineticType.new :width => 200, :height => 200, :title => "Kinetic Type"
|
@@ -0,0 +1,11 @@
|
|
1
|
+
"Learning Processing" is a 2008 book that serves as a gentle
|
2
|
+
introduction to the theory and practice of programming. It
|
3
|
+
works by introducing code concepts over the course of 23
|
4
|
+
chapters, and creating a series of examples that build on
|
5
|
+
the sketches that you write over the course of the book.
|
6
|
+
|
7
|
+
"Learning Processing" is written by Daniel Shiffman of the
|
8
|
+
ITP in New York City.
|
9
|
+
|
10
|
+
More information about the book can be found at:
|
11
|
+
http://www.learningprocessing.com/
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# So, let's get started: The first thing you may notice is
|
2
|
+
# that there is a bunch more code around the edges here
|
3
|
+
# than in the Learning Processing example. Ruby-Processing
|
4
|
+
# doesn't perform any special munging or pre-processing,
|
5
|
+
# so what you see here is *just Ruby* taking advantage
|
6
|
+
# of the Processing library.
|
7
|
+
|
8
|
+
# Hence, this line, which loads in Processing.
|
9
|
+
require 'ruby-processing'
|
10
|
+
|
11
|
+
# Here we begin to define the Sketch by making it a
|
12
|
+
# Processing App.
|
13
|
+
class StrokeAndFill < Processing::App
|
14
|
+
|
15
|
+
# Now we define a setup method, for code that gets
|
16
|
+
# run one time when the app is started.
|
17
|
+
def setup
|
18
|
+
background 255
|
19
|
+
stroke 0
|
20
|
+
fill 150
|
21
|
+
rect 50, 50, 75, 100
|
22
|
+
end
|
23
|
+
|
24
|
+
# And the draw method has nothing inside of it.
|
25
|
+
# If it did, the code inside would be run repeatedly.
|
26
|
+
def draw
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
# Now that the sketch is defined, we can start one up.
|
33
|
+
# The following line does this, passing in the title, width, and height.
|
34
|
+
StrokeAndFill.new :title => "Stroke And Fill", :width => 200, :height => 200
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'ruby-processing'
|
2
|
+
|
3
|
+
class NofillApp < Processing::App
|
4
|
+
|
5
|
+
def setup
|
6
|
+
smooth
|
7
|
+
background 255
|
8
|
+
# In Ruby, methods and variables are under_scored instead of camelCased
|
9
|
+
no_fill
|
10
|
+
stroke 0
|
11
|
+
# You might notice that there are no parenthesis or semicolons.
|
12
|
+
# That's because they're optional.
|
13
|
+
ellipse 60, 60, 100, 100
|
14
|
+
# This line works too:
|
15
|
+
ellipse(60, 60, 100, 100);
|
16
|
+
end
|
17
|
+
|
18
|
+
def draw
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
# The names of classes are still camel cased.
|
25
|
+
NofillApp.new :title => "Nofill", :width => 200, :height => 200
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'ruby-processing'
|
2
|
+
|
3
|
+
# RGB color is specified by intensity of red, then green, then blue.
|
4
|
+
class RgbColor < Processing::App
|
5
|
+
|
6
|
+
def setup
|
7
|
+
smooth
|
8
|
+
|
9
|
+
background 255
|
10
|
+
no_stroke
|
11
|
+
|
12
|
+
# Bright red
|
13
|
+
fill 255, 0, 0
|
14
|
+
ellipse 20, 20, 16, 16
|
15
|
+
|
16
|
+
# Dark red
|
17
|
+
fill 127, 0, 0
|
18
|
+
ellipse 40, 20, 16, 16
|
19
|
+
|
20
|
+
# Pink
|
21
|
+
fill 255, 200, 200
|
22
|
+
ellipse 60, 20, 16, 16
|
23
|
+
end
|
24
|
+
|
25
|
+
def draw
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
RgbColor.new :title => "Rgb Color", :width => 200, :height => 200
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'ruby-processing'
|
2
|
+
|
3
|
+
class AlphaTransparency < Processing::App
|
4
|
+
|
5
|
+
def setup
|
6
|
+
background 0
|
7
|
+
no_stroke
|
8
|
+
|
9
|
+
# No fourth argument means 100% opacity
|
10
|
+
fill 0, 0, 255
|
11
|
+
rect 0, 0, 100, 200
|
12
|
+
|
13
|
+
# 255 means 100% opacity
|
14
|
+
fill 255, 0, 0, 255
|
15
|
+
rect 0, 0, 200, 40
|
16
|
+
|
17
|
+
# 75% opacity
|
18
|
+
fill 255, 0, 0, 191
|
19
|
+
rect 0, 50, 200, 40
|
20
|
+
|
21
|
+
# 55% opacity
|
22
|
+
fill 200, 0, 0, 127
|
23
|
+
rect 0, 100, 200, 40
|
24
|
+
|
25
|
+
# 25% opacity
|
26
|
+
fill 255, 0, 0, 63
|
27
|
+
rect 0, 150, 200, 40
|
28
|
+
end
|
29
|
+
|
30
|
+
def draw
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
AlphaTransparency.new :title => "Alpha Transparency", :width => 200, :height => 200
|