1- # Stores and manipulates the path
1+ # Stores and manipulates the points
22class Path
3- attr_reader :path , :last , :bounds , :cut , :theta , :delta , :speed , :searches
3+ attr_reader :points , :last , :bounds , :cut , :theta , :delta , :speed , :searches
44
55 def initialize ( bounds , speed , delta , history )
66 @bounds = bounds
77 @speed = speed
88 @delta = delta
99 @theta = 0
10- @path = ( 0 ..history ) . map { bounds . centroid . copy }
10+ @points = ( 0 ..history ) . map { bounds . centroid . copy }
1111 @searches = 0
12- @last = Vec2D . new ( path . first )
12+ @last = Vec2D . new ( points . first )
1313 end
1414
1515 def grow
@@ -22,33 +22,27 @@ def grow
2222 end
2323
2424 def move
25- @last = path . first
26- path . pop
25+ @last = points . first
26+ points . pop
2727 @theta += delta
28- path . unshift last + Vec2D . new ( speed * Math . cos ( theta ) , speed * Math . sin ( theta ) )
28+ points . unshift last + Vec2D . new ( speed * Math . cos ( theta ) , speed * Math . sin ( theta ) )
2929 @searches = 0
3030 end
3131
3232 def search
3333 @theta += delta
34- path [ 0 ] = last + Vec2D . new ( speed * Math . cos ( theta ) , speed * Math . sin ( theta ) )
34+ points [ 0 ] = last + Vec2D . new ( speed * Math . cos ( theta ) , speed * Math . sin ( theta ) )
3535 @searches += 1
3636 end
3737
38- def render ( gfx , renderer )
39- gfx . begin_shape
40- path . map { |vec | vec . to_curve_vertex ( renderer ) }
41- gfx . end_shape
42- end
43-
4438 def intersecting?
45- return true unless bounds . contains? ( path . first )
39+ return true unless bounds . contains? ( points . first )
4640
4741 if searches < 100
48- a = Line2D . new ( path [ 0 ] , path [ 1 ] )
49- ( 3 ...path . length ) . each do |i |
50- b = Line2D . new ( path [ i ] , path [ i - 1 ] )
51- return true if a . intersecting? ( b )
42+ one = Line2D . new ( points [ 0 ] , points [ 1 ] )
43+ ( 3 ...points . length ) . each do |idx |
44+ two = Line2D . new ( points [ idx ] , points [ idx - 1 ] )
45+ return true if one . intersecting? ( two )
5246 end
5347 end
5448 false
0 commit comments