示例#1
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)
示例#2
0
def draw_heart(x,
               y,
               a,
               h,
               f,
               xline,
               yline,
               colors=[COLOR['Red'], COLOR['Black']]):
    '''
    Рисует шарик-сердечко с заданными параметрами образующего треугольника и
    заданными координатами конца нитки с заданием угла поворота
    ----------------------------------------------------------
    x - горизонтальная координата центра основания образующего треугольника
    y - вертикальная координата центра основания образующего треугольника
    a - основание образующего треугольника
    h - высота образующего треугольника
    f - угол поворота фигуры
    xline - горизонтальная координата конца нитки
    yline - вертикальная координата конца нитки
    colors - кортеж цветов.
    '''
    draw_triangle(colors[0], x, y, a, h, f)
    pgd.circle(
        screen, colors[0],
        (int(round(x + a * np.cos(f) / 2)), int(round(y - a * np.sin(f) / 2))),
        a // 2)
    pgd.circle(
        screen, colors[0],
        (int(round(x - a * np.cos(f) / 2)), int(round(y - a * np.sin(f) / 2))),
        a // 2)

    pgd.aalines(screen, colors[1], False,
                [[x + h * np.sin(f), y + h * np.cos(f)], [xline, yline]])
示例#3
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)
示例#4
0
 def update(self, surface, snake, prey):
     if self.id_and_pos in snake:
         if self.id_and_pos == snake[-1:][0]:
             polygon(surface, (210, 205, 10), self.points, 0)
         else:
             polygon(surface, (35, 125, 30), self.points, 0)
     elif self is prey:
         polygon(surface, self.prey_color, self.points, 0)
     else:
         polygon(surface, self.color, self.points, 0)
     aalines(surface, (210, 205, 10), 1, self.points, 1)
示例#5
0
def drawPoly(view, transform, pointlist, lightlist, color = black, width = 0):  
    lst = [ transform(p).xy() for p in pointlist ]
    draw.aalines(view.display, color, True, lst, True)
    #draw.polygon(view.display, color, lst, width)
    gfxdraw.filled_polygon(view.display, lst, color)
    
    


    
    
示例#6
0
 def render(self, screen: Surface, selected: List[Tuple]):
     if len(selected) > 0:
         circle_centres = [((col + 0.5) * self.block_width,
                            (row + 0.5) * self.block_height)
                           for (row, col) in selected]
         surface = self.image.copy()
         if len(selected) > 1:
             aalines(surface, Color(255, 255, 255), False, circle_centres)
         for centre in circle_centres:
             circle(surface, Color(255, 255, 255), centre, 5)
         screen.blit(surface, self.rect, special_flags=BLEND_MAX)
示例#7
0
    def draw(self, screen):
        screen.fill(BLACK)

        first = self.waves[0]
        amp = mapf(first.amp, b=(0, self.scale))
        draw.aalines(screen, DARKER_GREY, True,
                     [(x - amp * cos(first.phase), y - amp * sin(first.phase))
                      for x, y in self.origin_path])

        origin = self.MIDDLE
        if not self.stop:
            for wave in self.waves[1:]:
                radius = mapf(wave.amp, b=(0, self.scale))
                gfxdraw.aacircle(screen, int(origin.x), int(origin.y),
                                 int(max(2, radius)), GREY)

                angle = self.t * wave.freq + wave.phase
                end_point = origin + (radius * cos(angle), radius * sin(angle))
                draw.aaline(screen, WHITE, origin.int_tuple,
                            end_point.int_tuple)

                origin = end_point

            self.trail.append(origin)
        length = len(self.trail)

        if length > 1:
            if self.teleport:
                prev = self.trail[0]
                for i in self.trail[1:]:
                    if prev.dist(i) < 10:
                        draw.aaline(screen, NICE_RED, prev.float_tuple,
                                    i.float_tuple)
                    prev = i
            else:
                draw.aalines(screen, NICE_RED, False,
                             list(map(lambda x: x.float_tuple, self.trail)))
            if not self.stop: self.t += self.dt
        if length > self.trail_length + 15:
            self.stop = True

        if self.zoom:
            scaled = transform.scale2x(screen)
            screen.fill(BLACK)
            screen.blit(scaled, (self.size[0] / 2 - origin.x * 2,
                                 self.size[1] / 2 - origin.y * 2))

        font = pygame.font.Font("NanumSquare.ttf", 17)
        text = font.render("https://github.com/pl-Steve28-lq", True, WHITE)
        rect = text.get_rect()
        rect.x = 10
        rect.y = int(self.size[1] - rect.size[1] * 3 / 2)
        screen.blit(text, rect)
 def draw(self, surf):
     if self.highlighted:
         r = self.get_margin_rect()
         fg = self.fg_color
         d = self.check_mark_tweak
         p1 = (r.left, r.centery - d)
         p2 = (r.centerx - d, r.bottom)
         p3 = (r.right, r.top - d)
         if self.smooth:
             draw.aalines(surf, fg, False, [p1, p2, p3])
         else:
             draw.lines(surf, fg, False, [p1, p2, p3])
示例#9
0
 def draw(self, surface, mouse_pos):
     if self.rect.collidepoint(mouse_pos):
         polygon(surface, (255 - self.color[0], 255 - self.color[1],
                           255 - self.color[2]), self.points, 0)
     else:
         polygon(surface, self.color, self.points, 0)
     aalines(surface, self.border_color, True, self.points, 1)
     #aalines(surface, self.border_color, True, ((self.rect.x, self.rect.y),
     #                                           (self.rect.x + self.rect.width, self.rect.y),
     #                                           (self.rect.x + self.rect.width, self.rect.y + self.rect.height),
     #                                           (self.rect.x, self.rect.y + self.rect.height)), 1)
     surface.blit(self.lable, (self.rect.x + self.rect.width // 7,
                               self.rect.y + self.rect.height // 2.8))
示例#10
0
    def draw_func(self, fun, n=20, colour='blue'):
        """ draw an arbitrary function with n line segments
        pass colour from tools.clrs or rgb value

        plot.draw_func( f(x), n = 20, colour = 'blue' ) -> None
        """
        if str(colour) in clrs.info:
            colour = clrs[colour]

        line = [
            self.to_screen(x, fun(x))
            for x in np.linspace(self.lo_x, self.hi_x, num=n)
        ]
        pgdraw.aalines(self.screen, colour, False, line)
def renderHex(name, size = 64, color = Color(128,128,128), smooth = False, fill = False, dashed = False, width = 5):
    outscribeSize = size*2*math.tan(30*math.pi/180)
    surf = Surface((int(outscribeSize*2)+width*2,int(outscribeSize*2)+width*2))
    surf.fill(Color(0,0,0))
    points = []
    for deg in range(0,360,60):
        rad = math.pi/180 * deg
        points.append((outscribeSize+width+math.cos(rad)*(outscribeSize),
                       outscribeSize+width+math.sin(rad)*(outscribeSize)))
    if smooth:
        Draw.aalines(surf, color, True, points)
    else:
        Draw.lines(surf, color, True, points)
    Image.save(surf,name)
    print ("Hex {} rendered.  Inscribed radius: {}".format(name,outscribeSize*math.cos(30*math.pi/180)))
示例#12
0
    def _draw_radar_outline(self, obj):
        from math import pi, cos, sin

        angle = theme.tank_radar_angle
        angle_r = (obj.status.direction - angle // 2) / 180.0 * pi
        angle_l = (obj.status.direction + angle // 2) / 180.0 * pi
        radar_range = theme.tank_radar_range
        points = [
            Point(obj.status.x + cos(angle_r) * radar_range,
                  obj.status.y + sin(angle_r) * radar_range),
            Point(obj.status.x + cos(angle_l) * radar_range,
                  obj.status.y + sin(angle_l) * radar_range),
            Point(obj.status.x, obj.status.y)
        ]
        points = [x.to_screen() for x in points]
        aalines(self.screen, obj._debug_color, True, points)
示例#13
0
    def draw(self, screen):
        step = 360 / self.res
        points = []
        i = 0
        while i < self.res:
            points.append(
                Vector2(
                    self.pos.x +
                    cos(radians(i * step + self.spin)) * self.size / 2,
                    self.pos.y +
                    sin(radians(i * step + self.spin)) * self.size / 2))
            i += 1

        draw.aalines(screen, cfg.white, True, points)

        self.spin += 1
        return
示例#14
0
    def _draw_radar_outline(self, obj):
        from math import pi, cos, sin

        angle = theme.tank_radar_angle
        angle_r = (obj.status.direction - angle // 2) / 180.0 * pi
        angle_l = (obj.status.direction + angle // 2) / 180.0 * pi
        radar_range = theme.tank_radar_range
        points = [
            Point(obj.status.x + cos(angle_r) * radar_range,
                  obj.status.y + sin(angle_r) * radar_range),
            Point(obj.status.x + cos(angle_l) * radar_range,
                  obj.status.y + sin(angle_l) * radar_range),
            Point(obj.status.x,
                  obj.status.y)
        ]
        points = [x.to_screen() for x in points]
        aalines(self.screen, obj._debug_color, True, points)
示例#15
0
    def draw(self, screen):
        # Create points of equilateral triangle around the center of the ship
        p1 = Vector2(cos(radians(self.dir)) * self.size +
                     self.pos.x, sin(radians(self.dir)) * self.size + self.pos.y)
        p2 = Vector2(cos(radians(self.dir + 120)) * self.size +
                     self.pos.x, sin(radians(self.dir + 120)) * self.size + self.pos.y)
        p3 = Vector2(cos(radians(self.dir + 240)) * self.size +
                     self.pos.x, sin(radians(self.dir + 240)) * self.size + self.pos.y)
        points = [p1, p2, p3]

        # Draw ship with antialiased lines
        draw.aalines(screen, cfg.white, True, points)

        for B in self.bullets:
            B.draw(screen)

        return
示例#16
0
    def draw(self):
        Global.window.fill(BLACK)  # clear display window

        Global.drawSurface.fill(DARKER_GRAY)  # clear drawing surface
        pygame_draw.aalines(Global.drawSurface, Global.lineColor, False,
                            self.vertices, 1)
        #image = pygame.transform.rotate(Global.drawSurface, self.spinAngle)
        # rect = image.get_rect(center = (GUI_WIDTH + Global.cx, Global.cy)) # set the position of the image's center
        # Global.window.blit(image, rect)  # draw the rotated surface onto the window
        Global.window.blit(Global.drawSurface, (GUI_WIDTH, 0))

        Global.guiSurface.fill(BLACK)  # clear GUI surface
        for c in self.controls.values():
            c.draw(Global.guiSurface)  # draw all controls onto the GUI surface
        Global.window.blit(Global.guiSurface,
                           (0, 0))  # draw the surface onto the window

        display.update()
示例#17
0
    def draw(self, theSurface: Surface):
        """

        Args:
            theSurface:  The surface to draw on


        """
        if self.highlighted:
            r = self.get_margin_rect()
            fg = self.fg_color
            d = CHECK_MARK_TWEAK
            p1 = (r.left, r.centery - d)
            p2 = (r.centerx - d, r.bottom)
            p3 = (r.right, r.top - d)
            if self.smooth:
                draw.aalines(theSurface, fg, False, [p1, p2, p3])
            else:
                draw.lines(theSurface, fg, False, [p1, p2, p3])
示例#18
0
def boys(y_head,
         colors=(COLOR['Black'], COLOR['Human'], COLOR['Blue']),
         place=[1, 4]):
    '''
    Рисует мальчиков на заданных местах с фиксированным положением рук
    ----------------------------------------------------------
    y_head - координата макушки мальчика
    colors - кортеж цветов
    place - лист с номером положений мальчиков
    '''
    for i in place:
        for p in [-1, 1]:
            pgd.aalines(screen, colors[0], False,
                        [[
                            HUMAN['Dist'] * i + p * HUMAN['Head'] / 2,
                            y_head + 2.5 * HUMAN['Head']
                        ],
                         [
                             HUMAN['Dist'] * i + p * 3 * HUMAN['Head'] * 0.9,
                             y_head + 5 * HUMAN['Head'] * 0.9
                         ]])

            pgd.aalines(screen, colors[0], False,
                        [[
                            HUMAN['Dist'] * i + p * HUMAN['Head'] / 2,
                            y_head + 3.3 * HUMAN['Head']
                        ],
                         [
                             HUMAN['Dist'] * i + p * 5 * HUMAN['Head'] / 8,
                             y_head + 7 * HUMAN['Head'] / 2 + HUMAN['Height']
                         ],
                         [
                             HUMAN['Dist'] * i + p * HUMAN['Head'],
                             y_head + 7 * HUMAN['Head'] / 2 + HUMAN['Height']
                         ]])

        pgd.ellipse(
            screen, colors[2],
            (HUMAN['Dist'] * i - HUMAN['Head'], y_head + 3 * HUMAN['Head'] / 2,
             2 * HUMAN['Head'], HUMAN['Height']))
        pgd.circle(screen, colors[1],
                   (HUMAN['Dist'] * i, y_head + HUMAN['Head']), HUMAN['Head'])
    def update(cls):
        fondo = display.get_surface()
        rect = [fondo.fill(COLOR_BG)]
        if System.type_mode:
            color = (0, 255, 0)
        else:
            color = (255, 0, 0)

        r = fondo.blit(cls.typemode_label, (505, 360))
        cls.typemode_mark.fill(color)
        fondo.blit(cls.typemode_mark, (r.right + 3, r.y))

        rect.extend(cls.widgets.draw(fondo))
        if cls.on_selection:
            corners = [
                cls.selection.rect.topleft, cls.selection.rect.topright,
                cls.selection.rect.bottomright, cls.selection.rect.bottomleft
            ]
            draw.aalines(fondo, cls.selection.color, 1, corners)
        display.update(rect)
示例#20
0
        def __init__(self, radius, attitude=0):
            self.radius = radius
            self.attitude = attitude
            self.__sides_dict = dict()

            r1 = self.radius / cos(pi / 6)
            if self.attitude == 0:
                lines = [(round(cos(i / 6 * pi2) * self.radius / cos(pi / 6) + r1 + 1),
                          round(sin(i / 6 * pi2) * self.radius / cos(pi / 6) + self.radius) + 1)
                         for i in range(0, 6)]
                image = Surface((round(2 * r1) + 3, round(2 * self.radius) + 3))
            else:
                lines = [(sin(i / 6 * pi2) * self.radius / cos(pi / 6) + self.radius,
                          cos(i / 6 * pi2) * self.radius / cos(pi / 6) + r1)
                         for i in range(0, 6)]
                image = Surface((round(2 * self.radius), round(2 * r1)))

            for side in _STONE_ENTITY_3:
                self.__sides_dict[side] = image.copy()
                self.__sides_dict[side].set_colorkey((0, 0, 0))
                draw.aalines(self.__sides_dict[side], _STONE_ENTITY_3[side], True, lines)
示例#21
0
def draw_hexagon(Surface, position, radius=RADIUS):
    points = [(sin(i / 6 * tau) * radius + position[0],
               cos(i / 6 * tau) * radius + position[1]) for i in range(0, 6)]
    # Filled
    #pygame.draw.polygon(Surface, BLUE, points)
    # Only lines
    return aalines(
        Surface,
        BLACK,
        True,
        points,
    )
示例#22
0
def show(screen):
    global t

    screen.fill(BLACK)

    # Original path
    draw.aalines(screen, DARKER_GREY, True, original_path)

    # Epicycles
    origin = MIDDLE  # type: Vec2d
    for wave in waves:

        # Circle
        radius = mapf(wave.amp, b=(0, SCALE))
        #draw.circle(screen, DARK_GREY, origin.int_tuple, int(max(2, radius)), 1)
        gfxdraw.aacircle(screen, int(origin.x), int(origin.y),
                         int(max(2, radius)), DARK_GREY)

        # Line
        angle = t * wave.freq + wave.phase
        end_point = origin + (radius * cos(angle), radius * sin(angle))
        draw.aaline(screen, WHITE, origin.int_tuple, end_point.int_tuple)

        origin = end_point

    # Trail
    trail.append(origin.float_tuple)
    if len(trail) > trail_length:
        trail.pop(0)
    if len(trail) > 1:
        draw.aalines(screen, NICE_RED, False, trail)

    # Zoom
    if ZOOM:
        scaled = transform.scale2x(screen)
        screen.fill(BLACK)
        screen.blit(scaled,
                    (WIDTH / 2 - origin.x * 2, HEIGHT / 2 - origin.y * 2))

    t += dt
示例#23
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]])
示例#24
0
def clew(location, coefficient_size):

    # This function creates clew

    color_grey = (128, 128, 128)
    circle(win, color_grey, (location[0], location[1]), 50 / coefficient_size)
    circle(win, (0, 0, 0), (location[0], location[1]), 50 / coefficient_size,
           2)

    aalines(win, (0, 0, 0), False,
            ((location[0] - 30 / coefficient_size, location[1] +
              30 / coefficient_size), (location[0] - 20 / coefficient_size,
                                       location[1] + 25 / coefficient_size),
             (location[0] - 10 / coefficient_size,
              location[1] + 20 / coefficient_size),
             (location[0], location[1] + 10 / coefficient_size),
             (location[0] + 30 / coefficient_size,
              location[1] - 20 / coefficient_size)))
    aalines(win, (0, 0, 0), False,
            ((location[0] - 25 / coefficient_size, location[1] +
              40 / coefficient_size), (location[0] - 20 / coefficient_size,
                                       location[1] + 35 / coefficient_size),
             (location[0] - 10 / coefficient_size,
              location[1] + 30 / coefficient_size),
             (location[0], location[1] + 20 / coefficient_size),
             (location[0] + 30 / coefficient_size,
              location[1] - 10 / coefficient_size)))
    aalines(win, (0, 0, 0), False,
            ((location[0] - 30 / coefficient_size, location[1] +
              20 / coefficient_size), (location[0] - 20 / coefficient_size,
                                       location[1] + 10 / coefficient_size),
             (location[0] - 10 / coefficient_size, location[1]),
             (location[0], location[1] - 10 / coefficient_size),
             (location[0] + 20 / coefficient_size,
              location[1] - 40 / coefficient_size)))
示例#25
0
    def draw_voronoi_dual(self):
        """
        Draws the Delaunay triangulation of cell centers.
        """

        points = [center.loc for center in self.centers]
        points.append(self.color_center.loc)
        try:
            dual = Delaunay(points)
        except (QhullError, ValueError):
            #Either too few points or points are degenerate.
            return

        simplices = [[dual.points[i].astype(int) for i in simplex] for simplex in dual.simplices]

        if self.fill:
            for simplex in simplices:
                polygon(self.WINDOW, self.color(simplex, dual=True), simplex)

        if self.outline:
            for simplex in simplices:
                aalines(self.WINDOW, (255, 255, 255), True, simplex, 1)
示例#26
0
    def draw_voronoi_cells(self):
        """
        This function will handle drawing voronoi cells, drawing cell outlines,
        coloring cells.
        """


        points = [center.loc for center in self.centers]
        points.append(self.color_center.loc)

        try:
            vor = Voronoi(points)
        except (QhullError, ValueError):
            #Either too few points or points are degenerate.
            return
        #-----------------------------------------------------------------
        #'polygons' equals all Voronoi regions with at least 3 drawable
        #vertices (We can't draw a polygon with fewer than 3 points.) along
        #with the center associated with each region. (We use the center
        #location to color the region.)
        #
        #vor.regions is a list of lists (a list for each region) of indices
        #of points in vor.vertices; in these lists a '-1' represents a
        #"point at infinity" -- these aren't drawable so we "forget" these
        #in our polygons list.
        #-----------------------------------------------------------------
        polygons = [(vor.points[np.where(vor.point_region == i)],
                     [vor.vertices[j].astype(int) for j in reg if j != -1])
                    for i, reg in enumerate(vor.regions)
                    if len(reg) > 3 or (len(reg) == 3 and -1 not in reg)]

        if self.fill:
            for center, poly in polygons:
                polygon(self.WINDOW, self.color(center), poly)

        if self.outline:
            for _, poly in polygons:
                aalines(self.WINDOW, (255, 255, 255), True, poly, 1)
示例#27
0
    def draw_case(self, df, x0=0, y0=0, n=20, colour='red'):
        """ draw a line from a starting position, with n line segments
        pass colour from tools.clrs or rgb value

        plot.draw_case( y'(x, y), x0 = 0, y0 = 0, n = 20, colour = 'red' ) -> None
        """

        if str(colour) in clrs.info:
            colour = clrs[colour]  # see if passed colour is in clrs

        def case(x, x0, y0):  # generate an approximating function
            xs = []
            ys = []

            xspace = np.linspace(x0, x, num=n)
            h = xspace[1] - xspace[0]  # step size

            for c, dx in enumerate(xspace):
                if c == 0:  # assume starting position
                    xs.append(x0)
                    ys.append(y0)
                    continue

                xs.append(dx)
                dy = df(xs[c - 1], ys[c - 1]) * h  # follow slope
                ys.append(ys[c - 1] + dy)  # to get new y
            return list(zip(xs, ys))

        if self.hi_x > 0:
            cas = case(self.hi_x, x0, y0)
            line = [self.to_screen(point) for point in cas]
            pgdraw.aalines(self.screen, colour, False, line)
        if self.lo_x < 0:
            cas = case(self.lo_x, x0, y0)
            line = [self.to_screen(point) for point in cas]
            pgdraw.aalines(self.screen, colour, False, line)
示例#28
0
def girls(y_head,
          colors=(COLOR['Black'], COLOR['Human'], COLOR['Pink']),
          place=[2, 3]):
    '''
    Рисует девочек на заданных местах с фиксированным положением рук
    ----------------------------------------------------------
    y_head - координата макушки девочки 
    colors - кортеж цветов
    place - лист с номером положений девочек
    '''
    for i in place:
        pgd.aalines(
            screen, colors[0], False,
            [[
                HUMAN['Dist'] * i +
                (i - 2.5) * 2 * HUMAN['Head'] / 2, y_head + 2.5 * HUMAN['Head']
            ],
             [
                 HUMAN['Dist'] * i + (i - 2.5) * 6 * HUMAN['Head'] * 0.9,
                 y_head + 5 * HUMAN['Head'] * 0.9
             ]])

        pgd.aalines(
            screen, colors[0], False,
            [[
                HUMAN['Dist'] * i -
                (i - 2.5) * 2 * HUMAN['Head'] / 2, y_head + 2.5 * HUMAN['Head']
            ],
             [
                 HUMAN['Dist'] * i -
                 (i - 2.5) * 10 * HUMAN['Head'] / 4, y_head + 4 * HUMAN['Head']
             ],
             [
                 HUMAN['Dist'] * i -
                 (i - 2.5) * 11 * HUMAN['Head'] / 2, y_head + 3 * HUMAN['Head']
             ]])
        for p in [-1, 1]:
            pgd.aalines(screen, colors[0], False,
                        [[
                            HUMAN['Dist'] * i + p * HUMAN['Head'] / 2,
                            y_head + 3.3 * HUMAN['Head']
                        ],
                         [
                             HUMAN['Dist'] * i + p * 5 * HUMAN['Head'] / 8,
                             y_head + 7 * HUMAN['Head'] / 2 + HUMAN['Height']
                         ],
                         [
                             HUMAN['Dist'] * i + p * HUMAN['Head'],
                             y_head + 7 * HUMAN['Head'] / 2 + HUMAN['Height']
                         ]])

        draw_triangle(colors[2], HUMAN['Dist'] * i,
                      y_head + 3 * HUMAN['Head'] / 2 + HUMAN['Height'],
                      2 * HUMAN['Head'], HUMAN['Height'], np.pi / 1)
        pgd.circle(screen, colors[1],
                   (HUMAN['Dist'] * i, y_head + HUMAN['Head']), HUMAN['Head'])
示例#29
0
def _draw_shape_draft(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;
    """
    
    # Get some of the shape attributes
    ref_point = shape.get_ref_point()
    r_inner = shape.get_r_inner()
    
    # Draw the shape edges
    shape_bounds = draw.aalines(
        surface, SHAPE_COLOR, True, shape.get_vertices()
    )
    
    # Draw the shape inner circle
    draw.circle(
        surface, SHAPE_COLOR,
        # NB! draw.circle() expects integer arguments
        map(int, ref_point), int(r_inner),
        1 # circle edge width
    )
    
    # Draw the cross in the inner circle center
    for (a, b) in (
        ((-1, 0), (+1, 0)),
        ((0, +1), (0, -1))
        
    ):
        draw.aaline(
            surface, SHAPE_COLOR,
            *[
                [
                    ref_point[coord] + r_inner / 3 * p[coord]
                    for coord in (0, 1)
                ]
                for p in (a, b)
            ]
        )
    
    return shape_bounds
示例#30
0
    def aalines(self, color, closed, pointlist, blend=1):
        """アンチエイリアス処理のなされた複数の連結された直線を描画します.

        Parameters
        ----------
        color : tuple of int
            描画に使用される色を指定します.
        closed : bool
            Trueに設定された場合, 始点と終点を直線でつないで描画します.
        pointlist : array-like
            頂点の座標を格納した2次元配列.
            配列の2次元目の要素数は2で, 少なくとも2点以上の座標を設定する必要があります.
        blend : int or bool
            Trueに設定された場合、描画位置のピクセルに上書きはされず , 半透明の状態で描画されます.

        Returns
        -------
        rect : pygame.Rect
            描画によって影響を受けた範囲を示すpygame.Rectオブジェクトを返します.

        """

        return pyd.aalines(self.pg.screen, color, closed, pointlist, blend)
示例#31
0
def _draw_shape_draft(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;
    """

    # Get some of the shape attributes
    ref_point = shape.get_ref_point()
    r_inner = shape.get_r_inner()

    # Draw the shape edges
    shape_bounds = draw.aalines(surface, SHAPE_COLOR, True,
                                shape.get_vertices())

    # Draw the shape inner circle
    draw.circle(
        surface,
        SHAPE_COLOR,
        # NB! draw.circle() expects integer arguments
        map(int, ref_point),
        int(r_inner),
        1  # circle edge width
    )

    # Draw the cross in the inner circle center
    for (a, b) in (((-1, 0), (+1, 0)), ((0, +1), (0, -1))):
        draw.aaline(
            surface, SHAPE_COLOR,
            *[[ref_point[coord] + r_inner / 3 * p[coord] for coord in (0, 1)]
              for p in (a, b)])

    return shape_bounds
示例#32
0
 def aalines(self, color, points, closed=False, width=1, screen=False):
     points = points if screen else list(map(self._vec2_to_screen, points))
     return draw.aalines(self.surface, color, closed, points, width)
示例#33
0
 def blit(self, surface):
     self.update()
     draw.aalines(surface, self.color, 1, self.points, 1)
示例#34
0
def drawPoly(view, transform, pointlist, lightlist, color=black, width=0):
    lst = [transform(p).xy() for p in pointlist]
    draw.aalines(view.display, color, True, lst, True)
    #draw.polygon(view.display, color, lst, width)
    gfxdraw.filled_polygon(view.display, lst, color)
示例#35
0
 def blit(self, surface):
     self.update()
     draw.aalines(surface, self.color, 1, self.points, 1)
示例#36
0
    def draw(self, surface, rect):
        onScreen = []

        if self.blank:
            self.blank = False
            self.maprender.blank = True

        # quadtree collision testing would be good here
        for entity, shape in self.area.shapes.items():
            if entity.avatar:
                w, h = entity.avatar.image.get_size()
                try:
                    points = shape.get_points()
                except AttributeError:
                    temp_rect = entity.avatar.image.get_rect()
                    temp_rect.center = shape.body.position
                    x, y = self.area.worldToPixel(temp_rect.topleft)
                else:
                    l = 99999
                    t = 99999
                    r = 0
                    b = 0
                    for x, y in points:
                        if x < l: l = x
                        if x > r: r = x
                        if y < t: t = y
                        if y > b: b = y
                    ax, ay = entity.avatar.axis
                    x, y = self.area.worldToPixel((l-ax,b-ay))

                x -= self.extent.left
                y -= self.extent.top
                onScreen.append((entity.avatar.image, Rect((x, y), (w, h)), 1))

        # should not be sorted every frame
        #onScreen.sort(key=screenSorter)

        if parallax:
            self.parallaxrender.draw(surface, rect, [])

        dirty = self.maprender.draw(surface, rect, onScreen)

        if DEBUG:
            def translate((x, y)):
                return x - self.extent.left, y - self.extent.top

            for shape in self.area.space.shapes:
                try:
                    points = [ translate(i) for i in shape.get_points() ]
                except AttributeError:
                    pass
                else:
                    draw.aalines(surface, (255,100,100), 1, points)
                    continue

                try:
                    radius = shape.radius
                    pos = shape.body.position
                    pos = translate((int(pos.x), int(pos.y)))
                except AttributeError:
                    pass
                else:
                    draw.circle(surface, (255,100,100), pos, int(radius), 1)
                    continue

            #for i in onScreen:
            #    draw.rect(surface, (100,255,100), i[1])

        return dirty
示例#37
0
    def draw(self, surface, rect):
        onScreen = []

        if self.blank:
            self.blank = False
            self.maprender.blank = True

        visible_shapes = self.area.space.bb_query(toBB(self.extent))

        for child in [ child for child in self.area if child.avatar]:
            shape = child.shapes[0]
            if shape not in visible_shapes:
                continue

            bb = child.bb
            x = bb.left - self.extent.left - child.avatar.axis.x
            y = bb.top - self.extent.top

            if hasattr(shape, "radius"):
                w, h = child.avatar.image.get_size()
                angle = -(math.degrees(shape.body.angle)) % 360
                image = rotozoom(child.avatar.image.convert_alpha(), angle, 1.0)
                ww, hh = image.get_size()
                rrect = Rect(x, y-h, ww, hh)
                rrect.move_ip((w-ww)/2, (h-hh)/2)
            else:
                w, h = child.avatar.image.get_size()
                rrect = Rect(x, y - h, w, h)
                image = child.avatar.image
            onScreen.append((image, rrect, 1))

        if parallax:
            self.parallaxrender.draw(surface, rect, [])

        dirty = self.maprender.draw(surface, rect, onScreen)

        if DEBUG:
            def translate((x, y)):
                return x - self.extent.left, y - self.extent.top

            for shape in self.area.space.shapes:
                try:
                    points = [ translate(i) for i in shape.get_points() ]
                except AttributeError:
                    pass
                else:
                    draw.aalines(surface, (255,100,100), 1, points)
                    continue

                try:
                    radius = shape.radius
                    pos = shape.body.position
                    pos = translate(pos)
                    pos += shape.offset
                except AttributeError:
                    pass
                else:
                    pos = map(int, pos)
                    draw.circle(surface, (255,100,100), pos, int(radius), 1)
                    continue

        return dirty