示例#1
0
    def render(self, cube, projection='default'):
        """ Render ourself. """
        colors = (None, 'red', 'green', 'blue', 'white', 'yellow', 'orange')

        normals = [(0, 0, 1), (-1, 0, 0), (1, 0, 0), (0, -1, 0), (0, 1, 0), (0, 0, -1)]
        offsets = [(0, 0), (-4, 0), (4, 0), (0, -4), (0, 4), (8, 0)]

        height, width = self.screen.getmaxyx()
        x_offset, y_offset = int(width/2) - 1, int(height/2) - 1

        if projection == 'default':
            normals = normals[:1]  # Only render the first normal

        for normal, offset in zip(normals, offsets):
            for sticker in cube.stickers:
                if sticker.is_visible(normal):
                    angle = algebra.angle_between_vectors(normal, self.view_normal)
                    perp = algebra.cross_product(normal, self.view_normal)

                    if perp != (0, 0, 0):
                        rotation_axis = perp.index(1) if 1 in perp else perp.index(-1)
                        sign = 1 if 1 in perp else -1
                        new_coords = algebra.rotation(sticker.coords, rotation_axis, theta=angle, sign=sign)
                        x, y, z = new_coords
                    else:
                        x, y, z = sticker.coords

                    i = int(x + x_offset + offset[0])
                    j = int(y + y_offset + offset[1])
                    pair_number = colors.index(sticker.color)
                    self.screen.attron(curses.color_pair(pair_number))
                    self.screen.addstr(j, i, u'\u2588'.encode(self.encoding))
                    self.screen.attroff(curses.color_pair(pair_number))
示例#2
0
 def rotate(self, axis, sign=1):
     """ Rotate this sticker in 3D space about the origin. """
     self.normal = algebra.rotation(self.normal, axis, sign=sign)
     self.coords = algebra.rotation(self.coords, axis, sign=sign)