
# I didn't have this prior to changing the class def below
#import wxTurtle
from wxTurtleCurves import turtleCurves

# wrapper for any additional drawing routines
# that need to know about each other
#class turtleCoat:        # I'm not even sure how this worked, but it did
class turtleCoat(turtleCurves):
    def square1(self, distance):
        self.polygon(4, distance)

    # just to be different, turn right instead of left
    def square2(self, distance):
        for i in range(4):
            self.forward(distance)
            self.right(90)

    def polygon(self, sides, distance):
        angle = 360.0 / sides
        for i in range(sides):
            self.forward(distance)
            self.left(angle)

#def drawMain(dc_local, w, rs=reset, turtleCoat=turtleCoat):
def drawMain(dc_local, w, turtleCoat=turtleCoat):
    t = turtleCoat(dc_local)
    t.color('blue')
    t.rDragon(3, 12)
    t.color('orange')
    t.cCurve(5, 10)
    t.color('black')
    t.square2(30)
    t.square1(100)
    t.polygon(6, 30)
    #print t._invradian
    #print t.angle
    
    # I would like to be able to call routines like square2 and polygon1
    # without having refer to the object if something like below
    # is possible?
    #def polygon(sides, distance): tc.polygon1(sides, distance)
    #polygon(3, 60)
    
    # I got this from chapter 4 of Learning Python, it seems to work
    # functions are just objects
    # so we create local objects that point to the methods of the object
    # this only works for the object, not the class in general, so a
    # different solution might be more appropriate
    square = t.square1
    polygon = t.polygon

    t.color('green')
    # test to see if we get a green square
    square(150)
    # this also shows some kind of truncation or rounding error
    # the top corners of the triangle are off by one pixel
    t.color('black')
    
    t.pu()
    t.home()
    t.lt(180)
    t.fd(200)
    t.rt(180)
    t.pd()
    t.color('blue')
    for i in range(5):
        polygon(5, 40)
        #t.polygon(5, 40)
        t.left(360.0 / 5)

    t2 = turtleCoat(dc_local)
    t2.color('red')
    t2.polygon(16, 10)

    t.color('blue')
    #t.forward(200)
    polygon(8, 80)

    # if this works correctly
    # the arcs will be different colors
    # so _goto has to be changed to set the pen characteristics
    # before drawing
    for i in range(18):
        #t.color('blue')
        t.forward(50)
        t.right(30)
        #t2.color('red')
        t2.fd(50)
        t2.rt(30)
        

"""
def drawMainOld(dc_local, w, rs=reset, square=_square, polygon=_polygon):
    #global dc
    #dc = dc_local
    #reset()
    rs()
    #cls()
    #'''
    pu()
    left(90)
    forward(200)
    right(90)
    pd()
    cCurve(3, 12)
    pu()
    home()
    pd()
    #'''
    cls()
    pu()
    rt(45)
    forward(150)
    lt(45)
    pd()
    rDragon(4, 13)
    pu()
    home()
    pd()
    # doing a square inline
    '''
    for i in range(4):
        fd(90)
        rt(90)
    '''
    #_square(150)   # this won't work since _square isn't in the namespace
    #square(150)
    color('blue')
    polygon(12, 60)
"""

# ulimately what would be nice is to be able to have an interactive
# prompt such as the Python shell >>> that you could just type turtle
# commands into line by line and see the results interactively
# but this comes close since you can simply change the text file
# while the program is running and then rerun the text file
# if you don't "cls()" prior to drawing then you'll still be able to
# see the previous results in the window
# one addition would be to try and detect whether a pen is already active
# and if so, then rather than doing a reset() you would simply leave the
# existing pen alone, so the current direction, x, y, color, etc. are not
# changed between runs
# keep in mind that the drawing is not saved in an offscreen bitmap though
# so any window overlaps are going to "erase" previous drawings

