ruby-processing 1.0.6 → 1.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +12 -0
- data/lib/core/core.jar +0 -0
- data/lib/core/jruby-complete.jar +0 -0
- data/lib/ruby-processing.rb +12 -1
- data/lib/ruby-processing/app.rb +33 -40
- data/lib/ruby-processing/runner.rb +1 -1
- data/lib/ruby-processing/runners/base.rb +1 -1
- data/lib/ruby-processing/runners/run.rb +4 -8
- data/lib/templates/applet/index.html.erb +0 -1
- data/lib/templates/application/lib/args.txt.erb +1 -1
- data/library/boids/boids.rb +6 -3
- data/library/control_panel/control_panel.rb +1 -1
- data/library/dxf/library/dxf.jar +0 -0
- data/library/net/library/net.jar +0 -0
- data/library/opengl/library/export.txt +0 -0
- data/library/opengl/library/opengl.jar +0 -0
- data/library/pdf/library/pdf.jar +0 -0
- data/library/serial/library/serial.jar +0 -0
- data/library/video/library/video.jar +0 -0
- data/samples/jwishy.rb +1 -1
- data/samples/pong.rb +175 -0
- data/samples/processing_app/topics/simulate/simple_particle_system.rb +44 -46
- metadata +3 -22
- data/library/dxf/bin/processing/dxf/RawDXF.class +0 -0
- data/library/dxf/dxfviewer.jar +0 -0
- data/library/net/bin/processing/net/Client.class +0 -0
- data/library/net/bin/processing/net/Server.class +0 -0
- data/library/serial/bin/processing/serial/Serial.class +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/CHANGELOG
CHANGED
@@ -1,3 +1,15 @@
|
|
1
|
+
v1.0.7 Stability...
|
2
|
+
* Added preliminary support for embedding Ruby-Processing in the Processing
|
3
|
+
IDE (see the ruby-processing-plugin project).
|
4
|
+
* Added 'width' and 'height' as methods that should get proxied down
|
5
|
+
to inner classes and classes that include the Processing::Proxy.
|
6
|
+
* Fixed a padding bug that put tiny gray margins on Windows and Linux.
|
7
|
+
* Updated JRuby to 1.2.0 final as well as the Processing libraries.
|
8
|
+
* Got a little bit better at detecting full-screen support on Linux.
|
9
|
+
* Fixed some applet and app exporting problems on Windows.
|
10
|
+
* The Boids library had a speed limit fix that should make 'em less flighty.
|
11
|
+
* Peter Krenn contributed a simple Pong example.
|
12
|
+
|
1
13
|
v1.0.6 Inner Classes...
|
2
14
|
* Java-style inner classes. Any inner class of a sketch will now have the
|
3
15
|
Processing methods and constants proxied down for convenience.
|
data/lib/core/core.jar
CHANGED
Binary file
|
data/lib/core/jruby-complete.jar
CHANGED
Binary file
|
data/lib/ruby-processing.rb
CHANGED
@@ -14,13 +14,24 @@ require 'ruby-processing/helpers/numeric'
|
|
14
14
|
|
15
15
|
# The top-level namespace, a home for all Ruby-Processing classes.
|
16
16
|
module Processing
|
17
|
-
VERSION = [1,0,
|
17
|
+
VERSION = [1,0,7] unless defined? Processing::VERSION
|
18
18
|
|
19
19
|
# Returns the current version of Ruby-Processing.
|
20
20
|
def self.version
|
21
21
|
VERSION.join('.')
|
22
22
|
end
|
23
23
|
|
24
|
+
# Are we online -- inside an applet?
|
25
|
+
def self.online?
|
26
|
+
@online ||= defined?(JRUBY_APPLET)
|
27
|
+
end
|
28
|
+
|
29
|
+
# Are we embedded -- inside the Processing IDE?
|
30
|
+
def self.embedded?
|
31
|
+
@embedded ||= defined?(RP5_EMBEDDED)
|
32
|
+
end
|
33
|
+
|
34
|
+
# Autoload a number of constants that we may end up using.
|
24
35
|
autoload :App, 'ruby-processing/app'
|
25
36
|
autoload :Runner, 'ruby-processing/runner'
|
26
37
|
autoload :Watcher, 'ruby-processing/runners/watch'
|
data/lib/ruby-processing/app.rb
CHANGED
@@ -4,10 +4,10 @@
|
|
4
4
|
|
5
5
|
require 'java'
|
6
6
|
|
7
|
-
module Processing
|
7
|
+
module Processing
|
8
8
|
|
9
9
|
# Conditionally load core.jar
|
10
|
-
require "#{RP5_ROOT}/lib/core/core.jar" unless
|
10
|
+
require "#{RP5_ROOT}/lib/core/core.jar" unless Processing.online? || Processing.embedded?
|
11
11
|
import "processing.core"
|
12
12
|
|
13
13
|
# This is the main Ruby-Processing class, and is what you'll
|
@@ -79,13 +79,6 @@ module Processing
|
|
79
79
|
super(subclass)
|
80
80
|
@sketch_class = subclass
|
81
81
|
end
|
82
|
-
|
83
|
-
|
84
|
-
# Are we running inside an applet?
|
85
|
-
def self.online?
|
86
|
-
@online ||= Object.const_defined?(:JRUBY_APPLET)
|
87
|
-
end
|
88
|
-
def online?; self.class.online?; end
|
89
82
|
|
90
83
|
|
91
84
|
# Detect if a library has been loaded (for conditional loading)
|
@@ -113,7 +106,7 @@ module Processing
|
|
113
106
|
def self.load_ruby_library(dir)
|
114
107
|
dir = dir.to_sym
|
115
108
|
return true if @@loaded_libraries[dir]
|
116
|
-
if online?
|
109
|
+
if Processing.online?
|
117
110
|
begin
|
118
111
|
return @@loaded_libraries[dir] = (require "library/#{dir}/#{dir}")
|
119
112
|
rescue LoadError => e
|
@@ -137,7 +130,7 @@ module Processing
|
|
137
130
|
def self.load_java_library(dir)
|
138
131
|
dir = dir.to_sym
|
139
132
|
return true if @@loaded_libraries[dir]
|
140
|
-
return @@loaded_libraries[dir] = !!(JRUBY_APPLET.get_parameter("archive").match(%r(#{dir}))) if online?
|
133
|
+
return @@loaded_libraries[dir] = !!(JRUBY_APPLET.get_parameter("archive").match(%r(#{dir}))) if Processing.online?
|
141
134
|
local_path = "#{SKETCH_ROOT}/library/#{dir}"
|
142
135
|
gem_path = "#{RP5_ROOT}/library/#{dir}"
|
143
136
|
path = File.exists?(local_path) ? local_path : gem_path
|
@@ -172,8 +165,8 @@ module Processing
|
|
172
165
|
super()
|
173
166
|
$app = self
|
174
167
|
proxy_java_fields
|
175
|
-
set_sketch_path unless online?
|
176
|
-
make_accessible_to_the_browser if online?
|
168
|
+
set_sketch_path unless Processing.online?
|
169
|
+
# make_accessible_to_the_browser if Processing.online?
|
177
170
|
default_title = File.basename(Processing::SKETCH_PATH).sub(/(\.rb|\.pde)$/, '').titleize
|
178
171
|
@width = options[:width] || DEFAULT_WIDTH
|
179
172
|
@height = options[:height] || DEFAULT_HEIGHT
|
@@ -203,9 +196,7 @@ module Processing
|
|
203
196
|
# If you'd like to do something fancy, feel free.
|
204
197
|
def set_sketch_path(path=nil)
|
205
198
|
field = @declared_fields['sketchPath']
|
206
|
-
|
207
|
-
default = $__windows_app_mode__ ? "#{local}/lib" : local
|
208
|
-
field.set_value(java_self, path || default)
|
199
|
+
field.set_value(java_self, path || SKETCH_ROOT)
|
209
200
|
end
|
210
201
|
|
211
202
|
|
@@ -337,8 +328,8 @@ module Processing
|
|
337
328
|
# Cleanly close and shutter a running sketch.
|
338
329
|
def close
|
339
330
|
$app = nil
|
340
|
-
control_panel.remove if respond_to?(:control_panel) && !online?
|
341
|
-
container = online? ? JRUBY_APPLET : @frame
|
331
|
+
control_panel.remove if respond_to?(:control_panel) && !Processing.online?
|
332
|
+
container = Processing.online? ? JRUBY_APPLET : @frame
|
342
333
|
container.remove(self)
|
343
334
|
self.destroy
|
344
335
|
container.dispose
|
@@ -374,14 +365,13 @@ module Processing
|
|
374
365
|
# Wait for init to get its grey tracksuit on and run a few laps.
|
375
366
|
sleep 0.02 while default_size? && !finished? && !@@full_screen
|
376
367
|
|
377
|
-
if online?
|
368
|
+
if Processing.online?
|
378
369
|
display_in_an_applet
|
379
370
|
elsif full_screen?
|
380
|
-
|
381
|
-
display = java.awt.GraphicsEnvironment.get_local_graphics_environment.get_default_screen_device
|
371
|
+
display = java.awt.GraphicsEnvironment.local_graphics_environment.default_screen_device
|
382
372
|
linux = java.lang.System.get_property("os.name") == "Linux"
|
383
|
-
supported = display.full_screen_supported?
|
384
|
-
supported
|
373
|
+
supported = display.full_screen_supported? || linux
|
374
|
+
supported ? display_full_screen(display) : display_in_a_window
|
385
375
|
else
|
386
376
|
display_in_a_window
|
387
377
|
end
|
@@ -391,8 +381,8 @@ module Processing
|
|
391
381
|
|
392
382
|
def display_full_screen(display)
|
393
383
|
@frame = java.awt.Frame.new(display.default_configuration)
|
394
|
-
|
395
|
-
@width, @height =
|
384
|
+
dimension = java.awt.Toolkit.default_toolkit.screen_size
|
385
|
+
@width, @height = dimension.width, dimension.height
|
396
386
|
@frame.set_undecorated true
|
397
387
|
@frame.set_ignore_repaint true
|
398
388
|
@frame.set_background java.awt.Color.black
|
@@ -411,14 +401,15 @@ module Processing
|
|
411
401
|
@frame.set_layout nil
|
412
402
|
@frame.add self
|
413
403
|
@frame.pack
|
414
|
-
@frame.
|
415
|
-
@frame.
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
404
|
+
@frame.set_resizable false
|
405
|
+
@frame.set_default_close_operation Processing.embedded? ?
|
406
|
+
javax.swing.JFrame::DISPOSE_ON_CLOSE : javax.swing.JFrame::EXIT_ON_CLOSE
|
407
|
+
ins = @frame.get_insets
|
408
|
+
hpad, vpad = ins.left + ins.right, ins.top + ins.bottom
|
409
|
+
frame_width = [width, MIN_WINDOW_WIDTH].max + hpad
|
410
|
+
frame_height = [height, MIN_WINDOW_HEIGHT].max + vpad
|
420
411
|
@frame.set_size(frame_width, frame_height)
|
421
|
-
set_bounds((frame_width - width) / 2.0, (frame_height - vpad - height) / 2.0, width, height)
|
412
|
+
set_bounds((frame_width - hpad - width) / 2.0, (frame_height - vpad - height) / 2.0, width, height)
|
422
413
|
@frame.show
|
423
414
|
end
|
424
415
|
|
@@ -437,14 +428,15 @@ module Processing
|
|
437
428
|
# When the net library is included, we make the Ruby interpreter
|
438
429
|
# accessible to javascript as the 'ruby' variable. From javascript,
|
439
430
|
# you can call evalScriptlet() to run code against the sketch.
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
431
|
+
#
|
432
|
+
# def make_accessible_to_the_browser
|
433
|
+
# return unless library_loaded?('net')
|
434
|
+
# field = java.lang.Class.for_name("org.jruby.JRubyApplet").get_declared_field("runtime")
|
435
|
+
# field.set_accessible true
|
436
|
+
# ruby = field.get(JRUBY_APPLET)
|
437
|
+
# window = Java::netscape.javascript.JSObject.get_window(JRUBY_APPLET)
|
438
|
+
# window.set_member('ruby', ruby)
|
439
|
+
# end
|
448
440
|
|
449
441
|
end # Processing::App
|
450
442
|
|
@@ -459,6 +451,7 @@ module Processing
|
|
459
451
|
def self.desired_method_names
|
460
452
|
bad_method = /__/ # Internal JRuby methods.
|
461
453
|
unwanted = PApplet.superclass.instance_methods + Object.instance_methods
|
454
|
+
unwanted -= ['width', 'height']
|
462
455
|
methods = Processing::App.public_instance_methods
|
463
456
|
methods.reject {|m| unwanted.include?(m) || bad_method.match(m) }
|
464
457
|
end
|
@@ -122,7 +122,7 @@ module Processing
|
|
122
122
|
def spin_up(starter_script, sketch)
|
123
123
|
runner = "#{RP5_ROOT}/lib/ruby-processing/runners/#{starter_script}"
|
124
124
|
java_args = discover_java_args(sketch)
|
125
|
-
command = "java #{java_args} -cp #{jruby_complete} #{dock_icon} org.jruby.Main #{runner} #{sketch}"
|
125
|
+
command = "java #{java_args} -cp \"#{jruby_complete}\" #{dock_icon} org.jruby.Main \"#{runner}\" #{sketch}"
|
126
126
|
exec(command)
|
127
127
|
# exec replaces the Ruby process with the JRuby one.
|
128
128
|
end
|
@@ -45,7 +45,7 @@ module Processing
|
|
45
45
|
|
46
46
|
# Read in the sketch source code. Needs to work both online and offline.
|
47
47
|
def self.read_sketch_source
|
48
|
-
if Processing
|
48
|
+
if Processing.online?
|
49
49
|
# Fuck the following lines. Fucking Java can go sit on broken glass.
|
50
50
|
source = ''
|
51
51
|
url = java.net.URL.new(JRUBY_APPLET.get_code_base, Processing::SKETCH_PATH)
|
@@ -1,11 +1,7 @@
|
|
1
|
-
#
|
2
|
-
#
|
3
|
-
if ARGV[1] == '--windows-app'
|
4
|
-
ARGV[1] = nil
|
5
|
-
Dir.chdir('lib')
|
6
|
-
$__windows_app_mode__ = true
|
7
|
-
end
|
1
|
+
# TODO: this is crud. Windows applets are having serious
|
2
|
+
# trouble with absolute paths.
|
8
3
|
|
9
|
-
|
4
|
+
root = defined?(JRUBY_APPLET) ? 'ruby-processing/runners' : File.dirname(__FILE__)
|
5
|
+
require "#{root}/base.rb"
|
10
6
|
|
11
7
|
Processing.load_and_run_sketch
|
@@ -77,7 +77,6 @@
|
|
77
77
|
<param name="archive" value="<%= @file_list %>" />
|
78
78
|
<param name="jruby.eval" value="ARGV[0] = '<%= @main_file %>'; require 'ruby-processing/runners/run.rb'" />
|
79
79
|
<param name="image" value="images/ruby.jpg" />
|
80
|
-
<param name="centerimage" value="true" />
|
81
80
|
<param name="boxmessage" value="Loading <%= @title %>..." />
|
82
81
|
<param name="lang" value="en" />
|
83
82
|
<param name="mayscript" value="true" />
|
data/library/boids/boids.rb
CHANGED
@@ -55,9 +55,12 @@ class Boid
|
|
55
55
|
|
56
56
|
def limit(max=30.0)
|
57
57
|
# Tweet, Tweet! The boid police will bust you for breaking the speed limit.
|
58
|
-
|
59
|
-
|
60
|
-
|
58
|
+
most = [@vx.abs, @vy.abs, @vz.abs].max
|
59
|
+
return if most < max
|
60
|
+
scale = max / most.to_f
|
61
|
+
@vx *= scale
|
62
|
+
@vy *= scale
|
63
|
+
@vz *= scale
|
61
64
|
end
|
62
65
|
|
63
66
|
def angle
|
@@ -145,7 +145,7 @@ module ControlPanel
|
|
145
145
|
|
146
146
|
module InstanceMethods
|
147
147
|
def control_panel
|
148
|
-
return if Processing
|
148
|
+
return if Processing.online?
|
149
149
|
@control_panel = ControlPanel::Panel.new unless @control_panel
|
150
150
|
return @control_panel unless block_given?
|
151
151
|
yield(@control_panel)
|
data/library/dxf/library/dxf.jar
CHANGED
Binary file
|
data/library/net/library/net.jar
CHANGED
Binary file
|
File without changes
|
Binary file
|
data/library/pdf/library/pdf.jar
CHANGED
Binary file
|
Binary file
|
Binary file
|
data/samples/jwishy.rb
CHANGED
data/samples/pong.rb
ADDED
@@ -0,0 +1,175 @@
|
|
1
|
+
# Simple pong clone to demonstrate keyboard input and basic collision detection
|
2
|
+
# Left paddle is controlled with 'a' and 'z', right with ''' and '/'
|
3
|
+
|
4
|
+
class Sketch < Processing::App
|
5
|
+
def setup
|
6
|
+
smooth
|
7
|
+
ellipse_mode(CENTER)
|
8
|
+
no_fill
|
9
|
+
stroke(255)
|
10
|
+
frame_rate(60)
|
11
|
+
|
12
|
+
@left_paddle = Paddle.new(width / 4, height / 2)
|
13
|
+
@right_paddle = Paddle.new(width / 4 * 3, height / 2)
|
14
|
+
@ball = Ball.new(width / 2, height / 2)
|
15
|
+
end
|
16
|
+
|
17
|
+
def draw
|
18
|
+
background(0)
|
19
|
+
|
20
|
+
paddles.each { |paddle| paddle.update }
|
21
|
+
|
22
|
+
@ball.collide_with_boundaries
|
23
|
+
paddles.each { |paddle| @ball.collide_with_paddle(paddle) }
|
24
|
+
@ball.move
|
25
|
+
|
26
|
+
paddles.each { |paddle| paddle.draw }
|
27
|
+
@ball.draw
|
28
|
+
end
|
29
|
+
|
30
|
+
def paddles
|
31
|
+
return @left_paddle, @right_paddle
|
32
|
+
end
|
33
|
+
|
34
|
+
def key_pressed
|
35
|
+
case key
|
36
|
+
when 'a' then @left_paddle.direction = -1
|
37
|
+
when 'z' then @left_paddle.direction = 1
|
38
|
+
when '\'' then @right_paddle.direction = -1
|
39
|
+
when '/' then @right_paddle.direction = 1
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def key_released
|
44
|
+
case key
|
45
|
+
when 'a', 'z' then @left_paddle.direction = 0
|
46
|
+
when '\'', '/' then @right_paddle.direction = 0
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
class Paddle
|
51
|
+
attr_accessor :position, :radius, :direction
|
52
|
+
|
53
|
+
def initialize(x, y)
|
54
|
+
@position = Vector.new(x, y)
|
55
|
+
@radius = 20
|
56
|
+
@direction = 0
|
57
|
+
@speed = 2
|
58
|
+
end
|
59
|
+
|
60
|
+
def draw
|
61
|
+
stroke_weight(2)
|
62
|
+
ellipse(@position.x, @position.y, @radius * 2, @radius * 2)
|
63
|
+
end
|
64
|
+
|
65
|
+
def update
|
66
|
+
move
|
67
|
+
collide_with_boundaries
|
68
|
+
end
|
69
|
+
|
70
|
+
def move
|
71
|
+
@position.y += @direction * @speed
|
72
|
+
end
|
73
|
+
|
74
|
+
def collide_with_boundaries
|
75
|
+
@position.y = @position.y < @radius ? @radius : @position.y > height - @radius ? height - @radius : @position.y
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
class Ball
|
80
|
+
attr_accessor :position, :velocity, :radius
|
81
|
+
|
82
|
+
def initialize(x, y)
|
83
|
+
@position = Vector.new(x, y)
|
84
|
+
@velocity = Vector.new(2, 0)
|
85
|
+
@radius = 5
|
86
|
+
end
|
87
|
+
|
88
|
+
def draw
|
89
|
+
stroke_weight(1)
|
90
|
+
ellipse(@position.x, @position.y, @radius * 2, @radius * 2)
|
91
|
+
end
|
92
|
+
|
93
|
+
def move
|
94
|
+
@position += @velocity
|
95
|
+
end
|
96
|
+
|
97
|
+
def collide_with_boundaries
|
98
|
+
if position.x <= radius || position.x >= width - radius
|
99
|
+
velocity.x *= -1
|
100
|
+
elsif position.y <= radius || position.y >= height - radius
|
101
|
+
velocity.y *= -1
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
def collide_with_paddle(paddle)
|
106
|
+
# Check for collision
|
107
|
+
distance_vector = position - paddle.position
|
108
|
+
return unless distance_vector.squared_length <= (radius + paddle.radius) ** 2
|
109
|
+
|
110
|
+
# Calculate new velocity
|
111
|
+
normal = distance_vector.normal.normalized
|
112
|
+
@velocity = normal * (velocity * normal) * 2 - velocity
|
113
|
+
|
114
|
+
# Move ball to correct position
|
115
|
+
@position = paddle.position + distance_vector.normalized * (2 * (radius + paddle.radius) - distance_vector.length)
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
class Vector
|
120
|
+
attr_accessor :x, :y
|
121
|
+
|
122
|
+
def initialize(x, y)
|
123
|
+
@x, @y = x, y
|
124
|
+
end
|
125
|
+
|
126
|
+
def +(other)
|
127
|
+
if other.is_a?(Numeric)
|
128
|
+
Vector.new(@x + other, @y + other)
|
129
|
+
elsif other.is_a?(Vector)
|
130
|
+
Vector.new(@x + other.x, @y + other.y)
|
131
|
+
else
|
132
|
+
self
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
def -(other)
|
137
|
+
if other.is_a?(Numeric)
|
138
|
+
Vector.new(@x - other, @y - other)
|
139
|
+
elsif other.is_a?(Vector)
|
140
|
+
Vector.new(@x - other.x, @y - other.y)
|
141
|
+
else
|
142
|
+
self
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
def *(other)
|
147
|
+
if other.is_a?(Numeric)
|
148
|
+
Vector.new(@x * other, @y * other)
|
149
|
+
elsif other.is_a?(Vector)
|
150
|
+
@x * other.x + @y * other.y
|
151
|
+
else
|
152
|
+
self
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
def length
|
157
|
+
Math::sqrt(@x * @x + @y * @y)
|
158
|
+
end
|
159
|
+
|
160
|
+
def squared_length
|
161
|
+
@x * @x + @y * @y
|
162
|
+
end
|
163
|
+
|
164
|
+
def normal
|
165
|
+
Vector.new(-@y, @x)
|
166
|
+
end
|
167
|
+
|
168
|
+
def normalized
|
169
|
+
length = self.length
|
170
|
+
Vector.new(@x / length, @y / length)
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
Sketch.new :width => 800, :height => 400
|
@@ -4,9 +4,40 @@
|
|
4
4
|
# time. A ParticleSystem (Array) object manages a variable size list of
|
5
5
|
# particles.
|
6
6
|
|
7
|
-
|
7
|
+
module Runnable
|
8
|
+
def run
|
9
|
+
self.reject! { |particle| particle.dead? }
|
10
|
+
self.each { |particle| particle.run }
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
class Vector
|
15
|
+
attr_accessor :x, :y
|
16
|
+
|
17
|
+
def initialize(x, y)
|
18
|
+
@x, @y = x, y
|
19
|
+
end
|
20
|
+
|
21
|
+
def +(other)
|
22
|
+
if other.is_a?(Numeric)
|
23
|
+
Vector.new(@x + other, @y + other)
|
24
|
+
elsif other.is_a?(Vector)
|
25
|
+
Vector.new(@x + other.x, @y + other.y)
|
26
|
+
else
|
27
|
+
self
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def heading
|
32
|
+
-1 * Math::atan2(-@y, @x)
|
33
|
+
end
|
8
34
|
|
9
|
-
|
35
|
+
def magnitude
|
36
|
+
@x * @x + @y * @y
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
class Sketch < Processing::App
|
10
41
|
def setup
|
11
42
|
smooth
|
12
43
|
color_mode(RGB, 255, 255, 255, 100)
|
@@ -22,13 +53,6 @@ class SimpleParticleSystem < Processing::App
|
|
22
53
|
@particles << Particle.new(Vector.new(mouse_x, mouse_y))
|
23
54
|
end
|
24
55
|
|
25
|
-
module Runnable
|
26
|
-
def run
|
27
|
-
self.reject! { |particle| particle.dead? }
|
28
|
-
self.each { |particle| particle.run }
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
56
|
class Particle
|
33
57
|
def initialize(origin)
|
34
58
|
@origin = origin
|
@@ -59,55 +83,29 @@ class SimpleParticleSystem < Processing::App
|
|
59
83
|
end
|
60
84
|
|
61
85
|
def render
|
62
|
-
|
63
|
-
|
64
|
-
|
86
|
+
stroke(255, @lifespan)
|
87
|
+
fill(100, @lifespan)
|
88
|
+
ellipse(@origin.x, @origin.y, @radius, @radius)
|
65
89
|
end
|
66
90
|
|
67
91
|
def render_velocity_vector
|
68
92
|
scale = 10
|
69
93
|
arrow_size = 4
|
70
94
|
|
71
|
-
|
95
|
+
push_matrix
|
72
96
|
|
73
|
-
|
74
|
-
|
97
|
+
translate(@origin.x, @origin.y)
|
98
|
+
rotate(@velocity.heading)
|
75
99
|
|
76
100
|
length = @velocity.magnitude * scale
|
77
101
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
$app.pop_matrix
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
class Vector
|
87
|
-
attr_accessor :x, :y
|
88
|
-
|
89
|
-
def initialize(x, y)
|
90
|
-
@x, @y = x, y
|
91
|
-
end
|
92
|
-
|
93
|
-
def +(other)
|
94
|
-
if other.is_a?(Numeric)
|
95
|
-
Vector.new(@x + other, @y + other)
|
96
|
-
elsif other.is_a?(Vector)
|
97
|
-
Vector.new(@x + other.x, @y + other.y)
|
98
|
-
else
|
99
|
-
self
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
def heading
|
104
|
-
-1 * Math::atan2(-@y, @x)
|
105
|
-
end
|
102
|
+
line 0, 0, length, 0
|
103
|
+
line length, 0, length - arrow_size, arrow_size / 2
|
104
|
+
line length, 0, length - arrow_size, -arrow_size / 2
|
106
105
|
|
107
|
-
|
108
|
-
@x * @x + @y * @y
|
106
|
+
pop_matrix
|
109
107
|
end
|
110
108
|
end
|
111
109
|
end
|
112
110
|
|
113
|
-
|
111
|
+
Sketch.new :width => 640, :height => 340
|
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.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeremy Ashkenas
|
@@ -17,7 +17,7 @@ autorequire:
|
|
17
17
|
bindir: bin
|
18
18
|
cert_chain: []
|
19
19
|
|
20
|
-
date: 2009-04-
|
20
|
+
date: 2009-04-22 00:00:00 -04:00
|
21
21
|
default_executable: rp5
|
22
22
|
dependencies: []
|
23
23
|
|
@@ -89,11 +89,6 @@ files:
|
|
89
89
|
- library/control_panel
|
90
90
|
- library/control_panel/control_panel.rb
|
91
91
|
- library/dxf
|
92
|
-
- library/dxf/bin
|
93
|
-
- library/dxf/bin/processing
|
94
|
-
- library/dxf/bin/processing/dxf
|
95
|
-
- library/dxf/bin/processing/dxf/RawDXF.class
|
96
|
-
- library/dxf/dxfviewer.jar
|
97
92
|
- library/dxf/library
|
98
93
|
- library/dxf/library/dxf.jar
|
99
94
|
- library/javascript
|
@@ -112,11 +107,6 @@ files:
|
|
112
107
|
- library/minim/license.txt
|
113
108
|
- library/minim/version.txt
|
114
109
|
- library/net
|
115
|
-
- library/net/bin
|
116
|
-
- library/net/bin/processing
|
117
|
-
- library/net/bin/processing/net
|
118
|
-
- library/net/bin/processing/net/Client.class
|
119
|
-
- library/net/bin/processing/net/Server.class
|
120
110
|
- library/net/library
|
121
111
|
- library/net/library/net.jar
|
122
112
|
- library/opengl
|
@@ -157,10 +147,6 @@ files:
|
|
157
147
|
- library/pdf/library/pdf.jar
|
158
148
|
- library/pdf/notes.txt
|
159
149
|
- library/serial
|
160
|
-
- library/serial/bin
|
161
|
-
- library/serial/bin/processing
|
162
|
-
- library/serial/bin/processing/serial
|
163
|
-
- library/serial/bin/processing/serial/Serial.class
|
164
150
|
- library/serial/library
|
165
151
|
- library/serial/library/export.txt
|
166
152
|
- library/serial/library/librxtxSerial.jnilib
|
@@ -169,12 +155,6 @@ files:
|
|
169
155
|
- library/serial/library/rxtxSerial.dll
|
170
156
|
- library/serial/library/serial.jar
|
171
157
|
- library/video
|
172
|
-
- library/video/bin
|
173
|
-
- library/video/bin/processing
|
174
|
-
- library/video/bin/processing/video
|
175
|
-
- library/video/bin/processing/video/Capture.class
|
176
|
-
- library/video/bin/processing/video/Movie.class
|
177
|
-
- library/video/bin/processing/video/MovieMaker.class
|
178
158
|
- library/video/library
|
179
159
|
- library/video/library/video.jar
|
180
160
|
- samples/animator.rb
|
@@ -186,6 +166,7 @@ files:
|
|
186
166
|
- samples/getting_started.rb
|
187
167
|
- samples/jwishy.rb
|
188
168
|
- samples/orbit.rb
|
169
|
+
- samples/pong.rb
|
189
170
|
- samples/processing_app
|
190
171
|
- samples/processing_app/3D
|
191
172
|
- samples/processing_app/3D/camera
|
Binary file
|
data/library/dxf/dxfviewer.jar
DELETED
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|