ruby-processing 2.6.2 → 2.6.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (129) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rpextras.jar +0 -0
  3. data/lib/ruby-processing.rb +5 -8
  4. data/lib/ruby-processing/app.rb +26 -27
  5. data/lib/ruby-processing/config.rb +0 -2
  6. data/lib/ruby-processing/exporters/application_exporter.rb +1 -1
  7. data/lib/ruby-processing/exporters/base_exporter.rb +1 -1
  8. data/lib/ruby-processing/exporters/creator.rb +11 -11
  9. data/lib/ruby-processing/helper_methods.rb +33 -31
  10. data/lib/ruby-processing/helpers/numeric.rb +1 -1
  11. data/lib/ruby-processing/helpers/range.rb +11 -0
  12. data/lib/ruby-processing/library_loader.rb +11 -16
  13. data/lib/ruby-processing/runner.rb +22 -24
  14. data/lib/ruby-processing/runners/watch.rb +1 -1
  15. data/lib/ruby-processing/version.rb +1 -1
  16. data/library/boids/boids.rb +39 -70
  17. data/library/control_panel/control_panel.rb +3 -3
  18. data/samples/contributed/circle_collision.rb +3 -3
  19. data/samples/contributed/fern.rb +7 -10
  20. data/samples/contributed/fibonacci_sphere.rb +2 -2
  21. data/samples/contributed/full_screen.rb +23 -22
  22. data/samples/contributed/grapher.rb +3 -3
  23. data/samples/contributed/gravity.rb +1 -1
  24. data/samples/contributed/mandelbrot.rb +10 -13
  25. data/samples/external_library/java_processing/box2d_processing/bumpy_surface_noise.rb +1 -1
  26. data/samples/external_library/java_processing/box2d_processing/library/custom_shape/custom_shape.rb +2 -2
  27. data/samples/external_library/java_processing/box2d_processing/library/particle_system/particle_system.rb +1 -1
  28. data/samples/external_library/java_processing/box2d_processing/library/surface/surface.rb +2 -2
  29. data/samples/external_library/java_processing/box2d_processing/liquidy.rb +1 -1
  30. data/samples/external_library/java_processing/fisica/bubbles.rb +2 -2
  31. data/samples/external_library/java_processing/fisica/joints.rb +4 -4
  32. data/samples/external_library/java_processing/generative_design/node_spring_attractor.rb +2 -2
  33. data/samples/external_library/java_processing/geomerative/hello_world_rotate_firstletter.rb +7 -7
  34. data/samples/external_library/java_processing/hemesh/twin_iso.rb +3 -3
  35. data/samples/external_library/java_processing/pbox2d/bumpy_surface_noise.rb +1 -1
  36. data/samples/external_library/java_processing/pbox2d/library/custom_shape/custom_shape.rb +2 -2
  37. data/samples/external_library/java_processing/pbox2d/library/particle_system/particle_system.rb +1 -1
  38. data/samples/external_library/java_processing/pbox2d/library/surface/surface.rb +2 -2
  39. data/samples/external_library/java_processing/pbox2d/liquidy.rb +1 -1
  40. data/samples/external_library/java_processing/peasy_cam/library/hilbert/hilbert.rb +4 -4
  41. data/samples/external_library/ruby_gem/draw_test.rb +2 -2
  42. data/samples/external_library/ruby_gem/game_of_life.rb +3 -3
  43. data/samples/processing_app/basics/arrays/array_objects.rb +2 -2
  44. data/samples/processing_app/basics/color/hue.rb +1 -1
  45. data/samples/processing_app/basics/control/conditionals1.rb +5 -24
  46. data/samples/processing_app/basics/control/conditionals2.rb +1 -1
  47. data/samples/processing_app/basics/form/bezier_ellipse.rb +1 -1
  48. data/samples/processing_app/basics/form/brick_tower.rb +4 -8
  49. data/samples/processing_app/basics/form/regular_polygon.rb +1 -1
  50. data/samples/processing_app/basics/form/star.rb +1 -1
  51. data/samples/processing_app/basics/form/triangle_strip.rb +1 -1
  52. data/samples/processing_app/basics/input/storing_input.rb +1 -1
  53. data/samples/processing_app/basics/lights/spot.rb +1 -1
  54. data/samples/processing_app/basics/math/additive_wave.rb +2 -2
  55. data/samples/processing_app/basics/math/double_random.rb +2 -2
  56. data/samples/processing_app/basics/math/noise_wave.rb +1 -1
  57. data/samples/processing_app/basics/math/random.rb +1 -1
  58. data/samples/processing_app/basics/objects/module.rb +1 -1
  59. data/samples/processing_app/basics/objects/struct.rb +1 -1
  60. data/samples/processing_app/basics/structure/loop.rb +19 -14
  61. data/samples/processing_app/basics/structure/recursion2.rb +2 -2
  62. data/samples/processing_app/basics/textures/texture3.rb +13 -33
  63. data/samples/processing_app/basics/transform/birds.rb +5 -5
  64. data/samples/processing_app/basics/transform/cubes_in_cube.rb +3 -3
  65. data/samples/processing_app/basics/transform/rotate.rb +1 -1
  66. data/samples/processing_app/basics/typography/kinetic_type.rb +1 -1
  67. data/samples/processing_app/demos/graphics/bezier_patch.rb +34 -34
  68. data/samples/processing_app/demos/graphics/trefoil.rb +1 -1
  69. data/samples/processing_app/demos/graphics/wiggling.rb +5 -5
  70. data/samples/processing_app/demos/performance/esfera.rb +4 -4
  71. data/samples/processing_app/demos/performance/text_rendering.rb +1 -1
  72. data/samples/processing_app/library/dxf/simple_export.rb +3 -3
  73. data/samples/processing_app/library/pdf/complex_3D.rb +11 -11
  74. data/samples/processing_app/library/vecmath/vec2d/bouncing_ball.rb +1 -1
  75. data/samples/processing_app/library/vecmath/vec2d/circle_collision.rb +3 -3
  76. data/samples/processing_app/library/vecmath/vec2d/library/flock/flock.rb +5 -5
  77. data/samples/processing_app/library/vecmath/vec2d/library/particle/{particle_system.rb → particle.rb} +28 -21
  78. data/samples/processing_app/library/vecmath/vec2d/morph.rb +3 -3
  79. data/samples/processing_app/library/vecmath/vec2d/particle_system_pshape.rb +3 -3
  80. data/samples/processing_app/library/vecmath/vec2d/reflection1.rb +2 -2
  81. data/samples/processing_app/library/vecmath/vec2d/seeking_neural.rb +3 -2
  82. data/samples/processing_app/library/vecmath/vec2d/simple_particle_system.rb +1 -1
  83. data/samples/processing_app/library/vecmath/vec3d/frame_of_reference.rb +4 -4
  84. data/samples/processing_app/topics/advanced_data/library/word/word.rb +1 -1
  85. data/samples/processing_app/topics/advanced_data/load_save_XML.rb +1 -1
  86. data/samples/processing_app/topics/advanced_data/load_save_json.rb +1 -1
  87. data/samples/processing_app/topics/advanced_data/load_save_struct_yaml.rb +1 -1
  88. data/samples/processing_app/topics/advanced_data/load_save_yaml.rb +1 -1
  89. data/samples/processing_app/topics/advanced_data/threads_two.rb +1 -2
  90. data/samples/processing_app/topics/cellular_automata/game_of_life.rb +3 -3
  91. data/samples/processing_app/topics/cellular_automata/library/ca/ca.rb +2 -2
  92. data/samples/processing_app/topics/cellular_automata/library/cell/cell.rb +4 -4
  93. data/samples/processing_app/topics/cellular_automata/library/simple_cell/simple_cell.rb +1 -1
  94. data/samples/processing_app/topics/cellular_automata/spore1.rb +1 -1
  95. data/samples/processing_app/topics/cellular_automata/spore2.rb +1 -1
  96. data/samples/processing_app/topics/create_shapes/group_pshape.rb +2 -2
  97. data/samples/processing_app/topics/create_shapes/library/particle/particle_system.rb +3 -3
  98. data/samples/processing_app/topics/create_shapes/library/polygon/polygon.rb +2 -2
  99. data/samples/processing_app/topics/create_shapes/library/star/star.rb +3 -3
  100. data/samples/processing_app/topics/create_shapes/particle_system_pshape.rb +1 -1
  101. data/samples/processing_app/topics/create_shapes/path_pshape.rb +1 -1
  102. data/samples/processing_app/topics/drawing/scribble_plotter.rb +2 -2
  103. data/samples/processing_app/topics/gui/button.rb +16 -16
  104. data/samples/processing_app/topics/gui/rollover.rb +13 -13
  105. data/samples/processing_app/topics/image_processing/blur.rb +2 -2
  106. data/samples/processing_app/topics/image_processing/edge_detection.rb +2 -2
  107. data/samples/processing_app/topics/lsystems/cstest.rb +1 -1
  108. data/samples/processing_app/topics/lsystems/library/stochastic_grammar/stochastic_grammar.rb +1 -1
  109. data/samples/processing_app/topics/motion/bouncy_bubbles.rb +1 -1
  110. data/samples/processing_app/topics/motion/brownian.rb +2 -2
  111. data/samples/processing_app/topics/motion/circle_collision.rb +1 -1
  112. data/samples/processing_app/topics/motion/cubes_in_cube.rb +1 -1
  113. data/samples/processing_app/topics/motion/library/cube/cube.rb +2 -2
  114. data/samples/processing_app/topics/motion/morph.rb +11 -11
  115. data/samples/processing_app/topics/motion/moving_on_curves.rb +4 -4
  116. data/samples/processing_app/topics/motion/puff.rb +4 -4
  117. data/samples/processing_app/topics/motion/reflection1.rb +3 -3
  118. data/samples/processing_app/topics/motion/reflection2.rb +1 -1
  119. data/samples/processing_app/topics/shaders/bw_shader.rb +1 -1
  120. data/samples/processing_app/topics/shaders/glsl_heightmap_noise.rb +2 -2
  121. data/samples/processing_app/topics/simulate/flocking.rb +6 -6
  122. data/samples/processing_app/topics/simulate/library/flock/flock.rb +33 -41
  123. data/samples/processing_app/topics/simulate/multiple_particle_systems.rb +34 -60
  124. data/samples/processing_app/topics/simulate/simple_particle_system.rb +20 -32
  125. data/samples/processing_app/topics/simulate/smoke_particle_system.rb +45 -57
  126. data/samples/processing_app/topics/simulate/springs.rb +40 -44
  127. metadata +4 -5
  128. data/samples/processing_app/library/vecmath/vec2d/multiple_particle_systems.rb +0 -141
  129. data/samples/processing_app/library/vecmath/vec2d/smoke_particle_system.rb +0 -133
