from wxPython.wx       import *
from wxPython.glcanvas import *

from OpenGL.GL import *
from OpenGL.GLU import *
from OpenGL.GLUT import *
from string import split
from Numeric import *

#----------------------------------------------------------------------
   
class MyCanvasBase(wxGLCanvas):
    def __init__(self, parent):
        wxGLCanvas.__init__(self, parent, -1)
        self.prt = parent
        self.init = false
        self.names = (100,)
        self.PosVaz = 0

        self.dic = {27:(0,3), 36:(0,4), 45:(0,5), 28:(1,3), 37:(1,4), 46:(1,5), 29:(2,3), 38:(2,4), 47:(2,5),
                    3:(3,0), 12:(3,1), 21:(3,2), 30:(3,3), 39:(3,4), 48:(3,5), 57:(3,6), 66:(3,7), 75:(3,8),
                    4:(4,0), 13:(4,1), 22:(4,2), 31:(4,3), 40:(4,4), 49:(4,5), 58:(4,6), 67:(4,7), 76:(4,8),
                    5:(5,0), 14:(5,1), 23:(5,2), 32:(5,3), 41:(5,4), 50:(5,5), 59:(5,6), 68:(5,7), 77:(5,8),
                    33:(6,3), 42:(6,4), 51:(6,5), 34:(7,3), 43:(7,4), 52:(7,5), 35:(8,3), 44:(8,4), 53:(8,5)}

        self.tab = array([[-1,-1,-1,27,36,45,-1,-1,-1],
                          [-1,-1,-1,28,37,46,-1,-1,-1],
                          [-1,-1,-1,29,38,47,-1,-1,-1],
                          [3,12,21,30,39,48,57,66,75],
                          [4,13,22,31,40,49,58,67,76],
                          [5,14,23,32,41,50,59,68,77],
                          [-1,-1,-1,33,42,51,-1,-1,-1],
                          [-1,-1,-1,34,43,52,-1,-1,-1],
                          [-1,-1,-1,35,44,53,-1,-1,-1]])
        
        self.pin = array([[-1,-1,-1,1,1,1,-1,-1,-1],
                          [-1,-1,-1,1,1,1,-1,-1,-1],
                          [-1,-1,-1,1,1,1,-1,-1,-1],
                          [ 1, 1, 1,1,1,1, 1, 1, 1],
                          [ 1, 1, 1,1,0,1, 1, 1, 1],
                          [ 1, 1, 1,1,1,1, 1, 1, 1],
                          [-1,-1,-1,1,1,1,-1,-1,-1],
                          [-1,-1,-1,1,1,1,-1,-1,-1],
                          [-1,-1,-1,1,1,1,-1,-1,-1]])

        EVT_SIZE(self, self.OnSize)
        EVT_PAINT(self, self.OnPaint)
        EVT_KEY_DOWN(self, self.OnGlplotscKeyDown)
        EVT_LEFT_DOWN(self, self.OnLeftDown)
        EVT_LEFT_UP(self, self.OnLeftUp)

    def OnSize(self, event):
        self.size = self.GetClientSize()
        if self.GetContext():
            self.SetCurrent()
            glViewport(0, 0, self.size.width, self.size.height)

    def OnPaint(self, event):
        dc = wxPaintDC(self)
        self.SetCurrent()
        if not self.init:
            self.InitGL()
            self.init = true
        self.OnDraw()

    def OnLeftDown(self, evt):
        self.x, self.y = evt.GetPosition()
        if not(self.PosVazia(self.x, self.y)):
            try:
                self.Pos_Ant = self.dic[self.names[0]]
            except:
                self.Pos_Ant = (-1,-1)
            
    def OnLeftUp(self, evt):
        self.x, self.y = evt.GetPosition()
        if self.PosVazia(self.x, self.y) and self.Pos_Ant <> (-1,-1):
            try:
                self.Pos_Atu = self.dic[self.names[0]]
            except:
                return
            self.pin = self.DefJogada(self.Pos_Ant, self.Pos_Atu, self.pin)
            self.OnDraw()
            if sum(sum(self.pin)) == -35: #devido aos -1s da matriz de pinos
                dlg = wxMessageDialog(self.prt,'Parabéns! Você venceu!','Parabéns!!!', wxOK | wxICON_INFORMATION)
                dlg.ShowModal()
                dlg.Destroy()
                self.names = (100,)
                self.PosVaz = 0
                self.pin = array([[-1,-1,-1,1,1,1,-1,-1,-1],
                                  [-1,-1,-1,1,1,1,-1,-1,-1],
                                  [-1,-1,-1,1,1,1,-1,-1,-1],
                                  [ 1, 1, 1,1,1,1, 1, 1, 1],
                                  [ 1, 1, 1,1,0,1, 1, 1, 1],
                                  [ 1, 1, 1,1,1,1, 1, 1, 1],
                                  [-1,-1,-1,1,1,1,-1,-1,-1],
                                  [-1,-1,-1,1,1,1,-1,-1,-1],
                                  [-1,-1,-1,1,1,1,-1,-1,-1]])
                self.OnDraw()
            
    def OnGlplotscKeyDown(self, evt):
        self.keyboard(evt.KeyCode())
        
