def __init__(self, screen):
     sprite.Sprite.__init__(self)
     self.image = surface.Surface(screen)
     self.image.fill((255, 255, 255))
     self.rect = self.image.get_rect()
     self.playButton = surface.Surface(
         [int(screen[1] * 0.5), int(screen[1] * 0.5)])
     self.playButton.fill(Color("white"))
     rect = self.playButton.get_rect()
     rect.center = self.rect.center
     draw.circle(self.playButton, Color("yellow"), [
         int(self.playButton.get_width() / 2),
         int(self.playButton.get_width() / 2)
     ], int(self.playButton.get_width() / 2))
     rect = self.playButton.get_size()
     rect = Rect([(int(rect[0] * 0.25), int(rect[1] * 0.35)),
                  (int(rect[0] * 0.5), int(rect[1] * 0.3))])
     # rect = (self.rect.centerx, int(screen[1]*0.5*0.25), self.rect.centery, int(screen[1]*0.5*0.15))
     # rect = Rect(rect[0]-rect[1], rect[2]-rect[3], rect[1]*2, rect[3]*2)
     draw.polygon(self.playButton, Color("orange"), [
         rect.topleft, (rect.x + 0.25 * rect.w, rect.centery),
         rect.bottomleft, rect.midright
     ])
     self.image.blit(
         self.playButton,
         tuple(
             map(lambda val: int(val - self.playButton.get_width() / 2),
                 self.rect.center)))
     del rect
     self.complete = True
     self.actualizar = False
     self.code = 1
Beispiel #2
0
 def test_color_validation(self):
     surf = pygame.Surface((10, 10))
     colors = 123456, (1, 10, 100), RED # but not '#ab12df' or 'red' ...
     points = ((0, 0), (1, 1), (1, 0))
     # 1. valid colors
     for col in colors:
         draw.line(surf, col, (0, 0), (1, 1))
         draw.aaline(surf, col, (0, 0), (1, 1))
         draw.aalines(surf, col, True, points)
         draw.lines(surf, col, True, points)
         draw.arc(surf, col, pygame.Rect(0, 0, 3, 3), 15, 150)
         draw.ellipse(surf, col, pygame.Rect(0, 0, 3, 6), 1)
         draw.circle(surf, col, (7, 3), 2)
         draw.polygon(surf, col, points, 0)
     # 2. invalid colors
     for col in ('invalid', 1.256, object(), None, '#ab12df', 'red'):
         with self.assertRaises(TypeError):
             draw.line(surf, col, (0, 0), (1, 1))
         with self.assertRaises(TypeError):
             draw.aaline(surf, col, (0, 0), (1, 1))
         with self.assertRaises(TypeError):
             draw.aalines(surf, col, True, points)
         with self.assertRaises(TypeError):
             draw.lines(surf, col, True, points)
         with self.assertRaises(TypeError):
             draw.arc(surf, col, pygame.Rect(0, 0, 3, 3), 15, 150)
         with self.assertRaises(TypeError):
             draw.ellipse(surf, col, pygame.Rect(0, 0, 3, 6), 1)
         with self.assertRaises(TypeError):
             draw.circle(surf, col, (7, 3), 2)
         with self.assertRaises(TypeError):
             draw.polygon(surf, col, points, 0)
Beispiel #3
0
    def prepare_text(self):
        """
        Рисует буквы с переливающимся цветом
        :return:
        """

        # Рисуем полоски (параллелограммы)
        for strip in range(self.num_strips):
            x_coord = (strip * self.len_of_strip + self.position) % (
                self.len_of_strip * self.num_strips) - self.len_of_strip
            coords = ((x_coord,
                       0), (x_coord - self.height_of_strip * cos(pi / 4),
                            self.height_of_strip),
                      (x_coord + self.len_of_strip -
                       self.height_of_strip * cos(pi / 4),
                       self.height_of_strip), (x_coord + self.len_of_strip, 0))
            polygon(self.camera_surface, self.colors[strip % len(self.colors)],
                    coords)

        # Вырезаем буквы
        self.camera_surface.blit(self.text_surface, (0, 0))

        # Делаем прозрачным то, что нужно
        # удалив это строчку, можно накинуть 20 фпс
        self.camera_surface.set_colorkey((1, 1, 1))