@@ -26,7 +26,7 @@ end
26
26
 
27
27
  def draw
28
28
  background 51
29
- @jitter = rand(-0.1 .. 0.1) if Time.now.sec.even?
29
+ @jitter = rand(-0.1..0.1) if Time.now.sec.even?
30
30
  @angle += @jitter
31
31
  translate width / 2, height / 2
32
32
  rotate cos(@angle)
@@ -49,7 +49,7 @@
49
49
  end
50
50
 
51
51
  def compute_curve(line_num)
52
- base = millis / 10000.0 * PI * 2
52
+ base = millis / 10_000.0 * PI * 2
53
53
  sin((line_num + 1.0) * base) * sin((8.0 - line_num) * base)
54
54
  end
55
55
 
@@ -16,7 +16,7 @@ RESI=NI*10
16
16
  RESJ=NJ*10
17
17
 
18
18
  attr_accessor :outp, :inp, :normp, :auto_normals, :arcball, :bez_patch
19
-
19
+
20
20
  def setup
21
21
  size(1024, 768, P3D)
22
22
  ArcBall.init(self, width/2.0, height/2.0)
@@ -24,14 +24,14 @@ def setup
24
24
  build_geometry
25
25
  @bez_patch = build_shape
26
26
  end
27
-
27
+
28
28
  def draw
