ruby-processing 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. data/CHANGELOG +12 -0
  2. data/lib/ruby-processing.rb +2 -1
  3. data/lib/ruby-processing/app.rb +7 -5
  4. data/lib/ruby-processing/exporters/creator.rb +7 -4
  5. data/lib/ruby-processing/helpers/numeric.rb +11 -0
  6. data/lib/ruby-processing/helpers/string.rb +8 -0
  7. data/lib/ruby-processing/runner.rb +11 -10
  8. data/lib/ruby-processing/runners/watch.rb +33 -0
  9. data/samples/bezier_playground.rb +243 -0
  10. data/samples/flight_patterns.rb +1 -1
  11. data/samples/learning_processing/chapter_16/01_display_video.rb +1 -1
  12. data/samples/learning_processing/chapter_16/02_manipulate_video_image.rb +1 -1
  13. data/samples/processing_app/basics/arrays/array.rb +41 -0
  14. data/samples/processing_app/basics/arrays/array_2d.rb +38 -0
  15. data/samples/processing_app/basics/arrays/array_objects.rb +67 -0
  16. data/samples/processing_app/basics/color/brightness.rb +30 -0
  17. data/samples/processing_app/basics/color/color_wheel.rb +97 -0
  18. data/samples/processing_app/basics/color/creating.rb +37 -0
  19. data/samples/processing_app/basics/color/hue.rb +29 -0
  20. data/samples/processing_app/basics/color/linear_gradient.rb +47 -0
  21. data/samples/processing_app/basics/color/radial_gradient.rb +52 -0
  22. data/samples/processing_app/basics/color/reading/data/cait.jpg +0 -0
  23. data/samples/processing_app/basics/color/reading/reading.rb +43 -0
  24. data/samples/processing_app/basics/color/relativity.rb +38 -0
  25. data/samples/processing_app/basics/color/saturation.rb +35 -0
  26. data/samples/processing_app/basics/color/wave_gradient.rb +45 -0
  27. data/samples/processing_app/basics/control/conditionals1.rb +51 -0
  28. data/samples/processing_app/basics/control/conditionals2.rb +44 -0
  29. data/samples/processing_app/basics/control/embedded_iteration.rb +42 -0
  30. data/samples/processing_app/basics/control/iteration.rb +61 -0
  31. data/samples/processing_app/basics/control/logical_operators.rb +59 -0
  32. data/samples/processing_app/basics/data/characters_strings/characters_strings.rb +87 -0
  33. data/samples/processing_app/basics/data/characters_strings/data/Eureka-90.vlw +0 -0
  34. data/samples/processing_app/basics/data/characters_strings/data/rathausFrog.jpg +0 -0
  35. data/samples/processing_app/basics/data/datatype_conversion.rb +45 -0
  36. data/samples/processing_app/basics/data/integers_floats.rb +34 -0
  37. data/samples/processing_app/basics/data/true_false.rb +37 -0
  38. data/samples/processing_app/basics/data/variable_scope.rb +80 -0
  39. data/samples/processing_app/basics/data/variables.rb +40 -0
  40. data/samples/processing_app/basics/form/bezier.rb +23 -0
  41. data/samples/processing_app/basics/form/bezier_ellipse.rb +110 -0
  42. data/samples/processing_app/basics/form/pie_chart.rb +31 -0
  43. data/samples/processing_app/basics/form/points_lines.rb +37 -0
  44. data/samples/processing_app/basics/form/shape_primitives.rb +25 -0
  45. data/samples/processing_app/basics/form/triangle_strip.rb +43 -0
  46. data/samples/processing_app/basics/form/vertices.rb +51 -0
  47. data/samples/processing_app/basics/image/alphamask.rb +23 -0
  48. data/samples/processing_app/basics/image/background_image.rb +30 -0
  49. data/samples/processing_app/basics/image/create_image.rb +23 -0
  50. data/samples/processing_app/basics/image/data/construct.jpg +0 -0
  51. data/samples/processing_app/basics/image/data/eames.jpg +0 -0
  52. data/samples/processing_app/basics/image/data/jelly.jpg +0 -0
  53. data/samples/processing_app/basics/image/data/mask.jpg +0 -0
  54. data/samples/processing_app/basics/image/data/milan_rubbish.jpg +0 -0
  55. data/samples/processing_app/basics/image/data/teddy.gif +0 -0
  56. data/samples/processing_app/basics/image/data/test.jpg +0 -0
  57. data/samples/processing_app/basics/image/data/wash.jpg +0 -0
  58. data/samples/processing_app/basics/image/load_display_image.rb +25 -0
  59. data/samples/processing_app/basics/image/pointillism.rb +30 -0
  60. data/samples/processing_app/basics/image/request_image.rb +71 -0
  61. data/samples/processing_app/basics/image/sprite.rb +38 -0
  62. data/samples/processing_app/basics/image/transparency.rb +27 -0
  63. data/samples/processing_app/basics/input/clock.rb +46 -0
  64. data/samples/processing_app/basics/input/constrain.rb +39 -0
  65. data/samples/processing_app/basics/input/easing.rb +33 -0
  66. data/samples/processing_app/basics/input/keyboard.rb +36 -0
  67. data/samples/processing_app/basics/input/keyboard_2.rb +45 -0
  68. data/samples/processing_app/basics/input/keyboard_functions.rb +87 -0
  69. data/samples/processing_app/basics/input/milliseconds.rb +25 -0
  70. data/samples/processing_app/basics/input/mouse_1d.rb +34 -0
  71. data/samples/processing_app/basics/input/mouse_2d.rb +25 -0
  72. data/samples/processing_app/basics/input/mouse_functions.rb +73 -0
  73. data/samples/processing_app/basics/input/mouse_press.rb +21 -0
  74. data/samples/processing_app/basics/input/mouse_signals.rb +45 -0
  75. data/samples/processing_app/basics/input/storing_input.rb +39 -0
  76. data/samples/processing_app/basics/math/additive_wave.rb +66 -0
  77. data/samples/processing_app/basics/math/arctangent.rb +54 -0
  78. data/samples/processing_app/topics/simulate/chain.rb +82 -0
  79. data/samples/processing_app/topics/simulate/multiple_particle_systems.rb +166 -0
  80. data/samples/processing_app/topics/simulate/simple_particle_system.rb +113 -0
  81. data/samples/processing_app/topics/simulate/spring.rb +85 -0
  82. data/samples/processing_app/topics/simulate/springs.rb +125 -0
  83. metadata +93 -2
