def redraw(self):
        self.canvas.delete(ALL)

        # Top message
        self.canvas.create_text(self.camera.width/2, 40, text=self.message, fill='white', font='Arial 24 bold')

        # Bottom message
        sol = self.sol
        lineWidth = 100
        margin = 15
        y = self.camera.height - margin - 20
        while len(sol) > 0:
            self.canvas.create_text(self.camera.width/2, 
                y, text=sol[-lineWidth:], fill='white', font='Courier 12')
            y -= margin
            sol = sol[:-lineWidth]

        # Progress bar
        if self.showingPB:
            w = (self.width * (self.moveIndex - self.pbMin + 1) / 
                    (max(1, self.pbMax - self.pbMin)))
            self.canvas.create_rectangle(0, self.height-20, w, self.height, fill='#00ff66')

        toDraw = [ ]

        for z in xrange(self.size):
            for y in xrange(self.size):
                for x in xrange(self.size):
                    try:
                        (pieceID, rotationKey) = self.state.state[z][y][x]
                    except:
                        pieceID = 1
                        rotationKey = 210

                    pieceCenter = self.center + self.pieceOffset(x, y, z)
                    outDirections = [d for d in Cube.directions if d**pieceCenter > 0]
                    sod = [ ] #sorted out directions
                    for od in outDirections:
                        if od // CubeState.keys[rotationKey / 100]:
                            sod.append(od)
                    for od in outDirections:
                        if od // CubeState.keys[(rotationKey / 10) % 10]:
                            sod.append(od)
                    for od in outDirections:
                        if od // CubeState.keys[rotationKey % 10]:
                            sod.append(od)

                    pieceRotation = Vector(0,0,0)
                    theta = 0.

                    if pieceID in self.rotatingValues:
                        oldCenter = pieceCenter
                        pieceOffset = pieceCenter - (pieceCenter > self.rotationAxis)
                        pieceRotation = self.rotationAxis * pieceOffset
                        theta = self.rotationDTheta * (self.maxRot - self.rotationCount)

                        if self.rotationDirection:
                            theta *= -1

                        pieceCenter = (pieceCenter > self.rotationAxis)
                        pieceCenter = pieceCenter + cos(theta) * pieceOffset
                        pieceCenter = pieceCenter + sin(theta) * pieceRotation

                    faceColors = Cube.faceColors[pieceID]
                    for direc, color in zip(sod, faceColors):
                        axes = ()
                        faceCenter = pieceCenter + (direc / 2)

                        if pieceID in self.rotatingValues:
                            if direc // self.rotationAxis:
                                faceCenter = pieceCenter + (direc / 2)
                                if self.rotationAxis // Vector(0,1,0):
                                    axis0temp = Vector(1,0,0)
                                else:
                                    axis0temp = Vector(0,1,0)
                                axis1temp = direc * axis0temp
                                axis0 = axis0temp * cos(theta) + axis1temp * sin(theta)
                                axis1 = axis0 * direc
                                axes = (axis0, axis1)
                            else:
                                perp = -1 * (direc * self.rotationAxis)
                                perp = perp ^ (direc.mag)
                                faceCenter = pieceCenter + (sin(theta) * (perp / 2) + 
                                                            cos(theta) * (direc / 2))
                                axis0 = self.rotationAxis
                                axis1 = (faceCenter - pieceCenter) * self.rotationAxis * 2
                                axes = (axis0, axis1)
                            
                        visible = (faceCenter - pieceCenter) ** (faceCenter - self.camera.pos) < 0
                        corners = self.corners(faceCenter, pieceCenter - faceCenter, *axes)
                        corners = [corner.flatten(self.camera) for corner in corners]
                        state = 'disabled' # if visible else 'hidden'
                        outline = '#888888' if visible else 'gray'
                        if not visible: color = 'gray'
                        a = 0 if visible else 1000
                        spec = (corners, color, state, outline)
                        toDraw.append(((pieceCenter-self.camera.pos).mag + a, spec))
                        #a = self.canvas.create_polygon(corners, fill=color, 
                        #                            width=2, state=state, outline='#888888'
                        #                            #,activewidth=4, activefill=darken(color)
                        #                            )
                        if self.debug:
                            self.canvas.create_text(faceCenter.flatten(self.camera), text=str(pieceID))

                        #if pieceCenter.mag() == 1:
                        #    b = CenterPiece(pieceCenter, self)
                        #    self.canvas.tag_bind(a, '<Button-1>', b.callback)

                        """
                        newCorners = ()
                        for corner in corners: newCorners += corner.flatten(self.camera)
                        if visible:
                            self.canvas.create_polygon(self.faces[(pieceID,color)], newCorners)
                        #self.canvas.itemconfig(self.faces[(pieceID,color)], state=state)
              
                        """

            toDraw.sort(lambda a,b: cmp(b,a))
            for polygon in toDraw:
                spec = polygon[1]
                (corners, color, state, outline) = spec
                self.canvas.create_polygon(corners, fill=color, width=2, state=state, outline=outline)

        self.drawHelp()
dataset/ETHPy150Open bluquar/cubr/cube.py/Cube.redraw/original