29
29
  background(255)
30
30
  smooth(8)
31
31
  lights
32
32
  define_lights
33
33
  scale(0.9)
34
- no_stroke
34
+ no_stroke
35
35
  shape(bez_patch)
36
36
  end
37
37
 
@@ -44,34 +44,34 @@ def build_shape
44
44
  no_stroke
45
45
  bez = create_shape
46
46
  bez.begin_shape(QUAD_STRIP)
47
- bez.fill(192, 192, 192)
47
+ bez.fill(192, 192, 192)
48
48
  bez.ambient(20, 20, 20)
49
49
  bez.specular(30)
50
- (0 ... RESI - 1).each do |i|
50
+ (0 ... RESI - 1).each do |i|
51
51
  (0 ... RESJ).each do |j|
52
52
  if (!auto_normals)
53
53
  bez.normal(*normp[i][j])
54
54
  end
55
55
  bez.vertex(*outp[i][j])
56
- bez.vertex(*outp[i+1][j])
57
- end
56
+ bez.vertex(*outp[i+1][j])
57
+ end
58
58
  end
59
- bez.end_shape
60
- return bez
59
+ bez.end_shape
60
+ return bez
61
61
  end
62
62
 
63
63
  ##########
64
64
  # build geometry
65
65
  # for bez patch
