Beispiel #1
0
    def drawoutline(self, image, color):
        """Draws the outline of the cell over a color image."""
        if self._needs_refresh:
            self._refresh()

        draw_line(image, int(self._tail_left.x), int(self._tail_left.y),
                  int(self._head_left.x), int(self._head_left.y), color)
        draw_line(image, int(self._tail_right.x), int(self._tail_right.y),
                  int(self._head_right.x), int(self._head_right.y), color)

        r0 = self._head_right - self._head_center
        r1 = self._head_left - self._head_center
        t1 = atan2(r0.y, r0.x)
        t0 = atan2(r1.y, r1.x)
        draw_arc(image, self._head_center.x, self._head_center.y,
                 self._width / 2, t0, t1, color)

        r0 = self._tail_right - self._tail_center
        r1 = self._tail_left - self._tail_center
        t0 = atan2(r0.y, r0.x)
        t1 = atan2(r1.y, r1.x)
        draw_arc(image, self._tail_center.x, self._tail_center.y,
                 self._width / 2, t0, t1, color)
Beispiel #2
0
    def dirty(self):
        return self._dirty

    def clean(self):
        """Sets the dirty bit to false."""
        self._dirty = False
        
    def rotate_clockwise(self):
        """Rotating clockwise is the same as adding 1 (mod 6) to 
        each vertex in each edge of a cell."""
        for i in range(len(self.cell)):
            for j in range(2):
                self.cell[i][j] = (self.cell[i][j]+1) % 6
                
    def rotate_counterclockwise(self):
        """Rotating counterclockwise is the same as subtracting 1 (mod 6) to
        each vertex in each edge of a cell."""
        for i in range(len(self.cell)):
            for j in range(2):
                self.cell[i][j] = (self.cell[i][j]-1) % 6
                
    def draw(self, surface, (x, y), radius, outline_color=(0,0,0)):
        if self.dirty:
            #             blocked,     neutral,       p1,           p2
            colors = [(50, 50, 50), (180,133,63), (190,163,63), (205, 133, 93)]
            draw_hexagon(surface, x, y, radius, colors[self.ownership], outline_color)
            arc_color = (0,0,0)
            for p in self.cell:
                draw_arc(surface, x, y, radius, p, arc_color)
            self.clean()