def house(x, y, scale=1.0):
    """function draws a house with (x, y) coordinates of top left corner"""
    width = int(220 * scale)
    height = int(130 * scale)
    windows(x, y, width, height)
    top_windows(x, y, width, height)
    vertical_beams(x, y, width, height, scale)
    tubes(x, y, width, height)
    d.rect(screen, brown, (x, y, width, height))
    d.rect(screen, dark_gray,
           (x - int(20 * scale), y + 5, int(width + 40 * scale), height // 8))
    d.rect(screen, dark_gray, (x - int(20 * scale), y + 5 - height // 4,
                               int(width + 40 * scale), height // 12))
    d.rect(screen, dark_gray, (x, y - height, width, height // 6))
    d.polygon(screen, dark_gray,
              ((x - int(30 * scale), y - height + height // 6),
               (x, y - height + height // 6), (x, y - height)))
    d.polygon(screen, dark_gray,
              ((x + width + int(30 * scale), y - height + height // 6),
               (x + width, y - height + height // 6), (x + width, y - height)))
    cords = [(x + int(22 * scale), y + int(35 * scale)),
             (x + int(195 * scale), y + int(105 * scale)),
             (x + int(40 * scale), y - int(90 * scale)),
             (x + int(180 * scale), y - int(50 * scale))]
    probs = coinflip(4)
    for i in range(len(cords)):
        if probs[i] == 1:
            a, b = cords[i]
            cobweb(a, b, 0.45 * scale)
Beispiel #5
0
def draw_legs(surf_2, surf_1, length, width):
    """
    Функция рисует на дополнительных поверхностях ноги птицы
    :param surf_2: поверхность, на которой будет нарисована желтая часть лапок и черный контур вокруг лапок
    :param surf_1: поверхность, на которой будут нарисованы ноги без желтой части лапок
    :param length: длина белой части ноги
    :param width: ширина белой части ноги
    :return: функция ничего не возвращает
    """
    draw.ellipse(surf_2, white, (45, 10, 20, 50))
    draw.ellipse(surf_1, white, (0, 0, 30, 60))
    draw.polygon(surf_2, black,
                 [(width - 1, length), (width - 16, length + 10), (width - 31, length + 29),
                  (width - 5, length + 11), (width - 1, length + 36), (width + 4, length + 19),
                  (width + 1, length + 11),
                  (width + 1, length + 9), (width + 19, length + 34), (width + 18, length + 19),
                  (width + 11, length + 11), (width + 7, length + 4), (width + 36, length + 30),
                  (width + 29, length + 14), (width + 11, length)])
    draw.polygon(surf_2, (234, 211, 114),
                 [(width + 0, length), (width - 15, length + 10), (width - 30, length + 28),
                  (width - 5, length + 10), (width, length + 35), (width + 3, length + 20),
                  (width, length + 10),
                  (width + 2, length + 8), (width + 20, length + 33), (width + 17, length + 20),
                  (width + 10, length + 10), (width + 7, length + 4), (width + 35, length + 29),
                  (width + 28, length + 14), (width + 10, length)])
Beispiel #6
0
def draw_fig(new_x, new_y, r, color, m):
    if m != 3:
        pgd.circle(screen, color, (new_x, new_y), r)
    else:
        pgd.polygon(screen, color, [(new_x, new_y), (new_x + r, new_y),
                                    (new_x + r, new_y + r),
                                    (new_x, new_y + r)])
Beispiel #7
0
def draw_boat(boat_x, boat_y, p):
    """

    boat_x - координата x центра иллюминатора
    boat_y - координата y центра иллюминатора
    p - коэффициент пропорциональности размеров лодки


    """
    draw.circle(screen, (139, 80, 20), (boat_x, boat_y), p * 7)
    draw.rect(screen, (0, 0, 255),
              (boat_x - p * 7, boat_y - p * 7, p * 7 * 2, p * 7))
    draw.rect(screen, (0, 0, 255), (boat_x, boat_y, p * 7, p * 7))
    draw.rect(screen, (0, 0, 0), (boat_x, boat_y, p * 28 + 2, p * 7))
    draw.rect(screen, (139, 80, 20), (boat_x + 1, boat_y, p * 28, p * 7))
    draw.polygon(screen, (0, 0, 0), [(boat_x + p * 28 + 2, boat_y),
                                     (boat_x + p * 28 + 2, boat_y + p * 7 - 1),
                                     (boat_x + p * 43, boat_y)])
    draw.polygon(screen, (139, 80, 20),
                 [(boat_x + p * 28 + 2, boat_y),
                  (boat_x + p * 28 + 2, boat_y + p * 7 - 1),
                  (boat_x + p * 43, boat_y)])
    draw.circle(screen, (0, 0, 0), (boat_x + p * 33, boat_y + p * 3 - 2),
                p * 2)
    draw.circle(screen, (255, 255, 255), (boat_x + p * 33, boat_y + p * 3 - 2),
                p * 2 - 3)
Beispiel #8
0
    def rounded_corners(self, surface):
        """
		Applies a rounded corners effect to this Widget's initial background surface.
		"""
        bg = self.current_background_color()
        # points are (x, y)
        polygon(surface,
                bg, [(0, self.border_radius),
                     (self.rect.width, self.border_radius),
                     (self.rect.width, self.rect.height - self.border_radius),
                     (0, self.rect.height - self.border_radius)])
        polygon(surface, bg,
                [(self.border_radius, 0),
                 (self.rect.width - self.border_radius, 0),
                 (self.rect.width - self.border_radius, self.rect.height),
                 (self.border_radius, self.rect.height)])
        circle(surface, bg, (self.border_radius, self.border_radius),
               self.border_radius)
        circle(surface, bg,
               (self.rect.width - self.border_radius, self.border_radius),
               self.border_radius)
        circle(surface, bg, (self.rect.width - self.border_radius,
                             self.rect.height - self.border_radius),
               self.border_radius)
        circle(surface, bg,
               (self.border_radius, self.rect.height - self.border_radius),
               self.border_radius)
        return surface
def main():
    Tx=50
    Ty=400
    Turret = LaserTurret(Tx,Ty,75,10,3,pi/2,pi,3,MockLevel,20)
    init()
    screen = display.set_mode((sizeX, sizeY))
    times = [0] * 10
    i = 0
    t = time.perf_counter_ns()
    while True:
        for event in pygame.event.get():
            pass
        mosePos = mouse.get_pos()
        MockPlayer.posX=mosePos[0]+50
        MockPlayer.posY = mosePos[1]+50
        screen.fill(Color(0,0,0))
        Turret.nextCycle(times[i]/10**9,MockLevel.player.posX,MockLevel.player.posY)
        draw.circle(screen,Color(255,255,255),(MockLevel.player.posX,MockLevel.player.posY),10)
        #draw.circle(screen, Color(255, 0, 0), (Tx, Ty), 10)
        #draw.circle(screen, Color(0, 255, 0), Turret.getPoint(), 3)
        s=Turret.draw()
        screen.blit(s, (Turret.posX, Turret.posY))
        Turret.shoot(MockLevel.player.posX,MockLevel.player.posY)
        draw.polygon(screen,Color(0,255,0),MockPlayer.getPoints(1))
        draw.polygon(screen, Color(0, 0, 255), [(1000,100),(1000,200),(1200,200),(1200,100)])
        Turret.effect(screen)
        display.flip()
        times[i] = time.perf_counter_ns() - t
        t = time.perf_counter_ns()
        i += 1
        i %= 10
 def __make_pentagon__(self, surface, *args, **kwargs):
     color, width = pgbase.colors['black'], 0
     side = kwargs['side'] if 'side' in kwargs else self._shape_properties[
         'side']
     center = kwargs['center'] if 'center' in kwargs else (
         self._shape_properties['center']
         if 'center' in self._shape_properties else None)
     if center is None:
         start = kwargs[
             'start'] if 'start' in kwargs else self._shape_properties[
                 'start']
     else:
         start = Position(
             center.x() - 0.5 * side,
             center.y() + (0.5 * side * math.tan(math.radians(54))))
     if 'color' in kwargs:
         color = pgbase.colors[kwargs['color']]
     elif 'color' in self._shape_properties:
         color = pgbase.colors[self._shape_properties['color']]
     if 'width' in kwargs:
         width = kwargs['width']
     elif 'width' in self._shape_properties:
         width = self._shape_properties['width']
     # this will draw an upright pentagon
     r_72 = math.radians(72)
     r_54 = math.radians(54)
     points = [(start.x(), start.y())]
     points.append((points[0][0] + side, start.y()))
     points.append((points[1][0] + side * math.cos(r_72),
                    points[1][1] - side * math.sin(r_72)))
     points.append((points[2][0] - side * math.sin(r_54),
                    points[2][1] - side * math.cos(r_54)))
     points.append((points[3][0] - side * math.sin(r_54),
                    points[3][1] + side * math.cos(r_54)))
     pgdraw.polygon(surface, color, points, width)
Beispiel #11
0
    def __proximateAircraft__(self, x, y, status, relative_alt):
        pgD.polygon(self.gD, BLUE,
                    [[x, y - 15], [x - 10, y], [x, y + 15], [x + 10, y]], 0)
        if status == 1:
            pgD.line(self.gD, BLUE, [x + 20, y - 5], [x + 20, y + 10], 2)
            pgD.line(self.gD, BLUE, [x + 20, y + 10], [x + 15, y + 5], 2)
            pgD.line(self.gD, BLUE, [x + 20, y + 10], [x + 25, y + 5], 2)
        elif status == 2:
            pgD.line(self.gD, BLUE, [x + 20, y - 5], [x + 20, y + 10], 2)
            pgD.line(self.gD, BLUE, [x + 20, y - 5], [x + 15, y + 0], 2)
            pgD.line(self.gD, BLUE, [x + 20, y - 5], [x + 25, y + 0], 2)
        relative_alt = int(relative_alt / 100)
        if abs(relative_alt) > 99:
            feet = str(99)
        else:
            feet = str(abs(relative_alt))

        f = font.SysFont('Lucida Console', 16)
        if abs(relative_alt * 100) < 1000:
            feet = '0' + feet
        if relative_alt > 0:
            textsurface = f.render('+' + feet, False, BLUE)
        elif relative_alt < 0:
            textsurface = f.render('-' + feet, False, BLUE)
        else:
            textsurface = f.render(' ' + feet, False, BLUE)
        self.gD.blit(textsurface, (x - 12, y - 35))
Beispiel #12
0
def head():
    '''
    draw the head of the dog
    :return:
    '''
    draw.rect(SnoopDogg, (153, 102, 0), (45, 545, 80, 80))  # морда
    draw.aalines(SnoopDogg, BLACK_KOSTYL, True, [[45, 545], [125, 545], [125, 625], [45, 625]])
    draw.ellipse(SnoopDogg, (153, 102, 0), (30, 545, 20, 30))  # left ear
    draw.arc(SnoopDogg, BLACK_KOSTYL, (30, 545, 20, 30), pi, 2 * pi, 1)
    draw.arc(SnoopDogg, BLACK_KOSTYL, (30, 545, 20, 30), 0, pi, 1)
    draw.ellipse(SnoopDogg, (153, 102, 0), (120, 545, 20, 30))  # right ear
    draw.arc(SnoopDogg, BLACK_KOSTYL, (120, 545, 20, 30), pi, 2 * pi, 1)
    draw.arc(SnoopDogg, BLACK_KOSTYL, (120, 545, 20, 30), 0, pi, 1)
    draw.ellipse(SnoopDogg, WHITE, (100, 570, 20, 15))  # right zrachok
    draw.arc(SnoopDogg, BLACK_KOSTYL, (100, 570, 20, 15), pi, 2 * pi, 2)
    draw.arc(SnoopDogg, BLACK_KOSTYL, (100, 570, 20, 15), 0, pi, 2)
    draw.ellipse(SnoopDogg, WHITE, (50, 570, 20, 15))  # left zrachok
    draw.arc(SnoopDogg, BLACK_KOSTYL, (50, 570, 20, 15), pi, 2 * pi, 2)
    draw.arc(SnoopDogg, BLACK_KOSTYL, (50, 570, 20, 15), 0, pi, 2)
    draw.ellipse(SnoopDogg, BLACK_KOSTYL, (55, 575, 5, 5))  # tocka right
    draw.ellipse(SnoopDogg, BLACK_KOSTYL, (110, 575, 5, 5))  # tocka left
    draw.arc(SnoopDogg, BLACK_KOSTYL, (65, 590, 40, 20), pi, 2 * pi, 2)  # mouth
    draw.polygon(SnoopDogg, WHITE, [[70, 605], [70, 615], [75, 610]])  # left tooth
    # animation is here
    draw.ellipse(SnoopDogg, (66, 170, 255), (70, 615 + i, 5, 5))
    draw.ellipse(SnoopDogg, (66, 170, 255), (100, 615 + k, 5, 5))

    draw.polygon(SnoopDogg, WHITE, [[100, 605], [100, 615], [95, 610]])  # right tooth
    draw.aalines(SnoopDogg, BLACK_KOSTYL, True, [[70, 605], [70, 615], [75, 610]])
    draw.aalines(SnoopDogg, BLACK_KOSTYL, True, [[100, 605], [100, 615], [95, 610]])
Beispiel #13
0
 def create(color, angulo):
     img = Surface((32, 32), SRCALPHA)
     draw.polygon(img, color,
                  [[1, 13], [20, 13], [20, 5], [30, 14], [20, 26], [20, 18],
                   [1, 17]])
     image = transform.rotate(img, angulo)
     return image
Beispiel #14
0
def draw_tree(screen, x, y, size_x, size_y, color):
    #the center(x,y) of the tree is the point in the middle of its trunk
    #bottom part of trunk
    pgd.line(screen, color, [x, y + int(size_y/60)], 
                            [x, y + int(size_y/4)], 
                            int(size_x/18))
    pgd.line(screen, color, [x, y + int(17*size_y/60)], 
                            [x, y + int(size_y/2)], 
                            int(size_x/18))
    #right and bottom branch
    pgd.arc(screen, tree_color, [[x, y - int(5*size_y/57)], 
                                 [int(14*size_x/35), int(size_y/2 + 5*size_y/57)]],
                                 6*m.pi/14, 4*m.pi/5, 4)
    #top part of trunk
    pgd.polygon(screen, tree_color, [[x, y], 
                                     [x - int(size_x/22), y - int(size_y/80)], 
                                     [x, y - int(17.5*size_y/116)], 
                                     [x + int(size_x/22), y - int(16*size_y/116)]])
    pgd.polygon(screen, tree_color, [[x + int(size_x/80), y - int(size_y/6 + 0.5*size_y/100)], 
                                     [x - int(size_x/80), y - int(17*size_y/96)], 
                                     [x + int(size_x/18), y - int(size_y/2 + 1*size_y/100 )], 
                                     [x + int(7*size_x/86), y - int(size_y/2 + 0.5*size_y/100)]])
    #leaves on right and bottom branch
    delta_1 = int(5*size_x/37)
    for i in range(3):
        pgd.ellipse(screen, tree_color, [[x + delta_1, y - int(5*size_y/70)], 
                                         [int(size_x/40), int(5*size_y/35)]])
        delta_1 += int(3*size_x/60)
    
    #right and top branch and leaves on it
    pgd.arc(screen, tree_color, [[x + int(5*size_x/80), y - int(size_y/2)], 
                                 [int(size_x - 5*size_x/40), int(30*size_y/35)]],
            m.pi/2, 9*m.pi/10, 4)
    delta_2x = int(8*size_x/24)
    delta_2y = int(32*size_y/70)
    for i in range(5):
        pgd.ellipse(screen, tree_color, [[x + delta_2x, y - delta_2y], 
                                         [int(size_x/40), int(5*size_y/35)]])
        delta_2x += int(3*size_x/80)
        delta_2y += int(size_y/70)
    #left top branch and leaves
    pgd.arc(screen, tree_color, [[x - size_x, y - int(size_y/2)], 
                                 [size_x, size_y]],
            m.pi/10, m.pi/2, 4)
    delta_3x = int(2.5*size_x/8)
    delta_3y = int(3.5*size_y/8)
    for i in range(5):
        pgd.ellipse(screen, tree_color, [[x - delta_3x, y - delta_3y], 
                                         [int(size_x/40), int(5*size_y/35)]])
        delta_3x += int(3*size_x/80)
        delta_3y += int(size_y/70)
        #left top branch and leaves
    pgd.arc(screen, tree_color, [[x - int(22*size_x/48), y], 
                                 [int(22*size_x/48), int(size_y/2)]],
            m.pi/6, 2.5*m.pi/4, 4)
    delta_4 = int(size_x/6)
    for i in range(3):
        pgd.ellipse(screen, tree_color, [[x - delta_4, y], 
                                         [int(size_x/40), int(5*size_y/35)]])
        delta_4 += int(3*size_x/60)
Beispiel #15
0
def draw_trunk(screen, x, y, trunk_width, trunk_height, tree_color):
    ''' the center(x,y) of the tree is the point in the middle of its trunk '''

    bottom_trunk_y_lower_begin = y + trunk_height // 60
    bottom_trunk_y_lower_end = y + trunk_height // 4
    pgd.line(screen, tree_color, [x, bottom_trunk_y_lower_begin],
             [x, bottom_trunk_y_lower_end], trunk_width // 18)

    bottom_trunk_y_upper_begin = y + 17 * trunk_height // 60
    bottom_trunk_y_upper_end = y + trunk_height // 2
    pgd.line(screen, tree_color, [x, bottom_trunk_y_upper_begin],
             [x, bottom_trunk_y_upper_end], trunk_width // 18)

    top_trunk_coords_lower = [[x, y],
                              [x - trunk_width // 22, y - trunk_height // 80],
                              [x, y - 35 * trunk_height // 232],
                              [
                                  x + trunk_width // 22,
                                  y - 16 * trunk_height // 116
                              ]]
    top_trunk_coords_upper = [
        [x + trunk_width // 80, y - trunk_height // 6 + trunk_height // 200],
        [x - trunk_width // 80, y - 17 * trunk_height // 96],
        [x + trunk_width // 18, y - trunk_height // 2 + trunk_height // 100],
        [
            x + 7 * trunk_width // 86,
            y - trunk_height // 2 + trunk_height // 200
        ]
    ]
    pgd.polygon(screen, tree_color, top_trunk_coords_lower)

    pgd.polygon(screen, tree_color, top_trunk_coords_upper)
Beispiel #16
0
def budka_plus_cep():
    '''
    Draw the home for dogs
    :return:
    '''
    draw.polygon(screen, (235, 191, 0),
                 [[350, 450], [350, 650], [500, 700], [550, 650], [550, 450], [450, 300], [400, 350]])
    draw.aalines(screen, BLACK, False,
                 [[350, 450], [350, 650], [500, 700], [550, 650], [550, 450], [450, 300], [400, 350], [500, 500],
                  [500, 700]])
    draw.aalines(screen, BLACK, False, [[400, 350], [350, 450], [500, 500], [550, 450]])
    draw.ellipse(screen, BLACK, (375, 500, 100, 150))
    draw.arc(screen, YELLOW, (355, 610, 15, 30), 0, pi, 4)
    draw.arc(screen, YELLOW, (355, 610, 15, 30), pi, 2 * pi, 4)
    draw.arc(screen, YELLOW, (357, 630, 15, 30), 0, pi, 4)
    draw.arc(screen, YELLOW, (357, 630, 15, 30), pi, 2 * pi, 4)
    draw.arc(screen, YELLOW, (355, 650, 15, 30), 0, pi, 4)
    draw.arc(screen, YELLOW, (355, 650, 15, 30), pi, 2 * pi, 4)
    draw.arc(screen, YELLOW, (345, 665, 30, 15), 0, pi, 4)
    draw.arc(screen, YELLOW, (345, 665, 30, 15), pi, 2 * pi, 4)
    draw.arc(screen, YELLOW, (325, 663, 30, 15), 0, pi, 4)
    draw.arc(screen, YELLOW, (325, 663, 30, 15), pi, 2 * pi, 4)
    draw.arc(screen, YELLOW, (305, 665, 30, 15), 0, pi, 4)
    draw.arc(screen, YELLOW, (305, 665, 30, 15), pi, 2 * pi, 4)
    draw.arc(screen, YELLOW, (285, 663, 30, 15), 0, pi, 4)
    draw.arc(screen, YELLOW, (285, 663, 30, 15), pi, 2 * pi, 4)
    draw.arc(screen, YELLOW, (265, 665, 30, 15), 0, pi, 4)
    draw.arc(screen, YELLOW, (265, 665, 30, 15), pi, 2 * pi, 4)
Beispiel #17
0
    def draw(self, __display_surface):
        '''
        Draws table, balls, pockets
        '''
        __display_surface.fill(pygame.Color("black"))

        self.ball_surf.fill((0, 220, 100))

        coordinates = self.generate_bumper_coords(
            self.play_surface
        )  #Generate new coordinates in case window resized (Resize not implemented)

        for key, item in coordinates.items():

            drw.polygon(self.ball_surf, cl.Color('black'), item, 1)

        self.pockets.draw(self.ball_surf)
        self.balls.draw(self.ball_surf)
        __display_surface.blit(self.ball_surf, self.ball_surf_origin)
        #__display_surface.blit(self.scratch, (220,170))

        self.score.draw(__display_surface,
                        (__display_surface.get_width() -
                         2 * self.score_size[0], self.score_size[1]))
        self.scratch.draw(__display_surface, (220, 170))

        #Draw stick last so it is drawn above the ball surface
        if not self.balls_still_moving():
            self.stick.draw(__display_surface, self.play_stick_animation,
                            self.cue_ball.get_pos())
Beispiel #18
0
    def draw(self, screen):
        halfw = self.width / 2
        halfh = self.height / 2

        x = self.x
        y = self.y

        # 1       4
        #     x
        #   2   3

        slope = 15
        points = None
        if self.side == Sides.LEFT:
            points = ((x - halfw, y + halfh + slope), (x + halfw, y + halfh),
                      (x + halfw, y - halfh), (x - halfw, y - halfh - slope))
        elif self.side == Sides.RIGHT:
            points = ((x + halfw, y + halfh + slope), (x - halfw, y + halfh),
                      (x - halfw, y - halfh), (x + halfw, y - halfh - slope))
        elif self.side == Sides.TOP:
            points = ((x - halfw - slope, y - halfh), (x - halfw, y + halfh),
                      (x + halfw, y + halfh), (x + halfw + slope, y - halfh))
        elif self.side == Sides.BOT:
            points = ((x - halfw - slope, y + halfh), (x - halfw, y - halfh),
                      (x + halfw, y - halfh), (x + halfw + slope, y + halfh))

        draw.polygon(screen, self.color, points)
Beispiel #19
0
 def update(self):
     self.turn_towards(self.target.position)
     self.image = Surface(self.rect.size)
     rot = lambda point: Vector(point).rotate(self.direction
                                              ) + self.center_point
     polygon(self.image, self.color, [rot(p) for p in self.points])
     MovingSprite.update(self)
def display_abacus_add_subtract_problem(
    screen,
    color,
    separator_bead_color,
    upper_left,
    height,
    operands,
    line_spacing=1.2,
    font=None,
):
    if font is None:
        font = SysFont('Lucida Console', height)
    x_ul, y_ul = upper_left
    max_digits = max(len(digitize(operand)) for operand in operands)
    column_width = height_to_width(height)
    max_sign_width = 0.

    for row_n, operand in enumerate(operands):
        x_row = x_ul
        y_row = y_ul + row_n * height * line_spacing

        digits = digitize(abs(operand))
        n_digits = len(digits)

        sign = '+' if operand >= 0 else '-'
        sign_surface = font.render(sign, True, color)
        sign_width = sign_surface.get_width()

        max_sign_width = max(sign_width, max_sign_width)

        screen.blit(sign_surface, (x_row, y_row))

        draw_columns(
            screen,
            color,
            (x_row + sign_width +
             (max_digits - n_digits) * column_width, y_row),
            height,
            digits,
            separator_bead_color=separator_bead_color,
        )

    row_n = len(operands)
    x_rect_left = x_ul
    x_rect_right = (x_ul + max_sign_width + max_digits * column_width)
    y_rect_top = (y_ul + height * (row_n * line_spacing - .25 *
                                   (line_spacing - 1.)))
    y_rect_bottom = (y_rect_top + .25 * (line_spacing - 1.) * height)

    polygon(screen, color, [
        (x_rect_left, y_rect_top),
        (x_rect_right, y_rect_top),
        (x_rect_right, y_rect_bottom),
        (x_rect_left, y_rect_bottom),
    ])

    # coordinates of where to draw the rightmost digit
    # of the response
    return ((x_ul + sign_width + max_digits * column_width),
            y_ul + row_n * height * line_spacing)
Beispiel #21
0
    def render(self, window, color=(255, 0, 0)):
        # rotation for camera

        # translation for camera

        # actual render
        polygon(window, color, self.actual_model(), self.width)
Beispiel #22
0
def draw_parus(parus_x, parus_y, p):
    """

    parus_x - координата x левого верхнего угла стержня паруса
    parus_y - координата y левого верхнего угла стержня паруса
    p - коэффициент пропорциональности размеров паруса

    """
    draw.rect(screen, (0, 0, 0), (parus_x, parus_y, p * 2 - 2, 2 * 10 * p))
    draw.polygon(screen, (218, 173, 128),
                 [(parus_x + p * 2 - 2, parus_y),
                  (parus_x + p * 6, parus_y + p * 10),
                  (parus_x + p * 14, parus_y + p * 10)])
    draw.polygon(screen, (218, 173, 128),
                 [(parus_x + p * 2 - 2, parus_y + p * 10 * 2),
                  (parus_x + p * 6, parus_y + p * 10),
                  (parus_x + p * 14, parus_y + p * 10)])
    draw.aaline(screen, (0, 0, 0), (parus_x + p * 6, parus_y + p * 10),
                (parus_x + p * 14, parus_y + p * 10))
    draw.aaline(screen, (0, 0, 0), (parus_x + p * 6, parus_y + p * 10),
                (parus_x + p * 2 - 2, parus_y))
    draw.aaline(screen, (0, 0, 0), (parus_x + p * 14, parus_y + p * 10),
                (parus_x + p * 2 - 2, parus_y))
    draw.aaline(screen, (0, 0, 0), (parus_x + p * 6, parus_y + p * 10),
                (parus_x + p * 2 - 2, parus_y + 2 * 10 * p))
    draw.aaline(screen, (0, 0, 0), (parus_x + p * 14, parus_y + p * 10),
                (parus_x + p * 2 - 2, parus_y + 2 * 10 * p))
Beispiel #23
0
    def look(self, surface, walls):
        scene = []
        prev = self.rays[0].pos
        for ray in self.rays:
            ray.rotate(self.angle)

            closest = None
            record = inf
            for wall in walls:
                pt = ray.cast(wall)
                if(pt):
                    d = self.pos.distance_to(pt)
                    d = d * cos(radians(ray.initangle)) 
                    if(d < record):
                        record = d
                        closest = pt
            if closest:
                # Draw ray
                draw.polygon(surface, YELLOW, [prev, closest, self.pos])
                # draw.aaline(surface, YELLOW, self.pos, closest)
                prev = closest
            
            scene.append(record)
            
        return scene
Beispiel #24
0
 def _draw_parallelogram(self):
     for color, shape in PARALLELOGRAM.values():
         polygon(
             self._screen,
             color,
             shape           
         )            
Beispiel #25
0
 def paint(self, surface):
     if not self.active:
         return
     point_list = self.get_points()
     converted_point_list = []
     for point in point_list:
         converted_point_list.append(point.pair())
     draw.polygon(surface, self.color, converted_point_list)
Beispiel #26
0
	def __draw_walls(self):
		closed = [(x,y) for y in range(len(self.matrix)) for x in range(len(self.matrix[0])) 
						if not self.matrix[y][x]]

		for c in closed:
			x, y = c2r(c)
			draw.polygon(self.window, (100, 50, 50), 
				[(x,y), (x + X_CELL, y), (x + X_CELL, y + Y_CELL), (x, y + Y_CELL)])
Beispiel #27
0
 def paint(self, surface):
     if not self.active:
         return
     point_list = self.get_points()
     converted_point_list = []
     for point in point_list:
         converted_point_list.append(point.pair())
     draw.polygon(surface, self.color, converted_point_list)
Beispiel #28
0
def simple(screen, shapes, color = [255, 255, 255]):
    for shape in shapes:
        if shape[0] == "segment":
            draw.line(screen, color, shape[1], shape[2], int(shape[3]))
        if shape[0] == "circle":
            draw.circle(screen, color, [int(shape[1][0]), int(shape[1][1])], int(shape[2]))
        if shape[0] == "polygon":
            draw.polygon(screen, color, shape[1])
Beispiel #29
0
    def draw_item(self, item):
        if item.role == "Woger":
            #if hasattr(item, 'image'):
            #self.window.display_surface.blit(
            # item.image, self.camera.point_to_screen(item.body.position))
            if item.body.velocity[0] < -0.1:
                self.window.display_surface.blit(
                    item.image[0],
                    self.camera.point_to_screen(item.body.position))
                self.facing_right = 0
            elif item.body.velocity[0] > 0.1:
                self.window.display_surface.blit(
                    item.image[1],
                    self.camera.point_to_screen(item.body.position))
                self.facing_right = 1
            else:
                self.window.display_surface.blit(
                    item.image[self.facing_right],
                    self.camera.point_to_screen(item.body.position))

        elif item.role == "Bough":
            #an_image = item.image[angle(item.body.angle)]
            #Only 16 images in there.  So we find the closest image for that angle.
            #  >>> 360 / 23
            #  15
            #  >>> 0 / 23
            #  0
            #  >>> 180 / 23
            #  7
            assert (len(item.image) == 16)
            idx_for_angle = int(angle(item.body.angle) / 23)
            an_image = item.image[idx_for_angle]

            ##            verts = item.shape.get_points()
            ##            x,y = sum(v[0] for v in verts)/3, sum(v[1] for v in verts)/3
            self.window.display_surface.blit(
                an_image,
                ##                   self.camera.point_to_screen((x,y)))
                self.camera.point_to_screen(item.body.position))

        elif item.role == "Owange":
            if item.status == "Collided":
                self.window.display_surface.blit(
                    item.image[0],
                    self.camera.point_to_screen(item.body.position))
            else:
                self.window.display_surface.blit(
                    item.image[0],
                    self.camera.point_to_screen(item.body.position))

        elif item.role == "Cherry":
            self.window.display_surface.blit(
                item.image[0], self.camera.point_to_screen(item.body.position))
        else:
            # note: 80% of program execution time is in this clause
            # particularly retrieving the item.verts
            draw.polygon(self.window.display_surface, item.color,
                         self.camera.to_screen(item.verts), 0)
Beispiel #30
0
    def __draw_stick(self, __display_surface):
        '''
        Draw the stick
        '''

        drw.polygon(__display_surface, (255, 255, 255),
                    self.cue_tip_pts)  #White
        drw.polygon(__display_surface, (131, 81, 69),
                    self.stick_pts)  #Brown color
Beispiel #31
0
def new_map(screen, image, game):
    cities = game.take_cities_list()
    graph = game.take_cities_graph()
    screen.blit(image, (0, 0))
    exceptions = [(16, 38), (16, 45), (24, 47)]
    # Отрисовка ребер между городами
    for city in cities:
        for neighbor in city.take_neighbors():
            # Если ребро должно выходить за пределы карты и входить с другой стороны
            if (city.take_num(), neighbor.take_num()) in exceptions:
                x1, y1 = city.take_cords()
                x2, y2 = neighbor.take_cords()
                if x1 > x2:
                    x1, y1 = x2, y2
                draw.line(screen,
                          EDGE_COLOR, (x1, y1), (0, (y1 + y2) // 2),
                          width=3)
                draw.line(screen,
                          EDGE_COLOR, (x2, y2), (IMAGE_W, (y1 + y2) // 2),
                          width=3)
                font = pygame.font.Font(None, 20)
                text = font.render(neighbor.take_name(), True, TEXT_COLOR)
                screen.blit(text, (0, (y1 + y2) // 2))
                font = pygame.font.Font(None, 20)
                text = font.render(city.take_name(), True, TEXT_COLOR)
                screen.blit(text, (IMAGE_W - 105, (y1 + y2) // 2))
            elif (int(neighbor.take_num()),
                  int(city.take_num())) not in exceptions:
                draw.line(screen,
                          EDGE_COLOR,
                          city.take_cords(),
                          neighbor.take_cords(),
                          width=3)
    for city in cities:
        x, y = city.take_cords()
        draw.circle(screen, VIRUS_COLORS[city.take_virus()], (x, y),
                    CITY_RADIUS)
        if city.is_station():
            draw.polygon(screen, STATION_COLOR,
                         ((x + 5, y), (x + 5, y - 7), (x + 7 + 5, y - 14),
                          (x + 19, y - 7), (x + 19, y)))
        draw.circle(screen, CONTAMINATION_COLOR, (x - 10 - 5, y + 8), 7)
        font = pygame.font.Font(None, 20)
        text = font.render(str(city.take_contamination()), True,
                           (100, 255, 100))
        screen.blit(text, (x - 10 - 9, y + 2))
        font = pygame.font.Font(None, 18)
        text = font.render(city.take_name(), True, TEXT_COLOR)
        if city.take_name() == 'Нью-Дели' or city.take_name(
        ) == 'Лос-Анджелес' or city.take_name() == 'Монреаль':
            draw.rect(screen, 'white', ((x - 15, y - 25),
                                        (text.get_width(), text.get_height())))
            screen.blit(text, (x - 15, y - 25))
        else:
            draw.rect(screen, 'white',
                      ((x - 5, y + 7), (text.get_width(), text.get_height())))
            screen.blit(text, (x - 5, y + 7))
    def draw(self):
        angles = [np.pi / 2, np.pi + np.pi / 6, -np.pi / 6]
        vertices = []
        for a in angles:
            vx = self.pos[0] + int(np.cos(a) * self.size)
            vy = self.pos[1] + int(np.sin(a) * self.size)
            vertices.append((vx, vy))

        dr.polygon(screen, self.color, vertices)
Beispiel #33
0
 def __draw_menu_cursor(self, surface):
     cursor_height = self.menu_items_pos[self.selected_index]
     draw.polygon(surface, self.orange_color, [
         (400, cursor_height),
         (400, cursor_height + self.cursor * 2),
         (400 + self.cursor, cursor_height + self.cursor)])
     draw.polygon(surface, self.orange_color, [
         (780, cursor_height),
         (780, cursor_height + self.cursor * 2),
         (780 - self.cursor, cursor_height + self.cursor)])
Beispiel #34
0
	def draw_arrows(self, surf, i, rect):
		m = self.margin
		color = self.sel_color or self.fg_color
		x, y = rect.midtop
		pts = [(x - m, y - m), (x + m, y - m), (x, y)]
		draw.polygon(surf, color, pts)
		x, y = rect.midbottom
		y -= 1
		pts = [(x - m, y + m), (x + m, y + m), (x, y)]
		draw.polygon(surf, color, pts)
Beispiel #35
0
    def draw_item(self, item):
        if item.role == "Woger":
        #if hasattr(item, 'image'):
                #self.window.display_surface.blit(
               # item.image, self.camera.point_to_screen(item.body.position))
            if item.body.velocity[0] < -0.1:
               self.window.display_surface.blit(
               item.image[0], self.camera.point_to_screen(item.body.position))
               self.facing_right = 0
            elif item.body.velocity[0] > 0.1:
               self.window.display_surface.blit(
               item.image[1], self.camera.point_to_screen(item.body.position))
               self.facing_right = 1
            else:
               self.window.display_surface.blit(
               item.image[self.facing_right], self.camera.point_to_screen(item.body.position))
                   

        elif item.role == "Bough":
            #an_image = item.image[angle(item.body.angle)]
            #Only 16 images in there.  So we find the closest image for that angle.
            #  >>> 360 / 23
            #  15
            #  >>> 0 / 23
            #  0
            #  >>> 180 / 23
            #  7
            assert(len(item.image) == 16)
            idx_for_angle = int(angle(item.body.angle) /23)
            an_image = item.image[idx_for_angle]

##            verts = item.shape.get_points()
##            x,y = sum(v[0] for v in verts)/3, sum(v[1] for v in verts)/3
            self.window.display_surface.blit(an_image,
##                   self.camera.point_to_screen((x,y)))
                   self.camera.point_to_screen(item.body.position))

        elif item.role == "Owange":
            if item.status == "Collided":
               self.window.display_surface.blit(
                           item.image[0], self.camera.point_to_screen(item.body.position))
            else:
                self.window.display_surface.blit(
                           item.image[0], self.camera.point_to_screen(item.body.position))

        elif item.role == "Cherry":
            self.window.display_surface.blit(
               item.image[0], self.camera.point_to_screen(item.body.position))
        else:
            # note: 80% of program execution time is in this clause
            # particularly retrieving the item.verts
            draw.polygon(
                self.window.display_surface,
                item.color,
                self.camera.to_screen(item.verts), 0)
Beispiel #36
0
	def redraw(self):
		self.pointlist = []
		self.heights = []
		if not self.pointlist:
			self.generate_terrain(self.buffer.get_size())

		if self.color:
			draw.polygon(self.buffer, white, self.pointlist)
		else:
			draw.polygon(self.buffer, black, self.pointlist)
		draw.lines(self.buffer, white, True, self.pointlist)
Beispiel #37
0
	def __draw_view_cells(self, obj):
		color = obj.color
		if obj.mode is 'hunting':
			color = (255, obj.color[1], obj.color[2])

		for point in obj.view_cells:
			tl = c2r(point)
			tr = tl[0] + X_CELL, tl[1]
			br = tr[0], tr[1] + Y_CELL
			bl = br[0] - X_CELL, br[1]

			draw.polygon(self.window, color, (tl, tr, br, bl), 1)
Beispiel #38
0
def render(surface):
	from pygame import draw
	pts = []
	gl.rotate(1.0/180*math.pi, 0.5 , 1 , 0.25);
	#for pt in [(-160,-120,0),(-160,120,0),(160,120,0),(160,-120,0)]:
	z = 0
	for pt in [(-160,-120,z),(-160,120,z),(160,120, z),(160,-120, z)]:
		tp = gl.trans_(pt);
		# 画面の中心に移動
		tp[0]+=320;
		tp[1]+=240;
		pts.append(tp);
	draw.polygon(surface, (255,255,255), pts)
Beispiel #39
0
def runGUI():
    pygame.display.set_mode((800,600))
    pygame.display.set_caption("Neuro Junk 2012/13")
    screen = pygame.display.get_surface()
    
    while True:
        input(pygame.event.get())
        
        screen.fill((0,0,0))
        circle(screen, (255,255,255), (0,0), radius, 1)
        line(screen, (255,255,255), point1, point2, 1)
        
        polygon(screen, (255,255,255), outer_line, 2)
        polygon(screen, (255,255,255), inner_line,2)
        
        if intersectCircle(point1, point2, radius):
            rect(screen, (0,255,0), Rect(600, 200, 100, 100), 0)
        
        inn = changeField(inner_line, car)
        out = changeField(outer_line, car)
        csect = curSection(inn, out)
        
        polygon(screen, (0,0,255), out, 2)
        polygon(screen, (0,0,255), inn, 2)
        
        rect(screen, (255,255,255), Rect(car.x-2, car.y-2, 4, 4), 0)
        
        if csect is not None:
            line(screen, (0,255,0), csect.inner_start, csect.inner_end, 1)
            line(screen, (0,255,0), csect.outer_start, csect.outer_end, 1)
        
        pygame.display.update()
Beispiel #40
0
def draw_poly(poly):
    polygon = Polygon(poly.points)
    if poly.orientation:
        c = polygon.centroid.coords[0]
        polygon = Polygon([rotate(p, c, -poly.orientation)
                           for p in polygon.exterior.coords])
    c = polygon.centroid.coords[0]
    p = poly.position
    dx, dy = [p[i] - c[i] for i in range(2)]
    draw.polygon(screen, (0,255,0),
                 [defloat(scale(offset(p, dx, dy)))
                  for p in polygon.exterior.coords],
                 1)
    draw.circle(screen, (0,255,0),
                defloat(scale(offset(c, dx, dy))),
                3)
Beispiel #41
0
    def draw(self, screen):
        halfw = self.width / 2
        halfh = self.height / 2

        x = self.x
        y = self.y

        # 1       4
        #     x
        #   2   3

        slope = 15
        points = None
        if self.side == Sides.LEFT:
            points = (
                (x - halfw, y + halfh + slope),
                (x + halfw, y + halfh),
                (x + halfw, y - halfh),
                (x - halfw, y - halfh - slope)
            )
        elif self.side == Sides.RIGHT:
            points = (
                (x + halfw, y + halfh + slope),
                (x - halfw, y + halfh),
                (x - halfw, y - halfh),
                (x + halfw, y - halfh - slope)
            )
        elif self.side == Sides.TOP:
            points = (
                (x - halfw - slope, y - halfh),
                (x - halfw, y + halfh),
                (x + halfw, y + halfh),
                (x + halfw + slope, y - halfh)
            )
        elif self.side == Sides.BOT:
            points = (
                (x - halfw - slope, y + halfh),
                (x - halfw, y - halfh),
                (x + halfw, y - halfh),
                (x + halfw + slope, y + halfh)
            )

        draw.polygon(
            screen,
            self.color,
            points
        )
Beispiel #42
0
 def _draw_base(self):
     img = self._images["image"]
     img.fill(self._parent_view._settings["col"])
     img.fill((200,200,200), self.rect.inflate(-4, -4))
     # Draw line in center
     r = self.rect
     start_pos = (3, r.centery) if self.xy == "y" else (r.centerx, 3)
     end_pos = (r.w-4, r.centery) if self.xy == "y" else (r.centerx, r.h-4)
     draw.line(img, (100,100,100), start_pos, end_pos)
     # Draw arrows
     if self.xy == "y":
         points1 = ((3, r.h/4), (r.centerx, r.h/5-1), (r.w-3, r.h/4))
         points2 = ((3, r.h*.75), (r.centerx, r.h*.8), (r.w-3, r.h*.75))
     else:
         points1 = ((r.w/4, 3), (r.w/5-1, r.centery), (r.w/4, r.h-3))
         points2 = ((r.w*.75, 3), (r.w*.8, r.centery), (r.w*.75, r.h-3))
     draw.polygon(img, (50,50,50), points1)
     draw.polygon(img, (50,50,50), points2)
Beispiel #43
0
def draw_poly(poly, surface, color=None, width=None):
    polygon = orient_polygon(poly)
    c = polygon.centroid.coords[0]
    p = poly.position
    dx, dy = [p[i] - c[i] for i in range(2)]

    if color is None:
        color = (0,255,0)
    if width is None:
        width = 1
    
    draw.polygon(surface, color,
                 [defloat(scale(offset(p, dx, dy)))
                  for p in polygon.exterior.coords],
                 width)
    if width:
        draw.circle(surface, color,
                    defloat(scale(offset(c, dx, dy))),
                    3*width)
Beispiel #44
0
 def _draw_base(self):
     # Frames around edge of button
     x = min(self.image.get_size()) / 8
     self._frame_lt = ((0,0), (self.rect.w,0), (self.rect.w-x,x),
                       (x,x), (x,self.rect.h-x), (0,self.rect.h))
     self._frame_rb = ((self.rect.w,self.rect.h),
                       (0,self.rect.h), (x,self.rect.h-x),
                       (self.rect.w-x,self.rect.h-x),
                       (self.rect.w-x,x), (self.rect.w,0))
     cols = {}
     cols["image"] = self._settings["col"]
     cols["over"] = [min(c*1.1, 255) for c in self._settings["col"]]
     cols["down"] = [c*0.8 for c in self._settings["col"]]
     for img in cols:
         self._images[img].fill(cols[img])
         # Draw a frame around the edges of the button
         frame_lt_c = [min(c*1.3,255) for c in cols[img]]
         frame_rb_c = [c*0.8 for c in cols[img]]
         draw.polygon(self._images[img], frame_lt_c, self._frame_lt)
         draw.polygon(self._images[img], frame_rb_c, self._frame_rb)
Beispiel #45
0
def _draw_shape_filled(surface, shape):
    """Draw the shape on the given surface.
    
    Arguments:
        surface - drawing surface (an instance of pygame.Surface class);
        shape - shape to draw (an instance of one of the shape classes
            defined in shapes module);
    Result:
        bounding box, defined during the drawing;
    """
    return draw.polygon(surface, SHAPE_COLOR, shape.get_vertices())
Beispiel #46
0
def render(surface):
    surface.fill(black)

    c = 0
    for bv in world:
        x, y = bv.position
        if c >= len(colors):
            colors.append(Color(randint(40, 255), randint(40, 255),
                                randint(40, 255)))
        color = colors[c]
        c += 1
        for fv in bv:
            s = fv.shape
            st = fv.shape.type
            if st == b2Shape.e_circle:
                draw.circle(surface, color, (int(x*PPM), int(y*PPM)),
                            int(s.radius*PPM))
            elif st == b2Shape.e_polygon:
                transformed_verts = [bv.transform * v for v in s.vertices]
                verts = [(v.x*PPM, v.y*PPM) for v in transformed_verts]
                draw.polygon(surface, color, verts)
Beispiel #47
0
def render_filled_poly(turtle, string, i):
	#print "render_filled_poly:", string, i ###
	lturtle = turtle.clone(mirror = 1, enable_drawing = False)
	rturtle = turtle.clone(mirror = -1, enable_drawing = False)
	j = render_boundary(lturtle, rturtle, string, i, 1)
	h = turtle.heading
	lturtle.mirror_heading(h)
	rturtle.mirror_heading(h)
	render_boundary(lturtle, rturtle, string, j - 2, -1)
	###points = [turtle.position] + lturtle.path + list(reversed(rturtle.path))
	###draw.polygon(turtle.surface, fill_color, points)
	###gfxdraw.bezier(turtle.surface, points, 10, fill_color) ###
	###fill_bezier(turtle.surface, fill_color, points, bezier_steps)
	pfirst = [turtle.position]
	plast = [0.5 * (lturtle.path[-1] + rturtle.path[-1])]
	side1 = pfirst + lturtle.path + plast
	side2 = pfirst + rturtle.path + plast
	points1 = calculate_multi_bezier(side1, bezier_steps)
	points2 = calculate_multi_bezier(side2, bezier_steps)
	points = points1 + list(reversed(points2))
	draw.polygon(turtle.surface, lturtle.fill_color, points)
	return j
Beispiel #48
0
def draw_ring(screen, rad, color, bg_color, xpos, ypos, thk, pct):
    draw_filled_aacircle(screen, rad, color, xpos, ypos)
    draw_filled_aacircle(screen, rad-thk, bg_color, xpos, ypos)

    x_calc = xpos - 1.1*rad*np.cos(.5*np.pi + 2*np.pi*(1-pct))
    y_calc = ypos - 1.1*rad*np.sin(.5*np.pi + 2*np.pi*(1-pct))

    if pct > .75:
        point_list = np.array([[xpos,ypos],
                               [x_calc,y_calc],
                               [xpos+1.5*rad,ypos-1.5*rad],
                               [xpos,ypos-1.5*rad],
                               [xpos,ypos]])
    elif pct > .5:
        point_list = np.array([[xpos,ypos],
                               [x_calc,y_calc],
                               [xpos+1.5*rad,ypos+1.5*rad],
                               [xpos+1.5*rad,ypos-1.5*rad],
                               [xpos,ypos-1.5*rad],
                               [xpos,ypos]])
    elif pct > .25:
        point_list = np.array([[xpos,ypos],
                               [x_calc,y_calc],
                               [xpos-1.5*rad,ypos+1.5*rad],
                               [xpos+1.5*rad,ypos+1.5*rad],
                               [xpos+1.5*rad,ypos-1.5*rad],
                               [xpos,ypos-1.5*rad],
                               [xpos,ypos]])
    else:
        point_list = np.array([[xpos,ypos],
                               [x_calc,y_calc],
                               [xpos-1.5*rad,ypos-1.5*rad],
                               [xpos-1.5*rad,ypos+1.5*rad],
                               [xpos+1.5*rad,ypos+1.5*rad],
                               [xpos+1.5*rad,ypos-1.5*rad],
                               [xpos,ypos-1.5*rad],
                               [xpos,ypos]])

    polygon(screen, bg_color, point_list)
Beispiel #49
0
def createWarning(screen,message):

    def close():
        nonlocal tmpFrame
        tmpFrame.kill()

    # Creation
    tmpFont = font.SysFont("Arial",34)
    tmpText = tmpFont.render("!",1,(0,0,0))
    tmpFrame = Frame(screen,htitle="Warning",width=300,height=100)
    t = TypableSurface((160,90),text=message)
    tmpSurface = Surface((42,36))
    tmpButton = Button(tmpFrame,width=50,height=20,text="Ok",target=close)
    # Assembly
    tmpSurface.fill((255,255,255))
    draw.polygon(tmpSurface,(255,255,0),[(20,0),(0,35),(40,35)])
    draw.polygon(tmpSurface,(0,0,0),[(20,0),(0,35),(40,35)],3)
    tmpSurface.blit(tmpText,(16,0))
    tmpFrame.blit(tmpSurface,(2,10))
    tmpFrame.blit(t,(50,10))
    tmpButton.place((122,74))
    tmpFrame.place((screen.get_width()//2-150,screen.get_height()//2-50))

    return tmpFrame
Beispiel #50
0
def draw_triangle (surface, color, a, b, c, width=0):
    """draw_triangle (...) -> Rect

    Draws a triangle with the vertices a, b, c on a surface.

    The 'color' argument needs to match the pygame color style. 'a',
    'b', 'c' are sequences of the x- and y-coordinates of the three
    vertices on th surface. 'width' denotes the width of lines in pixels
    or, if set to 0, fills the triangle with the passed color. The
    return value is the bounding box of the affected area.

    The following example would draw a white, filled triangle on the
    specified surface:

    draw_triangle (surface, (255, 255, 255), (5, 1), (1, 5), (10, 5))
    
    Note: This function is a wrapper around pygame.draw.polygon() with a
    fixed three point list and thus all documentation about it can be
    applied to this function, too.
    """
    return draw.polygon (surface, color, [a, b, c], width)
Beispiel #51
0
def build_ship_sprite(size=None, scale=None, orientation=None, heading=None, main_engine=False, retro_engine=False):
    ship_height = int(round(size * scale))
    if ship_height <= 0:
        ship_height = 9

    width = ship_height / 3

    flame_height = ship_height / 5
    image_width = width
    image_height = ship_height + (flame_height * 2)

    sprite = Sprite()
    sprite.layer = 10
    surface = Surface((image_width, image_height))
    surface.set_colorkey((0, 0, 0))

    ship_top = flame_height
    ship_bottom = image_height - flame_height
    ship_left = 0
    ship_right = image_width
    ship_middle = image_width / 2

    ship_triangle = [(ship_middle, ship_top), (ship_left, ship_bottom), (ship_right, ship_bottom)]
    draw.polygon(surface, (255, 255, 255), ship_triangle)

    if main_engine:
        bottom_flame = [(ship_middle, ship_bottom), (0, image_height), (image_width, image_height)]
        draw.polygon(surface, (255, 255, 0), bottom_flame)

    if retro_engine:
        top_flame = [(ship_middle, ship_top), (0, 0), (image_width, 0)]
        draw.polygon(surface, (255, 255, 0), top_flame)

    rotated_surface = transform.rotate(surface, -orientation)

    sprite.image = rotated_surface

    return sprite
Beispiel #52
0
	def draw_scroll_down_button(self, surface):
		r = self.scroll_down_rect
		c = self.scroll_button_color
		draw.polygon(surface, c, [r.topleft, r.midbottom, r.topright])
Beispiel #53
0
	def draw_scroll_up_button(self, surface):
		r = self.scroll_up_rect
		c = self.scroll_button_color
		draw.polygon(surface, c, [r.bottomleft, r.midtop, r.bottomright])
Beispiel #54
0
 def draw_deadend_bullet(self, surf, bg, fg, shape, text, item_text, lvl):
     r = self.get_bullet_rect(surf, lvl)
     draw.polygon(surf, bg, [r.midtop, r.midright, r.midbottom, r.midleft])
     self.draw_item_text(surf, r, item_text)
Beispiel #55
0
 def draw_opened_bullet(self, surf, bg, fg, shape, text, item_text, lvl):
     r = self.get_bullet_rect(surf, lvl)
     draw.polygon(surf, bg, [r.topleft, r.midbottom, r.topright])
     self.draw_item_text(surf, r, item_text)
Beispiel #56
0
	def draw(self, surface):
		from pygame.draw import polygon
		polygon(surface, (128, 200, 255), self.points)
		polygon(surface, (255, 128, 0), self.points, 5)
 def draw_square(surf, bg, r):
     draw.polygon(surf, bg, [r.topleft, r.topright, r.bottomright, r.bottomleft])
def draw_triangle(x1, y1, x2, y2, x3, y3, thickness = 1):
    draw.polygon(screen, color, [(int(x1), int(WINDOW_HEIGHT-y1)), 
                                 (int(x2), int(WINDOW_HEIGHT-y2)), 
                                 (int(x3), int(WINDOW_HEIGHT-y3))], 
                 int(thickness))
Beispiel #59
0
if __name__ == '__main__':
    pygame.init()

    SCREEN_SIZE = (800, 600)               # initialize screen size
    SCREEN = display.set_mode(SCREEN_SIZE) # load screen

    triangle = Polygon([(0, 70), (110, 0), (110, 70)])
    rhombus = Polygon([(0, 80), (20, 0), (80, 0), (60, 80)])

    triangle.move_ip(200, 200)
    rhombus.move_ip(300, 300)

    grab, other, theta = None, None, 0
    while 1:
        SCREEN.fill((0, 0, 0))
        draw.polygon(SCREEN, (255, 0, 0), triangle.P, 1)
        draw.polygon(SCREEN, (0, 0, 255), rhombus.P, 1)
        mouse_pos = array(mouse.get_pos())
        for ev in event.get():
            if ev.type == KEYDOWN:
                if ev.key == K_q: exit()
                if ev.key == K_LEFT: theta = -0.01
                if ev.key == K_RIGHT: theta = 0.01
            if ev.type == KEYUP:
                if ev.key == K_LEFT: theta = 0
                if ev.key == K_RIGHT: theta = 0
            if ev.type == MOUSEBUTTONDOWN:
                if grab: grab, other = None, None
                elif rhombus.collidepoint(mouse_pos):
                    grab = rhombus
                    other = triangle
 def draw_scroll_right_button(self, surface):
     r = self.scroll_right_rect()
     c = self.scroll_button_color
     draw.polygon(surface, c, [r.topleft, r.midright, r.bottomleft])