66
66
  ##########
67
-
67
+
68
68
  def build_geometry
69
69
  @outp = []
70
70
  @normp = []
71
- @inp = Array.new(NI){|i| Array.new(NJ){|j| Vec3D.new(i, j, rand(-3.0 .. 3))}}
71
+ @inp = Array.new(NI){|i| Array.new(NJ){|j| Vec3D.new(i, j, rand(-3.0..3))}}
72
72
  uitang = Vec3D.new
73
- ujtang = Vec3D.new
74
-
73
+ ujtang = Vec3D.new
74
+
75
75
  (0 ... RESI).each do |i|
76
76
  mui = i.fdiv(RESI - 1)
77
77
  row = []
@@ -88,7 +88,7 @@ def build_geometry
88
88
  bj = bezier_blend(kj, muj, NJ)
89
89
  dbj = d_bezier_blend(kj, muj, NJ)
90
90
 
91
- vect += inp[ki][kj] * bi * bj
91
+ vect += inp[ki][kj] * bi * bj
92
92
 
93
93
  uitang += inp[ki][kj] * dbi * bj
94
94
 
@@ -97,22 +97,22 @@ def build_geometry
97
97
  end
98
98
  vect += Vec3D.new(-NI / 2, -NJ / 2, 0)
99
99
  vect *= 100
100
- row << vect.to_a
100
+ row << vect.to_a
101
101
  uitang.normalize!
102
102
  ujtang.normalize!
103
- row_n << uitang.cross(ujtang).to_a
103
+ row_n << uitang.cross(ujtang).to_a
104
104
  end
105
105
  @outp << row
106
106
  @normp << row_n
107
107
  end
108
108
  end
109
-
109
+
110
110
  def bezier_blend( k, mu, n)
111
- blend = 1.0
111
+ blend = 1.0
112
112
  nn = n
113
113
  kn = k
114
114
  nkn = n - k
115
-
115
+
116
116
  while (nn >= 1)
117
117
  blend *= nn
118
118
  nn -= 1
@@ -124,19 +124,19 @@ def bezier_blend( k, mu, n)
124
124
  blend = blend.fdiv(nkn)
125
125
  nkn -= 1
126
126
  end
