#!/usr/bin/python2.6 -tt
# Copyright 2011 Kyle Fitzsimmons, All Rights Reserved.
from TurtleWorld import *
from polygon import *
import math
def draw_pie(t, pieces, length):
"""Draw a polygonal pie given the number of slices and slice (side)length
with a (t)urtle"""
center_angle = 360 / pieces
side_angles = 180 - ((180 - center_angle) / 2)
for piece in range(pieces):
draw_piece(t, side_angles, length, center_angle)
rt(t, 180)
def draw_piece(t, side_angles, length, center_angle):
'''Function for determining the specifics of the triangle slices used to comprise the pie.
The center_angle variable is simply passed through to base_length().'''
base = base_length(length, center_angle)
print center_angle, side_angles, base
fd(t, length)
lt(t, side_angles)
fd(t, base)
lt(t, side_angles)
fd(t, length)
def base_length(length, center_angle):
'''Function that determines the base length of the pie slice from the side length and
center angle.'''
base = round(math.sin(math.radians(center_angle / 2)) * length * 2)
return int(base)
def main():
# Initiate GUI
world = TurtleWorld()
bob = Turtle()
bob.delay = .01
# User input
pieces = 8
side_length = 100
draw_pie(bob, pieces, side_length)
wait_for_user()
# This is the standard boilerplate that calls the main() function
if __name__ == '__main__':
main()