ruby-processing 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +6 -0
- data/lib/ruby-processing.rb +1 -1
- data/lib/ruby-processing/app.rb +10 -2
- data/lib/ruby-processing/exporters/base_exporter.rb +2 -2
- data/lib/ruby-processing/runner.rb +11 -2
- data/lib/ruby-processing/runners/run.rb +6 -1
- data/samples/processing_app/3D/camera/ortho_vs_perspective.rb +46 -0
- data/samples/processing_app/3D/camera/perspective.rb +44 -0
- data/samples/processing_app/3D/form/brick_tower.rb +94 -0
- data/samples/processing_app/3D/typography/data/Univers66.vlw.gz +0 -0
- data/samples/processing_app/3D/typography/kinetic_type.rb +79 -0
- data/samples/processing_app/ABOUT +3 -0
- data/samples/processing_app/topics/effects/data/red_smoke.jpg +0 -0
- data/samples/processing_app/topics/effects/lens.rb +95 -0
- metadata +19 -3
- data/samples/kinetic_type.rb +0 -100
data/CHANGELOG
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
v1.0.2 Bugfixes and Java Args...
|
2
|
+
* Application exporting, long plagued, should now be a little
|
3
|
+
closer to rock-solid. If you need to pass command-line options
|
4
|
+
to the JVM, add a java_args.txt file in your sketch's data
|
5
|
+
folder that sets stack size, memory size, or whatever ails you.
|
6
|
+
|
1
7
|
v1.0.1 Gemmin' it up.
|
2
8
|
* The smallest version bump is the biggest change:
|
3
9
|
Ruby-Processing has undergone a great refactor, kicked off by
|
data/lib/ruby-processing.rb
CHANGED
data/lib/ruby-processing/app.rb
CHANGED
@@ -22,6 +22,11 @@ module Processing
|
|
22
22
|
|
23
23
|
include_class "javax.swing.JFrame"
|
24
24
|
|
25
|
+
# Include some processing classes that we'd like to use:
|
26
|
+
%w(PShape PImage PGraphics PFont PVector).each do |klass|
|
27
|
+
include_class "processing.core.#{klass}"
|
28
|
+
end
|
29
|
+
|
25
30
|
# Alias some methods for familiarity for Shoes coders.
|
26
31
|
attr_accessor :frame, :title
|
27
32
|
alias_method :oval, :ellipse
|
@@ -52,7 +57,7 @@ module Processing
|
|
52
57
|
|
53
58
|
# Class methods that we should make available in the instance.
|
54
59
|
[:map, :pow, :norm, :lerp, :second, :minute, :hour, :day, :month, :year,
|
55
|
-
:sq, :constrain, :dist, :blend_color].each do |meth|
|
60
|
+
:sq, :constrain, :dist, :blend_color, :degrees, :radians, :mag].each do |meth|
|
56
61
|
method = <<-EOS
|
57
62
|
def #{meth}(*args)
|
58
63
|
self.class.#{meth}(*args)
|
@@ -91,6 +96,7 @@ module Processing
|
|
91
96
|
end
|
92
97
|
def self.load_library(*args); self.load_libraries(*args); end
|
93
98
|
|
99
|
+
|
94
100
|
# For pure ruby libraries.
|
95
101
|
# The library should have an initialization ruby file
|
96
102
|
# of the same name as the library folder.
|
@@ -184,7 +190,9 @@ module Processing
|
|
184
190
|
# If you'd like to do something fancy, feel free.
|
185
191
|
def set_sketch_path(path=nil)
|
186
192
|
field = self.java_class.declared_field('sketchPath')
|
187
|
-
|
193
|
+
local = File.dirname(SKETCH_PATH)
|
194
|
+
default = $__windows_app_mode__ ? "#{local}/lib" : local
|
195
|
+
field.set_value(Java.ruby_to_java(self), path || default)
|
188
196
|
end
|
189
197
|
|
190
198
|
|
@@ -63,9 +63,9 @@ module Processing
|
|
63
63
|
libs = []
|
64
64
|
code = source.dup
|
65
65
|
loop do
|
66
|
-
matchdata = code.match(/
|
66
|
+
matchdata = code.match(/load\w+librar(y|ies).+?["':](\S+?)["'\s]/)
|
67
67
|
break unless matchdata
|
68
|
-
match = matchdata[
|
68
|
+
match = matchdata[2]
|
69
69
|
@opengl = true if match.match(/opengl/i)
|
70
70
|
local_path = "#{local_dir}/library/#{match}"
|
71
71
|
rp5_path = "#{RP5_ROOT}/library/#{match}"
|
@@ -117,13 +117,22 @@ module Processing
|
|
117
117
|
|
118
118
|
# Trade in this Ruby instance for a JRuby instance, loading in a
|
119
119
|
# starter script and passing it some arguments.
|
120
|
-
def spin_up(starter_script,
|
120
|
+
def spin_up(starter_script, sketch)
|
121
121
|
runner = "#{RP5_ROOT}/lib/ruby-processing/runners/#{starter_script}"
|
122
|
-
|
122
|
+
java_args = discover_java_args(sketch)
|
123
|
+
command = "java #{java_args} -cp #{jruby_complete} #{dock_icon} org.jruby.Main #{runner} #{sketch}"
|
123
124
|
exec(command)
|
124
125
|
# exec replaces the Ruby process with the JRuby one.
|
125
126
|
end
|
126
127
|
|
128
|
+
# If you need to pass in arguments to Java, such as the ones on this page:
|
129
|
+
# http://java.sun.com/j2se/1.4.2/docs/tooldocs/windows/java.html
|
130
|
+
# then type them into a java_args.txt in your data directory next to your sketch.
|
131
|
+
def discover_java_args(sketch)
|
132
|
+
arg_file = "#{File.dirname(sketch)}/data/java_args.txt"
|
133
|
+
File.exists?(arg_file) ? File.read(arg_file).gsub("\n", " ") : ''
|
134
|
+
end
|
135
|
+
|
127
136
|
def ensure_exists(sketch)
|
128
137
|
puts "Couldn't find: #{sketch}" and exit unless File.exists?(sketch)
|
129
138
|
end
|
@@ -1,5 +1,10 @@
|
|
1
1
|
# Windows apps start life in the wrong folder.
|
2
|
-
|
2
|
+
# TODO: Fix this crud as soon as possible.
|
3
|
+
if ARGV[1] == '--windows-app'
|
4
|
+
ARGV[1] = nil
|
5
|
+
Dir.chdir('lib')
|
6
|
+
$__windows_app_mode__ = true
|
7
|
+
end
|
3
8
|
|
4
9
|
require "#{File.dirname(__FILE__)}/base.rb"
|
5
10
|
require Processing::SKETCH_PATH
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'ruby-processing'
|
2
|
+
|
3
|
+
# Click to see the difference between orthographic projection
|
4
|
+
# and perspective projection as applied to a simple box.
|
5
|
+
# The ortho function sets an orthographic projection and
|
6
|
+
# defines a parallel clipping volume. All objects with the
|
7
|
+
# same dimension appear the same size, regardless of whether
|
8
|
+
# they are near or far from the camera. The parameters to this
|
9
|
+
# function specify the clipping volume where left and right
|
10
|
+
# are the minimum and maximum x values, top and bottom are the
|
11
|
+
# minimum and maximum y values, and near and far are the minimum
|
12
|
+
# and maximum z values.
|
13
|
+
|
14
|
+
class OrthoVsPerspective < Processing::App
|
15
|
+
|
16
|
+
def setup
|
17
|
+
render_mode P3D
|
18
|
+
no_stroke
|
19
|
+
fill 204
|
20
|
+
end
|
21
|
+
|
22
|
+
def draw
|
23
|
+
background 0
|
24
|
+
lights
|
25
|
+
|
26
|
+
mouse_pressed? ? show_perspective : show_orthographic
|
27
|
+
|
28
|
+
translate width/2, height/2, 0
|
29
|
+
rotate_x -PI/6
|
30
|
+
rotate_y PI/3
|
31
|
+
box 160
|
32
|
+
end
|
33
|
+
|
34
|
+
def show_perspective
|
35
|
+
fov = PI/3.0
|
36
|
+
camera_z = (height/2.0) / tan(PI * fov / 360.0)
|
37
|
+
perspective fov, width.to_f/height.to_f, camera_z/2.0, camera_z*2.0
|
38
|
+
end
|
39
|
+
|
40
|
+
def show_orthographic
|
41
|
+
ortho -width/2, width/2, -height/2, height/2, -10, 10
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
OrthoVsPerspective.new :title => "Ortho Vs Perspective", :width => 640, :height => 360
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'ruby-processing'
|
2
|
+
|
3
|
+
# Move the mouse left and right to change the field of view (fov).
|
4
|
+
# Click to modify the aspect ratio. The perspective method
|
5
|
+
# sets a perspective projection applying foreshortening, making
|
6
|
+
# distant objects appear smaller than closer ones. The parameters
|
7
|
+
# define a viewing volume with the shape of truncated pyramid.
|
8
|
+
# Objects near to the front of the volume appear their actual size,
|
9
|
+
# while farther objects appear smaller. This projection simulates
|
10
|
+
# the perspective of the world more accurately than orthographic projection.
|
11
|
+
# The version of perspective without parameters sets the default
|
12
|
+
# perspective and the version with four parameters allows the programmer
|
13
|
+
# to set the area precisely.
|
14
|
+
|
15
|
+
class Perspective < Processing::App
|
16
|
+
|
17
|
+
def setup
|
18
|
+
render_mode P3D
|
19
|
+
no_stroke
|
20
|
+
end
|
21
|
+
|
22
|
+
def draw
|
23
|
+
lights
|
24
|
+
background 204
|
25
|
+
camera_y = height/2.0
|
26
|
+
fov = mouse_x/width.to_f * PI/2.0
|
27
|
+
camera_z = camera_y / tan(fov / 2.0)
|
28
|
+
aspect = width.to_f / height.to_f
|
29
|
+
|
30
|
+
aspect /= 2.0 if mouse_pressed?
|
31
|
+
|
32
|
+
perspective(fov, aspect, camera_z/10.0, camera_z*10.0)
|
33
|
+
|
34
|
+
translate width/2.0+30, height/2.0, 0
|
35
|
+
rotate_x -PI/6
|
36
|
+
rotate_y PI/3 + mouse_y/height.to_f * PI
|
37
|
+
box 45
|
38
|
+
translate 0, 0, -50
|
39
|
+
box 30
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
Perspective.new :title => "Perspective", :width => 640, :height => 360
|
@@ -0,0 +1,94 @@
|
|
1
|
+
require 'ruby-processing'
|
2
|
+
|
3
|
+
# Original by Ira Greenberg
|
4
|
+
|
5
|
+
# 3D castle tower constructed out of individual bricks.
|
6
|
+
# Uses the PVecor and Cube classes.
|
7
|
+
|
8
|
+
class BrickTower < Processing::App
|
9
|
+
|
10
|
+
def setup
|
11
|
+
@bricks_per_layer = 16
|
12
|
+
@brick_layers = 18
|
13
|
+
@brick_width, @brick_height, @brick_depth = 60, 25, 25
|
14
|
+
@radius = 175.0
|
15
|
+
@angle = 0
|
16
|
+
render_mode P3D
|
17
|
+
@brick = Cubeish.new(@brick_width, @brick_height, @brick_depth)
|
18
|
+
end
|
19
|
+
|
20
|
+
def draw
|
21
|
+
background 0
|
22
|
+
@temp_x, @temp_y, @temp_z = 0, 0, 0
|
23
|
+
fill 182, 62, 29
|
24
|
+
no_stroke
|
25
|
+
lights
|
26
|
+
translate(width/2.0, height*1.2, -380) # move viewpoint into position
|
27
|
+
rotate_x(radians(-45)) # tip tower to see inside
|
28
|
+
rotate_y(frame_count * PI/600) # slowly rotate tower
|
29
|
+
@brick_layers.times {|i| draw_layer(i) }
|
30
|
+
end
|
31
|
+
|
32
|
+
def draw_layer(layer_num)
|
33
|
+
@layer_num = layer_num
|
34
|
+
@temp_y -= @brick_height # increment rows
|
35
|
+
@angle = 360.0 / @bricks_per_layer * @layer_num / 2.0 # alternate brick seams
|
36
|
+
@bricks_per_layer.times {|i| draw_bricks(i) }
|
37
|
+
end
|
38
|
+
|
39
|
+
def draw_bricks(brick_num)
|
40
|
+
@brick_num = brick_num
|
41
|
+
@temp_z = cos(radians(@angle)) * @radius
|
42
|
+
@temp_x = sin(radians(@angle)) * @radius
|
43
|
+
push_matrix
|
44
|
+
translate @temp_x, @temp_y, @temp_z
|
45
|
+
rotate_y(radians(@angle))
|
46
|
+
top_layer = @layer_num == @brick_layers - 1
|
47
|
+
even_brick = @brick_num % 2 == 0
|
48
|
+
@brick.create unless top_layer # main tower
|
49
|
+
@brick.create if top_layer && even_brick # add crenelation
|
50
|
+
pop_matrix
|
51
|
+
@angle += 360.0 / @bricks_per_layer
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
|
56
|
+
# The Cubeish class works a little different than the cube in the
|
57
|
+
# Processing example. SIDES tells you where the negative numbers go.
|
58
|
+
# We dynamically create each of the PVectors by passing in the
|
59
|
+
# appropriate signs.
|
60
|
+
class Cubeish
|
61
|
+
SIDES = {:front => ['-- ', ' - ', ' ', '- '],
|
62
|
+
:left => ['-- ', '---', '- -', '- '],
|
63
|
+
:right => [' - ', ' --', ' -', ' '],
|
64
|
+
:back => ['---', ' --', ' -', '- -'],
|
65
|
+
:top => ['-- ', '---', ' --', ' - '],
|
66
|
+
:bottom => ['- ', '- -', ' -', ' ']}
|
67
|
+
|
68
|
+
SIGNS = {'-' => -1,
|
69
|
+
' ' => 1}
|
70
|
+
|
71
|
+
def initialize(width, height, depth)
|
72
|
+
@vertices = {}
|
73
|
+
@w, @h, @d = width, height, depth
|
74
|
+
|
75
|
+
SIDES.each do |side, signs|
|
76
|
+
@vertices[side] = signs.map do |s|
|
77
|
+
s = s.split('').map {|el| SIGNS[el] }
|
78
|
+
Processing::PVector.new(s[0]*@w/2, s[1]*@h/2, s[2]*@d/2)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def create
|
84
|
+
@vertices.each do |name, vectors|
|
85
|
+
$app.begin_shape BrickTower::QUADS
|
86
|
+
vectors.each {|v| $app.vertex(v.x, v.y, v.z) }
|
87
|
+
$app.end_shape
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
92
|
+
|
93
|
+
|
94
|
+
BrickTower.new :title => "Brick Tower", :width => 640, :height => 360
|
Binary file
|
@@ -0,0 +1,79 @@
|
|
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
|
+
frame_rate 30
|
17
|
+
# Load the font from the sketch's data directory.
|
18
|
+
text_font load_font("Univers66.vlw.gz"), 1.0
|
19
|
+
fill 255
|
20
|
+
|
21
|
+
# Creating the line objects
|
22
|
+
@lines = Array.new(WORDS.length) do |i|
|
23
|
+
Line.new(WORDS[i], 0, i*70)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def draw
|
28
|
+
background 0
|
29
|
+
translate -240, -120, -450
|
30
|
+
rotate_y 0.3
|
31
|
+
# Now animate every line object & draw it...
|
32
|
+
@lines.each_with_index do |line, i|
|
33
|
+
push_matrix
|
34
|
+
translate 0.0, line.ypos, 0.0
|
35
|
+
line.draw(i)
|
36
|
+
pop_matrix
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
class Line
|
42
|
+
include Math
|
43
|
+
attr_accessor :string, :xpos, :ypos, :letters
|
44
|
+
|
45
|
+
def initialize(string, x, y)
|
46
|
+
@string, @xpos, @ypos = string, x, y
|
47
|
+
spacing = 0.0
|
48
|
+
@letters = @string.split('').map do |c|
|
49
|
+
spacing += $app.text_width(c)
|
50
|
+
Letter.new(c, spacing, 0.0)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def compute_curve(line_num)
|
55
|
+
base = $app.millis / 10000.0 * PI * 2
|
56
|
+
sin((line_num + 1.0) * base) * sin((8.0 - line_num) * base)
|
57
|
+
end
|
58
|
+
|
59
|
+
def draw(line_num)
|
60
|
+
curve = compute_curve(line_num)
|
61
|
+
@letters.each_with_index do |letter, i|
|
62
|
+
$app.translate($app.text_width(@letters[i-1].char)*75, 0.0, 0.0) if i > 0
|
63
|
+
$app.rotate_y(curve * 0.035)
|
64
|
+
$app.push_matrix
|
65
|
+
$app.scale(75.0, 75.0, 75.0)
|
66
|
+
$app.text(letter.char, 0.0, 0.0)
|
67
|
+
$app.pop_matrix
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
class Letter
|
73
|
+
attr_accessor :char, :x, :y
|
74
|
+
def initialize(c, x, y)
|
75
|
+
@char, @x, @y = c, x, y
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
KineticType.new :width => 200, :height => 200, :title => "Kinetic Type"
|
Binary file
|
@@ -0,0 +1,95 @@
|
|
1
|
+
require 'ruby-processing'
|
2
|
+
|
3
|
+
# Original by luis2048
|
4
|
+
|
5
|
+
# A picture is shown and it looks like a magnifying glass
|
6
|
+
# is drawn over the picture. One of the most famous demos
|
7
|
+
# that has a lens effect is 2nd reality by future crew.
|
8
|
+
# The trick is to precalculate the entire effect. Just make
|
9
|
+
# an array that for each pixel in the destination picture
|
10
|
+
# tells which pixel to take from the source picture. This
|
11
|
+
# array is called the transformation array. The tricky part
|
12
|
+
# is to calculate the transformation array to make the
|
13
|
+
# destination look like a lens is beeing held over the source
|
14
|
+
# picture. Based on lens formula by on Abe Racadabra.
|
15
|
+
|
16
|
+
class Lens < Processing::App
|
17
|
+
|
18
|
+
def setup
|
19
|
+
@lens_d = 160
|
20
|
+
@lens_list = []
|
21
|
+
@xx, @yy, @dx, @dy = 0, 0, 3, 3
|
22
|
+
|
23
|
+
# Create buffered image for lens effect.
|
24
|
+
@lens_effect = create_graphics(width, height, P2D)
|
25
|
+
|
26
|
+
# Load background image.
|
27
|
+
@lens_effect.begin_draw
|
28
|
+
@lens_effect.image(load_image('red_smoke.jpg'), 0, 0, width, height)
|
29
|
+
@lens_effect.end_draw
|
30
|
+
image(@lens_effect, 0, 0, width, height)
|
31
|
+
|
32
|
+
# Create buffered image for warping.
|
33
|
+
@lens_image = create_graphics(@lens_d, @lens_d, P2D)
|
34
|
+
@lens_image2 = create_graphics(@lens_d, @lens_d, P2D)
|
35
|
+
|
36
|
+
compute_lens_transformation
|
37
|
+
end
|
38
|
+
|
39
|
+
def compute_lens_transformation
|
40
|
+
mag_factor = 40
|
41
|
+
m, a, b = 0, 0, 0
|
42
|
+
r = @lens_d / 2
|
43
|
+
s = sqrt(r*r - mag_factor*mag_factor)
|
44
|
+
|
45
|
+
for y in (-r...r)
|
46
|
+
for x in (-r..r)
|
47
|
+
if (x*x + y*y >= s*s)
|
48
|
+
a, b = x, y
|
49
|
+
else
|
50
|
+
z = sqrt(r*r - x*x - y*y)
|
51
|
+
a = (x * mag_factor / z + 0.5).to_i
|
52
|
+
b = (y * mag_factor / z + 0.5).to_i
|
53
|
+
end
|
54
|
+
@lens_list[(y+r) * @lens_d + (x+r)] = (b+r) * @lens_d + (a+r)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def bounce_lens
|
60
|
+
@dx = -@dx if (@xx+@dx+@lens_d > @lens_effect.width) || (@xx+@dx < 0)
|
61
|
+
@dy = -@dy if (@yy+@dy+@lens_d > @lens_effect.height) || (@yy+@dy < 0)
|
62
|
+
end
|
63
|
+
|
64
|
+
def move_lens
|
65
|
+
@xx += @dx
|
66
|
+
@yy += @dy
|
67
|
+
end
|
68
|
+
|
69
|
+
def draw
|
70
|
+
bounce_lens
|
71
|
+
move_lens
|
72
|
+
|
73
|
+
# Save the background of image at the coordinate where the
|
74
|
+
# lens effect will be applied.
|
75
|
+
@lens_image2.copy(@lens_effect, @xx, @yy, @lens_d, @lens_d, 0, 0, @lens_d, @lens_d)
|
76
|
+
|
77
|
+
# Output into a buffered image for reuse.
|
78
|
+
@lens_image.load_pixels
|
79
|
+
|
80
|
+
# For each pixel in the destination, apply the color from the
|
81
|
+
# appropriate pixel in the saved background. The @lens_list array
|
82
|
+
# tells us the appropriate offset.
|
83
|
+
# This inner loop has been optimized a bit.
|
84
|
+
px, px2 = @lens_image.pixels, @lens_image2.pixels
|
85
|
+
list = @lens_list
|
86
|
+
px.length.times {|i| px[i] = px2[list[i]] }
|
87
|
+
@lens_image.update_pixels
|
88
|
+
|
89
|
+
# Overlay the lens
|
90
|
+
image(@lens_image, @xx, @yy, @lens_d, @lens_d)
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
94
|
+
|
95
|
+
Lens.new :title => "Lens", :width => 640, :height => 360
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-processing
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeremy Ashkenas
|
@@ -12,7 +12,7 @@ autorequire:
|
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
14
|
|
15
|
-
date: 2009-01-
|
15
|
+
date: 2009-01-20 00:00:00 -05:00
|
16
16
|
default_executable: rp5
|
17
17
|
dependencies: []
|
18
18
|
|
@@ -183,7 +183,6 @@ files:
|
|
183
183
|
- samples/full_screen.rb
|
184
184
|
- samples/getting_started.rb
|
185
185
|
- samples/jwishy.rb
|
186
|
-
- samples/kinetic_type.rb
|
187
186
|
- samples/learning_processing
|
188
187
|
- samples/learning_processing/ABOUT
|
189
188
|
- samples/learning_processing/chapter_01
|
@@ -307,6 +306,23 @@ files:
|
|
307
306
|
- samples/learning_processing/chapter_16
|
308
307
|
- samples/learning_processing/chapter_16/01_display_video.rb
|
309
308
|
- samples/learning_processing/chapter_16/02_manipulate_video_image.rb
|
309
|
+
- samples/processing_app
|
310
|
+
- samples/processing_app/3D
|
311
|
+
- samples/processing_app/3D/camera
|
312
|
+
- samples/processing_app/3D/camera/ortho_vs_perspective.rb
|
313
|
+
- samples/processing_app/3D/camera/perspective.rb
|
314
|
+
- samples/processing_app/3D/form
|
315
|
+
- samples/processing_app/3D/form/brick_tower.rb
|
316
|
+
- samples/processing_app/3D/typography
|
317
|
+
- samples/processing_app/3D/typography/data
|
318
|
+
- samples/processing_app/3D/typography/data/Univers66.vlw.gz
|
319
|
+
- samples/processing_app/3D/typography/kinetic_type.rb
|
320
|
+
- samples/processing_app/ABOUT
|
321
|
+
- samples/processing_app/topics
|
322
|
+
- samples/processing_app/topics/effects
|
323
|
+
- samples/processing_app/topics/effects/data
|
324
|
+
- samples/processing_app/topics/effects/data/red_smoke.jpg
|
325
|
+
- samples/processing_app/topics/effects/lens.rb
|
310
326
|
- samples/reflection.rb
|
311
327
|
- samples/simple_buffer.rb
|
312
328
|
- samples/tree.rb
|
data/samples/kinetic_type.rb
DELETED
@@ -1,100 +0,0 @@
|
|
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"
|