127
- end
128
- blend *= pow(mu, k.to_f) if (k > 0)
129
- blend *= pow(1-mu, (n - k).to_f) if (n - k > 0)
127
+ end
128
+ blend *= mu**k.to_f if (k > 0)
129
+ blend *= (1 - mu)**(n - k).to_f if (n - k > 0)
130
130
  return(blend)
131
131
  end
132
132
 
133
133
  def d_bezier_blend( k, mu, n)
134
134
  dblendf = 1.0
135
-
135
+
136
136
  nn = n
137
137
  kn = k
138
138
  nkn = n - k
139
-
139
+
140
140
  while (nn >= 1)
141
141
  dblendf *= nn
142
142
  nn -= 1
@@ -149,25 +149,25 @@ def d_bezier_blend( k, mu, n)
149
149
  nkn -= 1
150
150
  end
151
151
  end
152
-
152
+
153
153
  fk = 1
154
154
  dk = 0
155
155
  fnk = 1
156
- dnk = 0
156
+ dnk = 0
157
157
  if (k > 0)
158
- fk = pow(mu, k.to_f)
159
- dk = k * pow(mu, (k - 1).to_f)
160
- end
158
+ fk = mu**k.to_f
159
+ dk = k * (mu**(k - 1).to_f)
160
+ end
161
161
  if (n - k > 0)
162
- fnk = pow(1 - mu, (n - k).to_f)
163
- dnk = (k - n)*pow(1 - mu, (n - k - 1).to_f)
162
+ fnk = (1 - mu)**(n - k).to_f
163
+ dnk = (k - n) * (1 - mu)**(n - k - 1).to_f
164
164
  end
165
165
  dblendf *= (dk * fnk + fk * dnk)
166
-
167
- return(dblendf)
166
+
167
+ return(dblendf)
168
168
  end
169
169
 
170
- def define_lights
170
+ def define_lights
171
171
  ambient_light(40, 40, 40)
172
172
  point_light(30, 30, 30, 0, 0, 0)
173
173
  directional_light(60, 60, 60, 1, 0, 0)
@@ -32,7 +32,7 @@ def draw
32
32
  background(0)
33
33
 
34
34
  pg.begin_draw
35
- pg.ellipse(rand(0.0 .. pg.width), rand(0.0 .. pg.height), 4, 4)
35
+ pg.ellipse(rand(0.0..pg.width), rand(0.0..pg.height), 4, 4)
36
36
  pg.end_draw
37
37
 
38
38
  ambient(250, 250, 250)
@@ -18,10 +18,10 @@ def setup
18
18
  @cosine = []
19
19
  wiggling = false
20
20
  # Dry up that processing code a tiny bit
21
- (0 .. TAU).step(TAU / CIRCLE_RES) do |i|
21
+ (0..TAU).step(TAU / CIRCLE_RES) do |i|
22
22
  sine << CIRCLE_RAD * sin(i)
23
23
  end
24
- (0 .. TAU).step(TAU / CIRCLE_RES) do |i|
24
+ (0..TAU).step(TAU / CIRCLE_RES) do |i|
25
25
  cosine << CIRCLE_RAD * cos(i)
26
26
  end
27
27
  @cube = create_cube
@@ -41,9 +41,9 @@ def draw
41
41
  face = cube.get_child(i)
42
42
  face.get_vertex_count.times do |j|
43
43
  x, y, z = face.get_vertex_x(j), face.get_vertex_y(j), face.get_vertex_z(j)
44
- x += rand(-NOISE_MAG/2 .. NOISE_MAG/2)
45
- y += rand(-NOISE_MAG/2 .. NOISE_MAG/2)
46
- z += rand(-NOISE_MAG/2 .. NOISE_MAG/2)
44
+ x += rand(-NOISE_MAG/2..NOISE_MAG/2)
45
+ y += rand(-NOISE_MAG/2..NOISE_MAG/2)
46
+ z += rand(-NOISE_MAG/2..NOISE_MAG/2)
47
47
  face.set_vertex(j, x, y, z)