# #############################################################################################
# #############################################################################################
class glPlotCanvas(MyCanvasBase):

    def InitGL(self):

        glClearColor(1.0, 1.0, 0.9, 0.0) # Define a cor do clear()
        glClear(GL_COLOR_BUFFER_BIT)     # Limpa o buffer
        glEnable(GL_DEPTH_TEST)          # Coloca um numero tao distante quanto possivel no zbuffer  
        glDepthFunc(GL_ALWAYS)           # Define a utilizacao do zbuffer
        glMatrixMode(GL_PROJECTION)      # Define MT como Matriz Porjecao
        glLoadIdentity()                 # matriz transformacao = identidade
        glOrtho(-50, 50, -50, 50, -100, 100) # Define volume de visualizacao
        
        glMatrixMode(GL_MODELVIEW)       # Define MT como Modelo de Visualizacao   
        glLoadIdentity()                
        glRotatef(-50.0,1.0,0.0,0.0)
        glRotatef(45.0,0.0,0.0,1.0)
        self.InitLight()
   
    def InitLight(self):
        glShadeModel (GL_SMOOTH)
        glEnable(GL_LIGHTING)
        
        glLightfv(GL_LIGHT0, GL_POSITION, [20.0,20.0,10.0,1.0])
        
        glLightfv(GL_LIGHT0, GL_AMBIENT, [0.0,0.0,0.0,1.0])
        glLightfv(GL_LIGHT0, GL_DIFFUSE, [1.0,1.0,1.0,1.0])
        glLightfv(GL_LIGHT0, GL_SPECULAR, [0.7,0.7,0.7,1.0])
        glEnable(GL_LIGHT0)

        glLightfv(GL_LIGHT1, GL_POSITION, [20.0,-20.0,10.0,1.0])
        glLightfv(GL_LIGHT1, GL_AMBIENT, [0.0,0.0,0.0,1.0])
        glLightfv(GL_LIGHT1, GL_DIFFUSE, [1.0,1.0,1.0,1.0])
        glLightfv(GL_LIGHT1, GL_SPECULAR, [0.7,0.7,0.7,1.0])
        glEnable(GL_LIGHT1)

        glLightfv(GL_LIGHT2, GL_POSITION, [-20.0,20.0,10.0,1.0])
        glLightfv(GL_LIGHT2, GL_AMBIENT, [0.0,0.0,0.0,1.0])
        glLightfv(GL_LIGHT2, GL_DIFFUSE, [1.0,1.0,1.0,1.0])
        glLightfv(GL_LIGHT1, GL_SPECULAR, [0.7,0.7,0.7,1.0])
        glEnable(GL_LIGHT2)

        glLightfv(GL_LIGHT3, GL_POSITION, [-20.0,-20.0,10.0,1.0])
        glLightfv(GL_LIGHT3, GL_AMBIENT, [0.0,0.0,0.0,1.0])
        glLightfv(GL_LIGHT3, GL_DIFFUSE, [1.0,1.0,1.0,1.0])
        glLightfv(GL_LIGHT1, GL_SPECULAR, [0.7,0.7,0.7,1.0])
        glEnable(GL_LIGHT3)


    
        glEnable(GL_COLOR_MATERIAL)
        glColorMaterial(GL_FRONT, GL_DIFFUSE)
        
        
    def DefJogada(self, pos_ant, pos_atu, conf):
        if conf[pos_atu] <> 0 or conf[pos_ant] <> 1:
            return conf
        if abs(pos_atu[0]-pos_ant[0]) == 0 and abs(pos_atu[1]-pos_ant[1]) == 2:
            if pos_atu[1] > pos_ant[1]:
                if conf[pos_atu[0],pos_atu[1] - 1] == 1:
                    conf[pos_ant] = 0
                    conf[pos_atu] = 1
                    conf[pos_atu[0],pos_atu[1]-1] = 0
            else:
                if conf[pos_atu[0],pos_atu[1] + 1] == 1:
                    conf[pos_ant] = 0
                    conf[pos_atu] = 1
                    conf[pos_atu[0],pos_atu[1]+1] = 0
        elif abs(pos_atu[0]-pos_ant[0]) == 2 and abs(pos_atu[1]-pos_ant[1]) == 0:
            if pos_atu[0] > pos_ant[0]:
                if conf[pos_atu[0] - 1,pos_atu[1]] == 1:
                    conf[pos_ant] = 0
                    conf[pos_atu] = 1
                    conf[pos_atu[0]-1,pos_atu[1]] = 0
            else:
                if conf[pos_atu[0] + 1,pos_atu[1]] == 1:
                    conf[pos_ant] = 0
                    conf[pos_atu] = 1
                    conf[pos_atu[0]+1,pos_atu[1]] = 0

        return conf

    def PosVazia(self, x, y):
        viewport = glGetIntegerv(GL_VIEWPORT)

        glSelectBuffer (512)
        glRenderMode (GL_SELECT)
    
        glInitNames()
        glPushName(0)
    
        glMatrixMode (GL_PROJECTION)
        glPushMatrix ()
        glLoadIdentity ()
        gluPickMatrix (x,(viewport[3] - y), 5.0, 5.0, viewport)
        glOrtho(-50, 50, -50, 50, -100, 100)
        self.DrawPos(GL_SELECT)

        glMatrixMode(GL_PROJECTION)
        glPopMatrix()
        glFlush()
        self.names = (100,)
        hits = glRenderMode (GL_RENDER)
        for hit_record in hits:
            min_depth, max_depth, self.names = hit_record

        self.OnDraw()
        
        return not(self.PosVaz)
    
    def DrawPin(self):
        
        s = shape(self.pin)
        ind = indices(s)
        ind = ind*6.0 - 24.0
        glPolygonMode(GL_FRONT, GL_FILL)
        
        for i in range(s[0]):
            for j in range(s[1]):
               
                if self.pin[i,j] > 0:
                    cx, cy = ind[0,i,j], ind[1,i,j]
                    
                    glColor4f (0.7, 0.0, 0.0, 1.0)   
                    glMaterialfv(GL_FRONT, GL_DIFFUSE, [0.7, 0.0, 0.0, 1.0])
                    glMaterialfv(GL_FRONT, GL_SPECULAR, [0.7, 0.0, 0.0, 1.0])
                    glMaterialf(GL_FRONT, GL_SHININESS, 25.0)
                    if self.tab[i,j]*self.pin[i,j] == self.names[0]:
                        self.PosVaz = 1
                        glColor4f (1.0, 0.0, 0.0, 0.3)
                        glMaterialfv(GL_FRONT, GL_DIFFUSE, [0.95, 0.7, 0.7, 1.0])
                        glMaterialfv(GL_FRONT, GL_SPECULAR, [0.95, 0.7, 0.7, 1.0])
                        glMaterialf(GL_FRONT, GL_SHININESS, 25.0)
                    
                    glBegin(GL_POLYGON)
                    glVertex3f(cx + 1.5, cy + 1.5, 6.5)
                    glVertex3f(cx - 1.5, cy + 1.5, 6.5)
                    glVertex3f(cx - 1.5, cy - 1.5, 6.5)
                    glVertex3f(cx + 1.5, cy - 1.5, 6.5)
                    glEnd()
                    glBegin(GL_POLYGON)
                    glVertex3f(cx + 1.5, cy + 1.5, 6.5)
                    glVertex3f(cx + 1.5, cy + 1.5, 3.0)
                    glVertex3f(cx - 1.5, cy + 1.5, 3.0)
                    glVertex3f(cx - 1.5, cy + 1.5, 6.5)
                    glEnd()
                    glBegin(GL_POLYGON)
                    glVertex3f(cx - 1.5, cy + 1.5, 6.5)
                    glVertex3f(cx - 1.5, cy + 1.5, 3.0)
                    glVertex3f(cx - 1.5, cy - 1.5, 3.0)
                    glVertex3f(cx - 1.5, cy - 1.5, 6.5)
                    glEnd()
                    glBegin(GL_POLYGON)
                    glVertex3f(cx - 1.5, cy - 1.5, 6.5)
                    glVertex3f(cx - 1.5, cy - 1.5, 3.0)
                    glVertex3f(cx + 1.5, cy - 1.5, 3.0)
                    glVertex3f(cx + 1.5, cy - 1.5, 6.5)
                    glEnd()
                    glBegin(GL_POLYGON)
                    glVertex3f(cx + 1.5, cy - 1.5, 6.5)
                    glVertex3f(cx + 1.5, cy - 1.5, 3.0)
                    glVertex3f(cx + 1.5, cy + 1.5, 3.0)
                    glVertex3f(cx + 1.5, cy + 1.5, 6.5)
                    glEnd()
                    
    def DrawPos(self, mode):
        s = shape(self.tab)
        ind = indices(s)
        ind = ind*6.0 - 24.0
        self.PosVaz = 0
        for i in range(s[0]):
            for j in range(s[1]):
               
                if self.tab[i,j] > 0:
                    
                    cx, cy = ind[0,i,j], ind[1,i,j]

                    glColor4f (1.0, 1.0, 0.0, 1.0)
                    glMaterialfv(GL_FRONT, GL_DIFFUSE, [1.0, 1.0, 0.0, 1.0])
                    glMaterialfv(GL_FRONT, GL_AMBIENT, [1.0, 1.0, 0.0, 1.0])
                    glMaterialf(GL_FRONT, GL_SHININESS, 25.0)
                    
                    glLoadName(i+(9*j))
                    
                    glPolygonMode(GL_FRONT, GL_FILL)                    
                    glBegin(GL_POLYGON)
                    glVertex3f(cx + 2.8, cy + 2.8, 3.1)
                    glVertex3f(cx - 2.8, cy + 2.8, 3.1)
                    glVertex3f(cx - 2.8, cy - 2.8, 3.1)
                    glVertex3f(cx + 2.8, cy - 2.8, 3.1)
                    glEnd()
                    
    def DrawTab(self):
        # clear color and depth buffers
        glClear (GL_COLOR_BUFFER_BIT)
        glColor3f (0.0, 0.0, 0.9)
        glMaterialfv(GL_FRONT, GL_DIFFUSE, [0.0, 0.0, 0.9, 1.0])
        glMaterialfv(GL_FRONT, GL_AMBIENT, [0.0, 0.0, 0.9, 1.0])
        glMaterialf(GL_FRONT, GL_SHININESS, 25.0)
        glPolygonMode(GL_FRONT, GL_FILL)
        
        #Tabuleiro
        #parte de cima
        glBegin(GL_POLYGON)
        glVertex3f(30.0, 30.0, 3.0)
        glVertex3f(-30.0, 30.0, 3.0)
        glVertex3f(-30.0, -30.0, 3.0)
        glVertex3f(30.0, -30.0, 3.0)
        glEnd()
        #parte de baixo
        glBegin(GL_POLYGON)
        glVertex3f(34.0, 34.0, -3.0)
        glVertex3f(34.0, -34.0, -3.0)
        glVertex3f(-34.0, -34.0, -3.0)
        glVertex3f(-34.0, 34.0, -3.0)
        glEnd()
        #lateral de baixo inclinada
        glColor3f (0.0, 0.0, 0.7)
        glBegin(GL_POLYGON)
        glVertex3f(30.0, -30.0, 3.0)
        glVertex3f(-30.0, -30.0, 3.0)
        glVertex3f(-34.0, -34.0, 0.0)
        glVertex3f(34.0, -34.0, 0.0)
        glEnd()
        #lateral de baixo reta
        glColor3f (0.0, 0.0, 0.5)
        glBegin(GL_POLYGON)
        glVertex3f(34.0, -34.0, 0.0)
        glVertex3f(-34.0, -34.0, 0.0)
        glVertex3f(-34.0, -34.0, -3.0)
        glVertex3f(34.0, -34.0, -3.0)
        glEnd()
        #lateral esquerda inclinada
        glColor3f (0.0, 0.0, 0.7)
        glBegin(GL_POLYGON)
        glVertex3f(-30.0, -30.0, 3.0)
        glVertex3f(-30.0, 30.0, 3.0)
        glVertex3f(-34.0, 34.0, 0.0)
        glVertex3f(-34.0, -34.0, 0.0)
        glEnd()
        #lateral esquerda reta
        glColor3f (0.0, 0.0, 0.5)
        glBegin(GL_POLYGON)
        glVertex3f(-34.0, -34.0, 0.0)
        glVertex3f(-34.0, 34.0, 0.0)
        glVertex3f(-34.0, 34.0, -3.0)
        glVertex3f(-34.0, -34.0, -3.0)
        glEnd()
        #lateral de cima inclinada
        glColor3f (0.0, 0.0, 0.7)
        glBegin(GL_POLYGON)
        glVertex3f(30.0, 30.0, 3.0)
        glVertex3f(34.0, 34.0, 0.0)
        glVertex3f(-34.0, 34.0, 0.0)
        glVertex3f(-30.0, 30.0, 3.0)
        glEnd()
        #lateral de cima reta
        glBegin(GL_POLYGON)
        glColor3f (0.0, 0.0, 0.5)
        glVertex3f(34.0, 34.0, 0.0)
        glVertex3f(34.0, 34.0, -3.0)
        glVertex3f(-34.0, 34.0, -3.0)
        glVertex3f(-34.0, 34.0, 0.0)
        glEnd()
        #lateral direita inclinada
        glColor3f (0.0, 0.0, 0.7)
        glBegin(GL_POLYGON)
        glVertex3f(30.0, 30.0, 3.0)
        glVertex3f(30.0, -30.0, 3.0)
        glVertex3f(34.0, -34.0, 0.0)
        glVertex3f(34.0, 34.0, 0.0)
        glEnd()
        #lateral direita reta
        glColor3f (0.0, 0.0, 0.5)
        glBegin(GL_POLYGON)
        glVertex3f(34.0, 34.0, 0.0)
        glVertex3f(34.0, -34.0, 0.0)
        glVertex3f(34.0, -34.0, -3.0)
        glVertex3f(34.0, 34.0, -3.0)
        glEnd()
           
    def OnDraw(self):
        self.DrawTab()
        self.DrawPos(GL_RENDER)
        self.DrawPin()
        self.SwapBuffers()
        
    def keyboard (self, key):
        if (key == 327): #tecla "1"
            self.names = (100,)
            self.PosVaz = 0
            self.pin = array([[-1,-1,-1,0,0,0,-1,-1,-1],
                              [-1,-1,-1,0,0,0,-1,-1,-1],
                              [-1,-1,-1,0,1,0,-1,-1,-1],
                              [0,0,0,1,1,1,0,0,0],
                              [0,0,0,0,1,0,0,0,0],
                              [0,0,0,0,1,0,0,0,0],
                              [-1,-1,-1,0,0,0,-1,-1,-1],
                              [-1,-1,-1,0,0,0,-1,-1,-1],
                              [-1,-1,-1,0,0,0,-1,-1,-1]])
            self.InitGL()
            self.OnDraw()
        elif (key == 334): #tecla 2
            self.names = (100,)
            self.PosVaz = 0
            self.pin = array([[-1,-1,-1,0,0,0,-1,-1,-1],
                              [-1,-1,-1,0,0,0,-1,-1,-1],
                              [-1,-1,-1,0,1,0,-1,-1,-1],
                              [0,0,0,0,1,0,0,0,0],
                              [0,0,1,1,1,1,1,0,0],
                              [0,0,0,0,1,0,0,0,0],
                              [-1,-1,-1,0,1,0,-1,-1,-1],
                              [-1,-1,-1,0,0,0,-1,-1,-1],
                              [-1,-1,-1,0,0,0,-1,-1,-1]])
            self.InitGL()
            self.OnDraw()
        elif (key == 329): #tecla "3"
            self.names = (100,)
            self.PosVaz = 0
            self.pin = array([[-1,-1,-1,1,1,1,-1,-1,-1],
                              [-1,-1,-1,1,1,1,-1,-1,-1],
                              [-1,-1,-1,1,1,1,-1,-1,-1],
                              [0,0,0,1,1,1,0,0,0],
                              [0,0,0,1,0,1,0,0,0],
                              [0,0,0,0,0,0,0,0,0],
                              [-1,-1,-1,0,0,0,-1,-1,-1],
                              [-1,-1,-1,0,0,0,-1,-1,-1],
                              [-1,-1,-1,0,0,0,-1,-1,-1]])
            self.InitGL()
            self.OnDraw()

        elif (key == 330): #tecla 4
            self.names = (100,)
            self.PosVaz = 0
            self.pin = array([[-1,-1,-1,0,0,0,-1,-1,-1],
                              [-1,-1,-1,0,1,0,-1,-1,-1],
                              [-1,-1,-1,1,1,1,-1,-1,-1],
                              [0,0,1,1,1,1,1,0,0],
                              [0,1,1,1,1,1,1,1,0],
                              [1,1,1,1,1,1,1,1,1],
                              [-1,-1,-1,0,0,0,-1,-1,-1],
                              [-1,-1,-1,0,0,0,-1,-1,-1],
                              [-1,-1,-1,0,0,0,-1,-1,-1]])
            self.InitGL()
            self.OnDraw()
        elif (key == 332): #tecla 6
            self.names = (100,)
            self.PosVaz = 0
            self.pin = array([[-1,-1,-1,0,0,0,-1,-1,-1],
                              [-1,-1,-1,0,1,0,-1,-1,-1],
                              [-1,-1,-1,1,1,1,-1,-1,-1],
                              [0,0,1,1,1,1,1,0,0],
                              [0,0,0,0,1,0,0,0,0],
                              [0,0,0,0,1,0,0,0,0],
                              [-1,-1,-1,0,1,0,-1,-1,-1],
                              [-1,-1,-1,1,1,1,-1,-1,-1],
                              [-1,-1,-1,1,1,1,-1,-1,-1]])
            self.InitGL()
            self.OnDraw()
        elif (key == 333): #tecla "7"
            self.names = (100,)
            self.PosVaz = 0
            self.pin = array([[-1,-1,-1,0,0,0,-1,-1,-1],
                              [-1,-1,-1,0,1,0,-1,-1,-1],
                              [-1,-1,-1,1,1,1,-1,-1,-1],
                              [0,0,1,1,1,1,1,0,0],
                              [0,0,0,1,1,1,0,0,0],
                              [0,0,1,1,1,1,1,0,0],
                              [-1,-1,-1,1,1,1,-1,-1,-1],
                              [-1,-1,-1,0,1,0,-1,-1,-1],
                              [-1,-1,-1,0,0,0,-1,-1,-1]])
            self.InitGL()
            self.OnDraw()
        elif (key == 328): #tecla 8
            self.names = (100,)
            self.PosVaz = 0
            self.pin = array([[-1,-1,-1,0,0,0,-1,-1,-1],
                              [-1,-1,-1,0,1,0,-1,-1,-1],
                              [-1,-1,-1,1,1,1,-1,-1,-1],
                              [0,0,1,1,1,1,1,0,0],
                              [0,1,1,1,0,1,1,1,0],
                              [0,0,1,1,1,1,1,0,0],
                              [-1,-1,-1,1,1,1,-1,-1,-1],
                              [-1,-1,-1,0,1,0,-1,-1,-1],
                              [-1,-1,-1,0,0,0,-1,-1,-1]])
            self.InitGL()
            self.OnDraw()
        elif (key == 335): #tecla "9"
            self.names = (100,)
            self.PosVaz = 0
            self.pin = array([[-1,-1,-1,0,0,0,-1,-1,-1],
                              [-1,-1,-1,0,0,0,-1,-1,-1],
                              [-1,-1,-1,0,0,0,-1,-1,-1],
                              [0,0,0,0,0,0,0,0,0],
                              [0,0,0,0,0,0,0,0,0],
                              [0,0,0,0,0,0,0,0,0],
                              [-1,-1,-1,0,0,0,-1,-1,-1],
                              [-1,-1,-1,0,1,1,-1,-1,-1],
                              [-1,-1,-1,0,1,1,-1,-1,-1]])
            self.InitGL()
            self.OnDraw()
        elif (key == 331 or key == 83): #Redesenha o objeto em sua posição original - s ou S
            self.names = (100,)
            self.PosVaz = 0
            self.pin = array([[-1,-1,-1,1,1,1,-1,-1,-1],
                              [-1,-1,-1,1,1,1,-1,-1,-1],
                              [-1,-1,-1,1,1,1,-1,-1,-1],
                              [1,1,1,1,1,1,1,1,1],
                              [1,1,1,1,0,1,1,1,1],
                              [1,1,1,1,1,1,1,1,1],
                              [-1,-1,-1,1,1,1,-1,-1,-1],
                              [-1,-1,-1,1,1,1,-1,-1,-1],
                              [-1,-1,-1,1,1,1,-1,-1,-1]])
            self.InitGL()
            self.OnDraw()
            
# #################################################################################
# #################################################################################
# #################################################################################

class BoaApp(wxApp):

    def OnInit(self):
        global filename
        self.frame = wxFrame(None, -1, "Trabalho de Computação Gráfica - UNICAMP", wxDefaultPosition, wxSize(700,700))
        win = glPlotCanvas(self.frame)
        self.frame.Show(TRUE)
        
        self.SetTopWindow(self.frame)
        return true
    
def main():
    application = BoaApp(0)
    application.MainLoop()

if __name__ == '__main__':
    main()
