@@ -8,10 +8,8 @@ def setup
88 wide_count = width / UNIT
99 height_count = height / UNIT
1010 @custom_array = CustomArray . new
11- height_count . times do |i |
12- wide_count . times do |j |
13- custom_array . add_object ( j * UNIT , i * UNIT , UNIT / 2 , UNIT / 2 , rand ( 0.05 ..0.8 ) )
14- end
11+ grid ( wide_count , height_count ) do |i , j |
12+ custom_array . add_object ( j * UNIT , i * UNIT , UNIT / 2 , UNIT / 2 , rand ( 0.05 ..0.8 ) )
1513 end
1614 no_stroke
1715end
@@ -33,19 +31,19 @@ def settings
3331
3432# The custom Array created using Forwardable
3533# Processing::Proxy gives access to PApplet methods
36- class CustomArray
34+ class CustomArray
3735 extend Forwardable
3836 def_delegators ( :@objs , :each , :<< )
3937 include Enumerable , Processing ::Proxy
40-
38+
4139 def initialize
4240 @objs = [ ]
4341 end
44-
42+
4543 def add_object ( mx , my , x , y , speed )
4644 self << Particle . new ( x . to_i , y . to_i , mx , my , UNIT , speed , 1 , 1 )
4745 end
48-
46+
4947 def update
5048 each do |obj |
5149 update_x obj
@@ -54,15 +52,15 @@ def update
5452 obj . y += obj . ydir
5553 end
5654 end
57-
55+
5856 def update_x ( obj )
5957 obj . x += obj . speed * obj . xdir
6058 return if ( 0 ..UNIT ) . cover? obj . x
6159 obj . xdir *= -1
6260 obj . x += obj . xdir
6361 obj . y += obj . ydir
6462 end
65-
63+
6664 def draw
6765 background ( 0 )
6866 fill ( 255 )
@@ -71,4 +69,3 @@ def draw
7169 end
7270 end
7371end
74-
0 commit comments