48
48
  end
49
49
  end
@@ -7,7 +7,7 @@
7
7
  #
8
8
  load_library :vecmath
9
9
 
10
- QUANTITY = 16000
10
+ QUANTITY = 16_000
11
11
 
12
12
  attr_reader :orb, :phi, :radius, :rx, :ry
13
13
 
@@ -43,9 +43,9 @@ def draw
43
43
  end
44
44
 
45
45
  def create_hair radius
46
- z = rand(-radius .. radius)
47
- phi = rand(0 .. TAU)
48
- len = rand(1.15 .. 1.2)
46
+ z = rand(-radius..radius)
47
+ phi = rand(0..TAU)
48
+ len = rand(1.15..1.2)
49
49
  theta = Math.asin(z / radius)
50
50
  Hair.new(z, phi, len, theta)
51
51
  end
@@ -5,7 +5,7 @@ end
5
5
 
6
6
  def draw
7
7
  background(255)
8
- (0 .. 10000).each do
8
+ (0..10_000).each do
9
9
  x = rand(width)
10
10
  y = rand(height)
11
11
  text("HELLO", x, y)
@@ -23,9 +23,9 @@ def draw
23
23
  translate(width / 3, height / 3, -200)
24
24
  rotate_z(map(mouse_y, 0, height, 0, PI))
25
25
  rotateY(map(mouse_x, 0, width, 0, HALF_PI))
26
- (-2 .. 2).step do |y|
27
- (-2 .. 2).step do |x|
28
- (-2 .. 2).step do |z|
26
+ (-2..2).step do |y|
27
+ (-2..2).step do |x|
28
+ (-2..2).step do |z|
29
29
  push_matrix
30
30
  translate(120*x, 120*y, -120*z)
31
31
  sphere(30)
@@ -21,35 +21,35 @@ def setup
21
21
  pt << rand(TAU) # Random X axis rotation
22
22
  pt << rand(TAU) # Random Y axis rotation
23
23
 
24
- pt << rand(60 .. 80) # Short to quarter-circle arcs
24
+ pt << rand(60..80) # Short to quarter-circle arcs
25
25
  if (rand(100)>90)
26
- pt[pt.length - 1] = rand(8 .. 27) * 10
26
+ pt[pt.length - 1] = rand(8..27) * 10
27
27
  end
28
- pt << rand(2 .. 50) * 5 # Radius. Space them out nicely
28
+ pt << rand(2..50) * 5 # Radius. Space them out nicely
29
29
 
30
- pt << rand(4 .. 32) # Width of band
30
+ pt << rand(4..32) # Width of band
31
31
  if (rand(100) > 90)
32
- pt[pt.length - 1] = rand(40 .. 60) # Width of band
32
+ pt[pt.length - 1] = rand(40..60) # Width of band
33
33
  end
34
34
 
35
- pt << rand(0.005 .. 0.0334)# Speed of rotation
35
+ pt << rand(0.005..0.0334)# Speed of rotation
36
36
 
37
37
  # get colors
38
38
  prob = rand(100)
39
39
  case prob
40
- when (0 .. 30)
40
+ when (0..30)
41
41
  style[i*2] = color_blended(rand, 255,0,100, 255,0,0, 210)
42
- when (30 .. 70)
42
+ when (30..70)
43
43
  style[i*2] = color_blended(rand, 0,153,255, 170,225,255, 210)
44
- when (70 .. 90)
44
+ when (70..90)
45
45
  style[i*2] = color_blended(rand, 200,255,0, 150,255,0, 210)
46
46
  else
47
47
  style[i*2] = color(255,255,255, 220)
48
48
  end
49
49
  case prob
50
- when (0 .. 50)
50
+ when (0..50)
51
51
  style[i*2] = color_blended(rand, 200,255,0, 50,120,0, 210)
52
- when (50 .. 90)
52
+ when (50..90)
53
53
  style[i*2] = color_blended(rand, 255,100,0, 255,255,0, 210)
