'''Polygon superclass.'''
import turtle
import math

class Polygon(object):
    
    '''A regular polygon that can draw itself, starting from a
    given corner.
    '''

    def __init__(self, n, b, x, y):
        '''Create a regular n-gon with sides of length b, beginning
        from corner at x,y.
        '''
        self.sides = n
        self.base = b
        self.x = x
        self.y = y

    def get_params(self):
        '''Return a tuple (n, b, x, y) consisting of number of sides n,
        length of base b, horizontal coordinate of starting corner x,
        vertical component of starting corner y.
        '''

        return (self.sides, self.base, self.x, self.y)

    def draw(self):
        '''Draw this polygon starting at (x,y) in a counterclockwise
        direction.
        '''

        t = turtle.Turtle()
        t.setx(self.x)
        t.sety(self.y)
        t.showturtle()
        t.begin_fill()
        for s in range(self.sides):
            t.forward(self.base)
            t.left(360.0 / self.sides)
        t.end_fill()

    def area(self):
        return ((self.base)**2 * self.sides) / (4* math.tan(math.pi/self.sides))