@@ -0,0 +1,85 @@
1
+ require 'ruby-processing'
2
+
3
+ #
4
+ # Ported from http://www.processing.org/learning/topics/spring.html
5
+ #
6
+ # Click, drag, and release the horizontal bar to start the spring.
7
+ #
8
+ class Spring < Processing::App
9
+
10
+ def setup
11
+ rect_mode CORNERS
12
+ no_stroke
13
+
14
+ @s_height = 16 # Height
15
+ @left = 50 # Left position
16
+ @right = 150 # Right position
17
+ @max = 100 # Maximum Y value
18
+ @min = 20 # Minimum Y value
19
+ @over = false # If mouse over
20
+ @move = false # If mouse down and over
21
+
22
+ # Spring simulation constants
23
+ @M = 0.8 # Mass
24
+ @K = 0.2 # Spring constant
25
+ @D = 0.92 # Damping
26
+ @R = 60 # Rest position
27
+
28
+ # Spring simulation variables
29
+ @ps = 60.0 # Position
30
+ @vs = 0.0 # Velocity
31
+ @as = 0 # Acceleration
32
+ @f = 0 # Force
33
+ end
34
+
35
+ def draw
36
+ background 102
37
+ update_spring
38
+ draw_spring
39
+ end
40
+
41
+ def draw_spring
42
+ # Draw base
43
+ fill 0.2
44
+ b_width = 0.5 * @ps + -8
45
+ rect(width/2 - b_width, @ps + @s_height, width/2 + b_width, 150)
46
+
47
+ # Set color and draw top bar
48
+ fill (@over || @move) ? 255 : 204
49
+ rect @left, @ps, @right, @ps + @s_height
50
+ end
51
+
52
+ def update_spring
53
+ # Update the spring position
54
+ if (!@move)
55
+ @f = -1 * @K * (@ps - @R) # f=-ky
56
+ @as = @f / @M # Set the acceleration, f=ma == a=f/m
57
+ @vs = @D * (@vs + @as) # Set the velocity
58
+ @ps = @ps + @vs # Updated position
59
+ end
60
+ @vs = 0.0 if @vs.abs < 0.1
61
+
62
+ # Test if mouse is over the top bar
63
+ within_x = (@left..@right).include?(mouse_x)
64
+ within_y = (@ps..@ps+@s_height).include?(mouse_y)
65
+ @over = within_x && within_y
66
+
67
+ # Set and constrain the position of top bar
68
+ if (@move)
69
+ @ps = mouseY - @s_height/2
70
+ @ps = @min if (@ps < @min)
71
+ @ps = @max if (@ps > @max)
72
+ end
73
+ end
74
+
75
+ def mouse_pressed
76
+ @move = true if @over
77
+ end
78
+
79
+ def mouse_released
80
+ @move = false
81
+ end
82
+
83
+ end
84
+
85
+ Spring.new(:width => 200, :height => 200, :title => "Spring", :full_screen => false)
@@ -0,0 +1,125 @@
1
+ require 'ruby-processing'
2
+
3
+ #
4
+ # Ported from http://www.processing.org/learning/topics/springs.html
5
+ #
6
+ # Move the mouse over one of the circles and click to re-position. When you release the mouse, it will
7
+ # snap back into position. Each circle has a slightly different behavior.
8
+ #
9
+ class Springs < Processing::App
10
+
11
+ def setup
12
+ no_stroke
13
+ smooth
14
+
15
+ @springs = []
16
+ @springs << Spring.new(self, 70, 160, 20, 0.98, 8.0, 0.1, @springs, 0)
17
+ @springs << Spring.new(self, 150, 110, 60, 0.95, 9.0, 0.1, @springs, 1)
18
+ @springs << Spring.new(self, 40, 70, 120, 0.90, 9.9, 0.1, @springs, 2)
19
+ end
20
+
21
+ def draw
22
+ background(51)
23
+ @springs.each do |sp|
24
+ sp.update
25
+ sp.display
26
+ end
27
+ end
28
+
29
+ def mouse_pressed
30
+ @springs.each {|x| x.pressed}
31
+ end
32
+
33
+ def mouse_released
34
+ @springs.each {|x| x.released}
35
+ end
36
+
37
+ end
38
+
39
+ class Spring
40
+
41
+ def initialize(app, x, y, s, d, m, k, others, id)
42
+ @app = app
43
+
44
+ # Screen values
45
+ @xpos = @tempxpos = x
46
+ @ypos = @tempypos = y
47
+ @rest_posx = x # Rest position X
48
+ @rest_posy = y # Rest position Y
49
+ @size = s
50
+ @damp = d # Damping
51
+
52
+ # Spring simulation constants
53
+ @mass = m # Mass
54
+ @kin = k # Spring constant
55
+ @friends = others
56
+ @me = id # Index of me in @friends
57
+ @over = false
58
+ @move = false
59
+
60
+ # Spring simulation variables
61
+ @velx = 0.0 # X Velocity
62
+ @vely = 0.0 # Y Velocity
63
+ @accel = 0 # Acceleration
64
+ @force = 0 # Force
65
+ end
66
+
67
+ def update
68
+ if (@move)
69
+ @rest_posx = @app.mouse_x
70
+ @rest_posy = @app.mouse_y
71
+ end
72
+
73
+ @force = -1 * @kin * (@tempypos - @rest_posy) # f=-ky
74
+ @accel = @force / @mass # Set the acceleration, f=ma == a=f/m
75
+ @vely = @damp * (@vely + @accel); # Set the velocity
76
+ @tempypos = @tempypos + @vely; # Updated position
77
+
78
+ @force = -1 * @kin * (@tempxpos - @rest_posx) # f=-ky
79
+ @accel = @force / @mass; # Set the acceleration, f=ma == a=f/m
80
+ @velx = @damp * (@velx + @accel); # Set the velocity
81
+ @tempxpos = @tempxpos + @velx; # Updated position
82
+
83
+ @over = ((over? || @move) && !other_over?)
84
+ end
85
+
86
+ # Test to see if mouse is over this spring
87
+ def over?
88
+ dis_x = @tempxpos - @app.mouse_x
89
+ dis_y = @tempypos - @app.mouse_y
90
+ Math::sqrt(@app.sq(dis_x) + @app.sq(dis_y)) < @size/2
91
+ end
92
+
93
+ # Make sure no other springs are active
94
+ def other_over?
95
+ @friends.each_with_index do |f, i|
96
+ if (i != @me)
97
+ if f.over?
98
+ return true
99
+ end
100
+ end
101
+ end
102
+ return false
103
+ end
104
+
105
+ def display
106
+ if (over?)
107
+ @app.fill(153)
108
+ else
109
+ @app.fill(255)
110
+ end
111
+ @app.ellipse(@tempxpos, @tempypos, @size, @size)
112
+ end
113
+
114
+ def pressed
115
+ @move = over?
116
+ end
117
+
118
+ def released
119
+ @move = false
120
+ @rest_posx = @xpos
121
+ @rest_posy = @ypos
122
+ end
123
+ end
124
+
125
+ Springs.new(:width => 200, :height => 200, :title => "Springs", :full_screen => false)
metadata CHANGED
@@ -1,18 +1,22 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-processing
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Ashkenas
8
8
  - Peter Gassner