54
54
  else
55
55
  style[i*2] = color(255, 255, 255, 220)
@@ -30,7 +30,7 @@ def draw
30
30
  # Add gravity to velocity
31
31
  @velocity += gravity
32
32
  # Bounce off edges
33
- velocity.x *= -1 unless (RADIUS .. width - RADIUS).include?(loc.x)
33
+ velocity.x *= -1 unless (RADIUS..width - RADIUS).include?(loc.x)
34
34
  if loc.y > (height - RADIUS)
35
35
  # We're reducing velocity ever so slightly
36
36
  # when it hits the bottom of the window
@@ -72,7 +72,7 @@ end
72
72
  def empty_space(r)
73
73
  pos = nil
74
74
  while !pos || !empty_space?(pos, r) do
75
- pos = Vec2D.new(rand(r .. width - r), rand(r .. height - r))
75
+ pos = Vec2D.new(rand(r..width - r), rand(r..height - r))
76
76
  end
77
77
  return pos
78
78
  end
@@ -162,8 +162,8 @@ end
162
162
 
163
163
  # reverse ball velocity if at sketch boundary
164
164
  def check_boundary_collision(ball)
165
- ball.velocity.x *= -1 unless (ball.r .. width - ball.r).include? ball.position.x
166
- ball.velocity.y *= -1 unless (ball.r .. height - ball.r).include? ball.position.y
165
+ ball.velocity.x *= -1 unless (ball.r..width - ball.r).include? ball.position.x
166
+ ball.velocity.y *= -1 unless (ball.r..height - ball.r).include? ball.position.y
167
167
  end
168
168
 
169
169
 
@@ -7,7 +7,7 @@ class Flock
7
7
  include Enumerable
8
8
 
9
9
  def initialize(size, position)
10
- @boids = (0 .. size).map{ Boid.new(position) }
10
+ @boids = (0..size).map{ Boid.new(position) }
11
11
  end
12
12
 
13
13
  def run
@@ -27,7 +27,7 @@ class Boid
27
27
  attr_reader :width, :height
28
28
  def initialize(loc)
29
29
  @acceleration = Vec2D.new
30
- @velocity = Vec2D.new(rand(-1.0 .. 1), rand(-1.0 .. 1))
30
+ @velocity = Vec2D.new(rand(-1.0..1), rand(-1.0..1))
31
31
  @location = loc
32
32
  @r = 2.0
33
33
  @maxspeed = 2
@@ -122,7 +122,7 @@ class Boid
122
122
  boids.reject{ |bd| bd.equal? self }.each do |other|
123
123
  d = location.dist(other.location)
124
124
  # If the distance is greater than 0 and less than an arbitrary amount
125
- if (0.0001 .. desiredseparation).include? d
125
+ if (0.0001..desiredseparation).include? d
126
126
  # Calculate vector pointing away from neighbor
127
127
  diff = location - other.location
128
128
  diff.normalize!
@@ -156,7 +156,7 @@ class Boid
156
156
  count = 0
157
157
  boids.reject{ |bd| bd.equal? self }.each do |other|
158
158
  d = location.dist(other.location)
159
- if (0 .. neighbordist).include? d
159
+ if (0..neighbordist).include? d
160
160
  sum += other.velocity
161
161
  count += 1
162
162
  end
@@ -180,7 +180,7 @@ class Boid
180
180
  count = 0
181
181
  boids.reject { |bd| bd.equal? self }.each do |other|
182
182
  d = location.dist(other.location)
183
- if (0.0001 .. neighbordist).include? d
183
+ if (0.0001..neighbordist).include? d
184
184
  sum += other.location # Add location
185
185
  count += 1
186
186
  end
@@ -1,17 +1,17 @@
1
1
  # The Particle System
2
2
 
3
- class ParticleSystem
3
+ class ParticleSystem
4
4
  include Processing::Proxy
5
5
 
6
6
  attr_reader :particles, :particle_shape
7
7
 
