Goal: Circumscribe a circle around a polygon.
repeat 1 + #sides [
t1, fd howbig
setpos ask "t1 [pos]
if touching? "t2 "t1 [pd]
t1, bk howbig rt 360 / #sides
t1, pu seth 0
repeat 360 [pu fd howbig rt 90 pd fd 1 bk 1 lt 90 pu bk howbig rt 1]
ask [t1 t2] [home seth 0]
This project draws a circle whose radius is howbig
. The radius is the same length as the distance from the center point to each vertex of the polygon. If the polygon is drawn with a thin line, the circle will appear to circumscribe it. (This means the circle surrounds the polygon, touching the point of each vertex.) If the lines are thick, the circle will pass through the middle of each thick vertex.
- Add an extra slider and name it circolor so that you can set the polygon and circle to two different colors.
- In the circle-a-polygon procedure, the method for drawing a circle is to build it dot by dot from the center point. The turtle starts at the center point and moves out to the edge of the circle with its pen up, then turns right 90 degrees, draws a line segment that is only one pixel long, turns left 90 degrees, puts its pen up again, backs up to the center point, and turns one degree. It repeats this process 360 times, drawing 360 tiny line segments to form a circle. If the radius of the circle is large, then the circle will appear dotted instead of solid. (If the howbig slider is set too high, some shapes drawn by the polygon procedure may wrap instead of forming regular polygons, and the turtle will not be able to circumscribe the shape. Set the howbig slider small enough to draw a regular polygon.)
Try different settings for howbig and howthick. (What happens to the circle if the polygon "wraps" beyond the project page border? What is the largest howbig setting that fits?)
Can you revise the circle-a-polygon procedure so that the circle is drawn with fewer line segments (perhaps 180 or 90 instead of 360)? What else do you need to adjust besides the repeat command?
On Your Own - Project Ideas
Can you revise the procedure so that the circle is drawn larger and does not touch the polygon at all?