9
9
  - Martin Stannard
10
10
  - Andrew Nanton
11
+ - Marc Chung
12
+ - Peter Krenn
13
+ - Florian Jenett
14
+ - Andreas Haller
11
15
  autorequire:
12
16
  bindir: bin
13
17
  cert_chain: []
14
18
 
15
- date: 2009-01-20 00:00:00 -05:00
19
+ date: 2009-03-03 00:00:00 -05:00
16
20
  default_executable: rp5
17
21
  dependencies: []
18
22
 
@@ -39,6 +43,7 @@ files:
39
43
  - lib/ruby-processing/exporters/base_exporter.rb
40
44
  - lib/ruby-processing/exporters/creator.rb
41
45
  - lib/ruby-processing/helpers
46
+ - lib/ruby-processing/helpers/numeric.rb
42
47
  - lib/ruby-processing/helpers/string.rb
43
48
  - lib/ruby-processing/runner.rb
44
49
  - lib/ruby-processing/runners
@@ -177,6 +182,7 @@ files:
177
182
  - library/video/library
178
183
  - library/video/library/video.jar
179
184
  - samples/animator.rb
185
+ - samples/bezier_playground.rb
180
186
  - samples/circle_collision.rb
181
187
  - samples/fern.rb
182
188
  - samples/flight_patterns.rb