8
- def initialize(width, height, sprite, n)
8
+ def initialize(width, height, sprite, n)
9
9
  @particles = []
10
10
  # The PShape is a group
11
11
  @particle_shape = create_shape(GROUP)
12
12
 
13
13
  # Make all the Particles
14
- n.times do |i|
14
+ n.times do |i|
15
15
  particles << Particle.new(width, height, sprite)
16
16
  # Each particle's PShape gets added to the System PShape
17
17
  particle_shape.add_child(particles[i].s_shape)
@@ -24,10 +24,10 @@ class ParticleSystem
24
24
  end
25
25
  end
26
26
 
27
- def set_emitter(x, y)
27
+ def set_emitter(x, y)
28
28
  particles.each do |p|
29
- # Each particle gets reborn at the emitter location
30
- p.rebirth(x, y) if (p.dead?)
29
+ # Each particle gets reborn at the emitter location
30
+ p.rebirth(x, y) if (p.dead?)
31
31
  end
32
32
  end
33
33
 
@@ -41,15 +41,16 @@ end
41
41
  class Particle
42
42
  include Processing::Proxy
43
43
 
44
- GRAVITY = Vec2D.new(0, 0.1)
45
-
46
- attr_reader :center, :velocity, :lifespan, :s_shape, :part_size,
47
- :width, :height, :sprite
48
-
44
+ GRAVITY = Vec2D.new(0, 0.1)
45
+
46
+ attr_reader :center, :velocity, :lifespan, :s_shape, :part_size,
47
+ :boundary_x, :boundary_y, :sprite
49
48
 
50
49
  def initialize width, height, sprite
51
- @width, @height, @sprite = width, height, sprite
52
- part_size = rand(10 .. 60)
50
+ @sprite = sprite
51
+ @boundary_x = Boundary.new(0, width)
52
+ @boundary_y = Boundary.new(0, height)
53
+ part_size = rand(10..60)
53
54
  # The particle is a textured quad
54
55
  @s_shape = create_shape
55
56
  s_shape.begin_shape(QUAD)
@@ -61,10 +62,8 @@ class Particle
61
62
  s_shape.vertex(+part_size / 2.0, +part_size / 2.0, sprite.width, sprite.height)
62
63
  s_shape.vertex(-part_size / 2.0, +part_size / 2.0, 0, sprite.height)
63
64
  s_shape.end_shape
64
-
65
65
  # Initialize center vector
66
- @center = Vec2D.new
67
-
66
+ @center = Vec2D.new
68
67
  # Set the particle starting location
69
68
  rebirth(width / 2.0, height / 2.0)
70
69
  end
@@ -79,16 +78,17 @@ class Particle
79
78
  @lifespan = 255
80
79
  # Set location using translate
81
80
  s_shape.reset_matrix
82
- s_shape.translate(x, y)
83
-
81
+ s_shape.translate(x, y)
84
82
  # Update center vector
85
83
  center.x, center.y = x, y
86
84
  end
87
85
 
88
86
  # Is it off the screen, or its lifespan is over?
89
87
  def dead?
90
- (center.x > width || center.x < 0 ||
91
- center.y > height || center.y < 0 || lifespan < 0)
88
+ return true if lifespan < 0
89
+ return true if boundary_y.exclude? center.y
90
+ return true if boundary_x.exclude? center.x
91
+ false
92
92
  end
93
93
 
94
94
  def update
@@ -99,8 +99,15 @@ class Particle
99
99
  s_shape.set_tint(color(255, lifespan))
100
100
  # Move the particle according to its velocity
101
101
  s_shape.translate(velocity.x, velocity.y)
102
- # and also update the center
102
+ # and also update the center location
103
103
  @center += velocity
104
104
  end
105
105
  end
106
106
 
107
+ # unusually in this case we are looking for excluded values
108
+
109
+ Boundary = Struct.new(:lower, :upper) do
110
+ def exclude? val
111
+ true unless (lower...upper).cover? val
112
+ end
113
+ end