import turtle
from shape import Shape


class Triangle(Shape):
    '''
    Represents geometric equilaterial triangle aligned with
    axes.

    position: Inherited from Shape
    '''

    def __init__(self, x, y, b):
        ''' (Triangle, float, float, float) -> NoneType

        Initialize triangle self to location (x, y)
        and base b.
        '''
        Shape.__init__(self, x, y)
        self.base = b

    def draw(self, t):
        ''' (Triangle, Turtle) -> NoneType

        Draw triangle self on Turtle t.
        '''
        t.color('green')
        t.up() # tail up for moving
        t.goto(self.position)
        t.down() # tail down for drawing
        t.begin_fill()
        for i in range(3):
            t.forward(self.base)
            t.left(120)
        t.end_fill()

    def get_area(self):
        ''' (Triangle) -> float

        Return area of self.

        >>> t = Triangle(0, 0, 10)
        >>> abs(t.get_area() - 43.30127018922194) < 0.000001
        True
        >>>
        '''
        # area of an equilaterial triangle of base self.base
        return (self.base**2 * 3**(1/2)) / 4


if __name__ == '__main__':
    import doctest
    doctest.testmod()
    #tur = turtle.Turtle()
    #t = Triangle(0, 0, 20)
    #import square
    #s = square.Square(0, 0, 20)
    #shapes = [t, s]
    #for i in shapes:
        #for j in range(5):
            #i.position = (j * 10, j * 10)
            #i.draw(tur)


