@@ -17,6 +17,7 @@ def setup
1717 @c = rand ( 360 )
1818 @points = ( 0 ..2 ) . map { Point . new ( rand ( width ) , rand ( height ) ) }
1919 background 0
20+ ellipse_mode RADIUS
2021end
2122
2223def draw
@@ -35,19 +36,19 @@ def draw
3536 no_fill
3637 # verifies if there is a circle and draw it
3738 return if collinear ( @points [ 0 ] . pos , @points [ 1 ] . pos , @points [ 2 ] . pos )
38- draw_circle @points
39+ draw_circle * @points
3940end
4041
41- def draw_circle ( pts )
42+ def draw_circle ( a , b , c )
4243 # find the bisectors of 2 sides
4344 mp = [ ]
44- mp [ 0 ] = bisector ( pts [ 0 ] . pos , pts [ 1 ] . pos )
45- mp [ 1 ] = bisector ( pts [ 1 ] . pos , pts [ 2 ] . pos )
45+ mp << bisector ( a . pos , b . pos )
46+ mp << bisector ( b . pos , c . pos )
4647 center_point = center ( mp ) # find the center of the circle
4748 # calculate the radius
48- radius = center_point . dist ( pts [ 2 ] . pos )
49+ radius = center_point . dist ( c . pos )
4950 # if not collinear display circle
50- ellipse ( center_point . x , center_point . y , 2 * radius , 2 * radius )
51+ ellipse ( center_point . x , center_point . y , radius , radius )
5152end
5253
5354def bisector ( a , b )
@@ -102,7 +103,7 @@ def update
102103 @pos += velocity
103104 end
104105
105- def check_edges
106+ def check_edges # could be more sophisticated, eg reverse velocity
106107 pos . x = constrain ( pos . x , 0 , width )
107108 pos . y = constrain ( pos . y , 0 , height )
108109 end
0 commit comments