@@ -318,11 +324,96 @@ files:
318
324
  - samples/processing_app/3D/typography/data/Univers66.vlw.gz
319
325
  - samples/processing_app/3D/typography/kinetic_type.rb
320
326
  - samples/processing_app/ABOUT
327
+ - samples/processing_app/basics
328
+ - samples/processing_app/basics/arrays
329
+ - samples/processing_app/basics/arrays/array.rb
330
+ - samples/processing_app/basics/arrays/array_2d.rb
331
+ - samples/processing_app/basics/arrays/array_objects.rb
332
+ - samples/processing_app/basics/color
333
+ - samples/processing_app/basics/color/brightness.rb
334
+ - samples/processing_app/basics/color/color_wheel.rb
335
+ - samples/processing_app/basics/color/creating.rb
336
+ - samples/processing_app/basics/color/hue.rb
337
+ - samples/processing_app/basics/color/linear_gradient.rb
338
+ - samples/processing_app/basics/color/radial_gradient.rb
339
+ - samples/processing_app/basics/color/reading
340
+ - samples/processing_app/basics/color/reading/data
341
+ - samples/processing_app/basics/color/reading/data/cait.jpg
342
+ - samples/processing_app/basics/color/reading/reading.rb
343
+ - samples/processing_app/basics/color/relativity.rb
344
+ - samples/processing_app/basics/color/saturation.rb
345
+ - samples/processing_app/basics/color/wave_gradient.rb
346
+ - samples/processing_app/basics/control
347
+ - samples/processing_app/basics/control/conditionals1.rb
348
+ - samples/processing_app/basics/control/conditionals2.rb
349
+ - samples/processing_app/basics/control/embedded_iteration.rb
350
+ - samples/processing_app/basics/control/iteration.rb
351
+ - samples/processing_app/basics/control/logical_operators.rb
352
+ - samples/processing_app/basics/data
353
+ - samples/processing_app/basics/data/characters_strings
354
+ - samples/processing_app/basics/data/characters_strings/characters_strings.rb
355
+ - samples/processing_app/basics/data/characters_strings/data
356
+ - samples/processing_app/basics/data/characters_strings/data/Eureka-90.vlw
357
+ - samples/processing_app/basics/data/characters_strings/data/rathausFrog.jpg
358
+ - samples/processing_app/basics/data/datatype_conversion.rb
359
+ - samples/processing_app/basics/data/integers_floats.rb
360
+ - samples/processing_app/basics/data/true_false.rb
361
+ - samples/processing_app/basics/data/variable_scope.rb
362
+ - samples/processing_app/basics/data/variables.rb
363
+ - samples/processing_app/basics/form
364
+ - samples/processing_app/basics/form/bezier.rb
365
+ - samples/processing_app/basics/form/bezier_ellipse.rb
366
+ - samples/processing_app/basics/form/pie_chart.rb
367
+ - samples/processing_app/basics/form/points_lines.rb
368
+ - samples/processing_app/basics/form/shape_primitives.rb
369
+ - samples/processing_app/basics/form/triangle_strip.rb
370
+ - samples/processing_app/basics/form/vertices.rb
371
+ - samples/processing_app/basics/image
372
+ - samples/processing_app/basics/image/alphamask.rb
373
+ - samples/processing_app/basics/image/background_image.rb
374
+ - samples/processing_app/basics/image/create_image.rb
375
+ - samples/processing_app/basics/image/data
376
+ - samples/processing_app/basics/image/data/construct.jpg
377
+ - samples/processing_app/basics/image/data/eames.jpg
378
+ - samples/processing_app/basics/image/data/jelly.jpg
379
+ - samples/processing_app/basics/image/data/mask.jpg
380
+ - samples/processing_app/basics/image/data/milan_rubbish.jpg
381
+ - samples/processing_app/basics/image/data/teddy.gif
382
+ - samples/processing_app/basics/image/data/test.jpg
383
+ - samples/processing_app/basics/image/data/wash.jpg
384
+ - samples/processing_app/basics/image/load_display_image.rb
385
+ - samples/processing_app/basics/image/pointillism.rb
386
+ - samples/processing_app/basics/image/request_image.rb
387
+ - samples/processing_app/basics/image/sprite.rb
388
+ - samples/processing_app/basics/image/transparency.rb
389
+ - samples/processing_app/basics/input
390
+ - samples/processing_app/basics/input/clock.rb
391
+ - samples/processing_app/basics/input/constrain.rb
392
+ - samples/processing_app/basics/input/easing.rb
393
+ - samples/processing_app/basics/input/keyboard.rb
394
+ - samples/processing_app/basics/input/keyboard_2.rb
395
+ - samples/processing_app/basics/input/keyboard_functions.rb
396
+ - samples/processing_app/basics/input/milliseconds.rb
397
+ - samples/processing_app/basics/input/mouse_1d.rb
398
+ - samples/processing_app/basics/input/mouse_2d.rb
399
+ - samples/processing_app/basics/input/mouse_functions.rb
400
+ - samples/processing_app/basics/input/mouse_press.rb
401
+ - samples/processing_app/basics/input/mouse_signals.rb
402
+ - samples/processing_app/basics/input/storing_input.rb
403
+ - samples/processing_app/basics/math
404
+ - samples/processing_app/basics/math/additive_wave.rb
405
+ - samples/processing_app/basics/math/arctangent.rb
321
406
  - samples/processing_app/topics
322
407
  - samples/processing_app/topics/effects
323
408
  - samples/processing_app/topics/effects/data
324
409
  - samples/processing_app/topics/effects/data/red_smoke.jpg
325
410
  - samples/processing_app/topics/effects/lens.rb
411
+ - samples/processing_app/topics/simulate
412
+ - samples/processing_app/topics/simulate/chain.rb
413
+ - samples/processing_app/topics/simulate/multiple_particle_systems.rb
414
+ - samples/processing_app/topics/simulate/simple_particle_system.rb
415
+ - samples/processing_app/topics/simulate/spring.rb
416
+ - samples/processing_app/topics/simulate/springs.rb
326
417
  - samples/reflection.rb
327
418
  - samples/simple_buffer.rb
328
419
  - samples/tree.rb