
from tWrapper import tWrapper

# wrapper for any additional drawing routines
# that need to know about each other
class turtleCoat(tWrapper):
    def chaos1(self):
        autoRefreshTemp = self.canvas.autoRefresh
        self.canvas.autoRefresh = 0

        xOffset = 50
        yOffset = 0
        scale = 1
        r = 2.9
        # when r was 4.0 I got an exception when doing the int
        # conversion below, so I need to consider the appropriate
        # behaviour when x or y is out of bounds for an int
        # and also out of bounds of the current cliprect or frame
        steps = 400

        inc = (4.0 - 2.9) / steps
        for j in range(steps):
            r += inc
            x = 0.3
            y = j + 30
            for i in range(200):
                x = r * x * (1 - x)

            for i in range(300):
                x = r * x * (1 - x)
                x1 = int(500 * x)
                # originally self.plot(dc, x1, y1, xOffset, yOffset, scale)

                # the scale and offset stuff should probably
                # be part of the turtle or coordinate space
                x2 = int(xOffset + scale * x1)
                y2 = int(yOffset + scale * y)
                self.plot(x2, y2)
            self.canvas.refresh()

        self.canvas.autoRefresh = autoRefreshTemp


#def drawMain(dc_local, w, rs=reset, turtleCoat=turtleCoat):
def drawMain(dc_local, w, turtleCoat=turtleCoat):
    # chaos1 (Ctrl-1) takes 2.2 seconds versus 7.14 seconds in 
    # turns out the issue was setting the pen in wxPython (wxWindows)
    # DrawPoint versus 
    # so I turned on optimization in the init (self.dc.SetOptimization)
    # which shouldn't cause problems with this kind of app
    # note that the setting the pen still has some overhead, about
    # a 50% hit on my machine at 3.325 with the current pen setting
    # self.dc.SetPen(self._color)
    # however, setting the pen is required if there is going to be
    # more than one turtle active, so i may do a subclass that allows
    # multiple turtles, but forces the pen to be shared (maybe a class variable)
    # finally the pen is a hack right now and i'll have to have a slew of
    # routines and some kind of struct... to support pen width, line ending
    # stipple, etc.

    t = turtleCoat(dc_local)
    t.cls()
    t.chaos1()
