예제 #1
0
def koordinatni(screen, X, Y, b):
    xos1 = np.array([0, Y - 100])
    xos2 = np.array([X, Y - 100])
    yos1 = np.array([X // 2, 0])
    yos2 = np.array([X // 2, Y])
    line(screen, b, xos1, xos2)
    line(screen, b, yos1, yos2)
예제 #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)
예제 #3
0
파일: playfield.py 프로젝트: tps12/Dorftris
    def update(self):
        ps = [self._position(loc)
              for loc in self.region]
                    
        if len(self._ps) == len(ps) and all([self._ps[i] == ps[i]
                                             for i in range(len(ps))]):
            return

        self._ps = ps
        pos = [min([p[i] for p in self._ps]) for i in range(2)]
        adj = self._zoom.width+self._zoom.height/3, self._zoom.height + 1
        size = [max([p[i] for p in self._ps]) - pos[i] + adj[i]
                for i in range(2)]
        self.image = Surface(size, flags=SRCALPHA)
        lines = []
        for p in self._ps:
            for edge in [sorted([[v[j][i] + p[i] - pos[i]
                                  for i in range(2)]
                                 for j in range(2)])
                         for v in self._lines()]:
                if edge in lines:
                    lines.remove(edge)
                else:
                    lines.append(edge)
        for line in lines:
            draw.line(self.image, self._color, line[0], line[1])
        self.rect = self.image.get_rect().move((pos[0]-self._zoom.height/3,
                                                pos[1]))
        self.dirty = 1
예제 #4
0
def draw_points(poly, surface, color=None, width=None):
    polygon = orient_multipoint(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

    maxd = (0,None,None)
    for i in range(len(polygon.geoms)):
        p = polygon.geoms[i]
        draw.circle(surface, color,
                    defloat(scale(offset((p.x,p.y), dx, dy))),
                    3*width)
        for j in range(i+1, len(polygon.geoms)):
            q = polygon.geoms[j]
            d = p.distance(q)
            if d > maxd[0]:
                maxd = (d, p, q)
    if maxd[0] > 0:
        p, q = maxd[1], maxd[2]
        draw.line(surface, color,
                  defloat(scale(offset((p.x,p.y), dx, dy))),
                  defloat(scale(offset((q.x,q.y), dx, dy))), width)
예제 #5
0
 def __init__(self, *groups):
     _layer = 3
     Base.__init__(self, groups)
     self.image = surface.Surface((600, 50))
     self.rect = self.image.get_rect(topleft=(0, 0))
     self.image.fill(WHITE)
     #desenhar quadrados
     start = 145
     for cores in color_dict.values():
         if cores != BLACK and cores != WHITE:
             draw.rect(self.image, cores, Rect((start, 0), (50, 50)))
             self.image.blit(
                 numeros.render(f'{int((start-95)/50)}', True, BLACK),
                 (start + 25, 0))
         elif cores == WHITE:
             self.image.blit(
                 numeros.render(f'{int((start-95)/50)}', True, BLACK),
                 (start + 25, 0))
         else:
             draw.rect(self.image, BLACK, Rect(start, 0, 50, 50))
             self.image.blit(
                 numeros.render(f'{int((start-95)/50)}', True, WHITE),
                 (start + 25, 0))
         draw.rect(self.image, BLACK, Rect(start, 0, 50, 50), 1)
         start += 50
     draw.line(self.image, RED, (550, 0), (600, 50), 5)
     draw.line(self.image, RED, (600, 0), (550, 50), 5)
     draw.rect(self.image, BLACK, Rect(550, 0, 50, 50), 1)
     self.image.blit(numeros.render(f'{0}', True, BLACK), (563, 0))
    def DrawBodyBones(self, Joints, JointsPoints, Color, Joint0, Joint1):
        '''
        Function that draw the skeleton in a frame.
        '''
        Joint0State = Joints[Joint0].TrackingState
        Joint1State = Joints[Joint1].TrackingState

        # If is not correct the tracking:
        if (Joint0State == PyKinectV2.TrackingState_NotTracked) or (
                Joint1State == PyKinectV2.TrackingState_NotTracked):
            return

        if (Joint0State == PyKinectV2.TrackingState_Inferred) and (
                Joint1State == PyKinectV2.TrackingState_Inferred):
            return

        # If the skeleton tracking is correct:
        Start = (JointsPoints[Joint0].x, JointsPoints[Joint0].y
                 )  # Start point coordinates.
        End = (JointsPoints[Joint1].x, JointsPoints[Joint1].y
               )  # Final point coordinates.

        # Draw a line with start and final points.
        try:
            if (Joint0State == PyKinectV2.TrackingState_Inferred) or (
                    Joint1State == PyKinectV2.TrackingState_Inferred):
                draw.line(self.FrameSurface, Color[1], Start, End, 8)

            else:
                draw.line(self.FrameSurface, Color[0], Start, End, 8)

        except:
            pass
예제 #7
0
    def draw(self):
        bgrect = wzglobals.background.get_rect()
        menupos = wzglobals.menu_bg.get_rect()
        menupos.centery = wzglobals.background.get_rect().centery
        # label X coord (left side from center)
        self.label_rect.left = bgrect.centerx - self.label_rect.width - 7
        self.label_rect.top = menupos.top + 50 + \
            (self.label_rect.height + 5) * self.pos
        # text X coord (right size from center)
        self.text_rect.left = bgrect.centerx + 7
        self.text_rect.top = self.label_rect.top

        self.image = pygame.Surface(
            (self.label_rect.width + 14 + self.size, self.font.get_linesize()),
            pygame.SRCALPHA
        )
        self.rect = self.image.get_rect()
        self.rect.left = self.label_rect.left
        self.rect.top = self.label_rect.top
        self.image.blit(self.label_image, (0, 0))
        self.image.blit(self.text_image, (self.label_rect.width + 14, 0))

        if self.focus:
            # X coordinate of the cursor
            cursorx = self.font.size(self.text[:self.currpos])[0]
            cursorx += self.label_rect.width + 14
            draw.line(
                self.image,
                (255, 255, 255),
                (cursorx, 0),
                (cursorx, self.font.get_height())
            )

        wzglobals.background.blit(self.image, self.label_rect)
예제 #8
0
    def display(self, surface):

        line(surface, self.color,
             (int(self.v.x) + (Config.frameWidth / 2), int(self.v.y) +
              (Config.frameHeight / 2)),
             (int(self.u.x) + (Config.frameWidth / 2), int(self.u.y) +
              (Config.frameHeight / 2)), self.width)
예제 #9
0
 def _blit_ray(self):
     if self._blitting_surface is not None:
         surface_width = self._blitting_surface.get_width()
         surface_height = self._blitting_surface.get_height()
         if not self._decart_camera_position[
                 0] == self._decart_mouse_position[0]:
             if self._mouse_position[0] > self._camera_position[0]:
                 x_range = (surface_width / 2 - self._decart_camera_position[0]) /\
                           (self._decart_mouse_position[0] - self._decart_camera_position[0])
             else:
                 x_range = self._camera_position[0] / (
                     self._camera_position[0] - self._mouse_position[0])
         else:
             x_range = float('inf')
         if not self._decart_camera_position[
                 1] == self._decart_mouse_position[1]:
             if self._mouse_position[1] < self._camera_position[1]:
                 y_range = (surface_height / 2 - self._decart_camera_position[1]) /\
                           (self._decart_mouse_position[1] - self._decart_camera_position[1])
             else:
                 y_range = (surface_height - self._camera_position[1]) /\
                           (self._mouse_position[1] - self._camera_position[1])
         else:
             y_range = float('inf')
         rage = min(x_range, y_range)
         res = (
             (self._mouse_position[0] - self._camera_position[0]) * rage +
             self._camera_position[0],
             (self._mouse_position[1] - self._camera_position[1]) * rage +
             self._camera_position[1])
         draw.line(self._blitting_surface, (0, 0, 0), res,
                   self._camera_position)
예제 #10
0
def test_vert_line(test_surf):
    """Draw several vertical lines."""
    x = 10
    for length in range(100):
        x += 5
        draw.line(test_surf, (255, 255, 255, 255),
                  (x, length), (x, 2 * length))
예제 #11
0
def test_vert_line(test_surf):
    """Draw several vertical lines."""
    x = 10
    for length in range(100):
        x += 5
        draw.line(test_surf, (255, 255, 255, 255), (x, length),
                  (x, 2 * length))
예제 #12
0
 def update(self):
     self.position = Vector(pygame.mouse.get_pos())
     self.image = Surface(self.rect.size, SRCALPHA)
     circle(self.image, self.color, (9, 9), 9, 1)
     line(self.image, self.color, (9, 0), (9, 18))
     line(self.image, self.color, (0, 9), (18, 9))
     self.update_rect()
예제 #13
0
파일: render.py 프로젝트: mjs/ldnpydojo
 def draw_spring(self, spring):
     draw.line(
         self.window.display_surface,
         (80, 120, 90),
         spring.verts_to_anchor1(spring.p1.verts),
         spring.verts_to_anchor2(spring.p2.verts),
         15)
예제 #14
0
파일: draw.py 프로젝트: reddragonnm/neatpy
def draw_brain_pygame(screen, brain, x=50, y=50, dim=300, circle_size=15, line_width=4, node_border_thickness=1):
    info = brain.get_draw_info()

    for conn in info['connections']['enabled']:
        line(
            screen,
            colors['dodgerblue'] if conn['weight'] > 0 else colors['coral'],
            (int(dim * conn['from'][1] + x), int(dim * conn['from'][0] + y)),
            (int(dim * conn['to'][1] + x), int(dim * conn['to'][0] + y)),
            line_width
        )

    for inp in info['nodes']['input']:
        circle(screen, colors['white'], (int(dim * inp[1] + x), int(dim * inp[0] + y)), circle_size)
        circle(screen, colors['black'], (int(dim * inp[1] + x), int(dim * inp[0] + y)), circle_size, node_border_thickness)

    for inp in info['nodes']['bias']:
        circle(screen, colors['white'], (int(dim * inp[1] + x), int(dim * inp[0] + y)), circle_size)
        circle(screen, colors['black'], (int(dim * inp[1] + x), int(dim * inp[0] + y)), circle_size, node_border_thickness)

    for inp in info['nodes']['hidden']:
        circle(screen, colors['white'], (int(dim * inp[1] + x), int(dim * inp[0] + y)), circle_size)
        circle(screen, colors['black'], (int(dim * inp[1] + x), int(dim * inp[0] + y)), circle_size, node_border_thickness)

    for inp in info['nodes']['output']:
        circle(screen, colors['white'], (int(dim * inp[1] + x), int(dim * inp[0] + y)), circle_size)
        circle(screen, colors['black'], (int(dim * inp[1] + x), int(dim * inp[0] + y)), circle_size, node_border_thickness)
예제 #15
0
def drawBoardGrid(screen, cGameGrid, boardX, boardY):
    for x in range(1, BOARD_WIDTH):
        draw.line(screen, cGameGrid, (boardX + x * 48, boardY),
                  (boardX + x * 48, boardY + 48 * BOARD_HEIGHT))
    for y in range(1, BOARD_HEIGHT):
        draw.line(screen, cGameGrid, (boardX, boardY + y * 48),
                  (boardX + 48 * BOARD_WIDTH, boardY + y * 48))
예제 #16
0
 def draw_graph_box_and_legend(self):
     x_end = self.left_bottom_corner_of_graph[0] + self.graph_box_length
     # y_end = self.left_bottom_corner_of_graph[1] - self.graph_box_length
     color = (30,30,30)
     draw.line(self.screen, color, 
                 self.left_bottom_corner_of_graph,
                 (self.left_bottom_corner_of_graph[0] + self.graph_box_length,
                     self.left_bottom_corner_of_graph[1]))
     draw.line(self.screen, color, 
                 self.left_bottom_corner_of_graph,
                 (self.left_bottom_corner_of_graph[0],
                     self.left_bottom_corner_of_graph[1] - self.graph_box_length))
     # legend
     x = self.field_length+padding_graph
     y = 10
     if not compare_wv_counts:
         rectsize = 15
         for legend_item_name, (legend_item_color,_) in self.legend_items.items():
             draw.rect(self.screen, Color(legend_item_color), [x,y, rectsize,rectsize])
             x += rectsize + 10
             x_size_text = self.draw_text(legend_item_name, x, y)
             x += x_size_text + 20
     elif compare_avg_qual_per_wv==1:
         self.draw_text("Average quality per WV",x,y)
     else:
         self.draw_text("WV distribution",x,y)
예제 #17
0
    def draw(self, screen, draw_subpath=True):
        """Draw the flight (and optinally its path).

        Arguments:
            screen {Surface} -- Surface to draw on.

        Keyword Arguments:
            draw_subpath {bool} -- Whether to draw the path of the flight.
                (default: {True})
        """

        pgdraw.circle(screen, (0, 0, 0), vec2int(self.get_pos()),
                      self.ICON_SIZE, 0)
        dir_vect = pgmath.Vector2(
            0, 1).rotate(-self.direction) * Flight.ICON_SIZE * 2
        vect_point = dir_vect + self.get_pos()
        new_x = int(vect_point[0])
        new_y = int(vect_point[1])
        pgdraw.line(screen, (
            0,
            0,
            0,
        ), (self.x, self.y), (new_x, new_y))

        if (self.path is not None and self.is_landing()) and draw_subpath:
            self.path.draw_subpath(screen, self.path_pos)
 def draw_path(self, screen, path):
     for a, b in zip(path, path[1:]):
         start_pos = (a[0] * self.scale + self.scale // 2,
                      a[1] * self.scale + self.scale // 2)
         end_pos = (b[0] * self.scale + self.scale // 2,
                    b[1] * self.scale + self.scale // 2)
         line(screen, (255, 0, 255), start_pos, end_pos)
예제 #19
0
def draw_horizontal(row, player):
    posy = row * gap + gap / 2
    if player == 1:
        color = white
    if player == 2:
        color = grey
    draw.line(screen, color, (15, posy), (535, posy), 15)
예제 #20
0
 def render(self, surface: Surface):
     surface.blit(self.surface, (self.x, self.y))
     if self.underline_length:
         draw.line(surface, self.text_format.color,
                   (self.x, self.y + self.text_format.size),
                   (self.x + self.underline_length, self.y + self.text_format.size))
     self.click_area.render(surface)
예제 #21
0
    def update(self):
        self.display.lock()
        try:
            for w in range(self.model.width):
                for h in range(self.model.height):
                    pixel = self.model[h, w]
                    self.display.fill(
                        color.Color(int(pixel[0] * 255), int(pixel[1] * 255),
                                    int(pixel[2] * 255)),
                        Rect(w * self.cell_width, h * self.cell_height,
                             self.cell_width, self.cell_height))

            # Draw vertical lines
            for w in range(self.model.width):
                draw.line(self.display, color.Color(40, 40, 40),
                          (w * self.cell_width, 0),
                          (w * self.cell_width, self.sim_height),
                          self.border_thickness)
            # Draw horizontal lines
            for h in range(self.model.height):
                draw.line(self.display, color.Color(40, 40, 40),
                          (0, h * self.cell_height),
                          (self.sim_width, h * self.cell_height),
                          self.border_thickness)

            display.update()
        finally:
            self.display.unlock()
            return True
예제 #22
0
def mydraw(tx,ty,player):
    
    screen.blit(background,(0,0))
    for i in range(num_line):
        #print(i," ",num_raw-1)
        line(screen,color_line,(pos_line[i],pos_raw[0]),(pos_line[i],pos_raw[num_raw-1]),width_line)
    for i in range(num_raw):
        line(screen,color_line,(pos_line[0],pos_raw[i]),(pos_line[num_line-1],pos_raw[i]),width_line)
    for i in range(num_raw):
        for j in range(num_line):
            cm_y = i*len_check + len_frame - int(len_cm/2)
            cm_x = j*len_check + len_frame - int(len_cm/2)
            if mymatrix[i][j] == 1:
                screen.blit(bcm,(cm_x,cm_y))
            if mymatrix[i][j] == 2:
                screen.blit(wcm,(cm_x,cm_y))
    #screen.blit(wcm,(cm_x,cm_y))
    if tx < num_line and ty < num_raw and flag==0:
        if mymatrix[ty][tx] == 0:
            if player == 1:
                screen.blit(bcm,(tcm_x,tcm_y))
            if player == 2:
                screen.blit(wcm,(tcm_x,tcm_y))
            screen.blit(aim,(aim_x,aim_y))
    if flag == 1:
        screen.blit(p1w,(pos_win_y,pos_win_x))
    if flag == 2:
        screen.blit(p2w,(pos_win_y,pos_win_x))
    button_restart.render()
    button_set.render()
    button_retract.render()
    update()
예제 #23
0
def house(x: int, y: int, scale=1.0):
    """
    draws scaled house in given coordinates

    :param x: x coordinate
    :param y: y coordinate
    :param scale: size of a house
    :return: image on "screen" plane
    """
    d.rect(screen, brick, (x, y, int(140 * scale), int(100 * scale)))
    d.rect(screen, black, (x, y, int(140 * scale), int(100 * scale)), 1)
    d.polygon(screen, krisha, [[x, y], [x + int(140 * scale), y],
                               [x + int(70 * scale), y - int(70 * scale)]])
    d.polygon(screen, black, [[x, y], [x + int(140 * scale), y],
                              [x + int(70 * scale), y - int(70 * scale)]], 1)
    d.rect(screen, window,
           (x + int(45 * scale), y + int(30 * scale), int(
               50 * scale), int(35 * scale)))
    d.rect(screen, brown,
           (x + int(45 * scale), y + int(30 * scale), int(
               50 * scale), int(35 * scale)), 2)
    d.line(screen, brown, (x + int(70 * scale), y + int(30 * scale)),
           (x + int(70 * scale), y + int(65 * scale)), 2)
    d.line(screen, brown, (x + int(45 * scale), y + int(47 * scale)),
           (x + int(95 * scale), y + int(47 * scale)), 2)
    d.polygon(screen, black, [[x + int(105 * scale), y - int(80 * scale)],
                              [x + int(105 * scale), y - int(35 * scale)],
                              [x + int(117 * scale), y - int(25 * scale)],
                              [x + int(117 * scale), y - int(80 * scale)]])
예제 #24
0
 def draw_grid(self, win):
     for i in range(self.rows):
         draw.line(win, config["colors"]["GREY"], (0, i * self.gap),
                   (self.width, i * self.gap))
         for j in range(self.rows):
             draw.line(win, config["colors"]["GREY"], (j * self.gap, 0),
                       (j * self.gap, self.width))
예제 #25
0
def draw_vertical(col, player):
    posx = col * gap + gap / 2
    if player == 1:
        color = white
    if player == 2:
        color = grey
    draw.line(screen, color, (posx, 15), (posx, 535), 15)
예제 #26
0
파일: effects.py 프로젝트: erasmusa/sequtus
 def draw(self, surface, offset):
     adjusted_origin = (self.origin[0] + offset[0], self.origin[1] + offset[1])
     adjusted_target = (self.target[0] + offset[0], self.target[1] + offset[1])
     
     real_colour = [self.colour[i] - self.degrade[i] * self.age for i in range(3)]
     
     draw.line(surface, bound_colour(real_colour), adjusted_origin, adjusted_target, 2)
예제 #27
0
파일: arbasim.py 프로젝트: raomin/arbasdk
    def run(self):
        self.running = True
        while self.running:
            model = self.arbalet.end_model.data_frame
            with self.arbalet.sdl_lock:
                self.display.lock()
                for w in range(self.arbalet.width):
                    for h in range(self.arbalet.height):
                        pixel = model[h, w]
                        self.display.fill(
                            color.Color(int(pixel[0]), int(pixel[1]),
                                        int(pixel[2])),
                            Rect(w * self.cell_width, h * self.cell_height,
                                 self.cell_width, self.cell_height))

                # Draw vertical lines
                for w in range(self.arbalet.width):
                    draw.line(self.display, color.Color(40, 40, 40),
                              (w * self.cell_width, 0),
                              (w * self.cell_width, self.sim_height),
                              self.border_thickness)
                # Draw horizontal lines
                for h in range(self.arbalet.height):
                    draw.line(self.display, color.Color(40, 40, 40),
                              (0, h * self.cell_height),
                              (self.sim_width, h * self.cell_height),
                              self.border_thickness)
                display.update()
                self.display.unlock()
            self.rate.sleep()

        with self.arbalet.sdl_lock:
            display.quit()
예제 #28
0
 def draw_field(self, players):
     canvas = Surface((self.raw_w, self.raw_h))
     for row in range(len(FIELD)):
         for col in range(len(FIELD[0])):
             scr_x = col * TILE_scale
             scr_y = row * TILE_scale
             subsurf = canvas.subsurface(
                 (scr_x, scr_y, TILE_scale, TILE_scale))
             subsurf.fill(TILE_CLRs[FIELD[row][col]])
     for i in range(4):
         player = players[i]  # type: Player
         player_color = PLAYER_CLRs[i]
         if player:
             pos_x = (player.position.x + 0.0) * TILE_scale
             pos_y = (player.position.y - 1.0) * TILE_scale
             draw.rect(canvas, player_color,
                       (pos_x, pos_y, TILE_scale, TILE_scale * 2), 0)
             aim_origin = player.get_shoot_origin() * TILE_scale
             draw.line(canvas, CLR_red, aim_origin,
                       aim_origin + player.look_direction * TILE_scale * 30)
             for e in player.events:
                 if e is "jump":
                     self.add_effect(
                         (pos_x + 0.5 * TILE_scale, pos_y + 2 * TILE_scale),
                         player_color)
                     player.events.remove(e)
                 else:
                     pass
             # because those events are triggered by input.poll()
             # they get reset instantly afterwards
             # when the commands are passed as events to player update this reset will be moved to player update
             player.events = []
     return canvas
예제 #29
0
 def get_imgs():
     """Load an return the images used as file and folder icons."""
     print("*** MCEDIT DEBUG: file_dialog:", __file__)
     print("*** MCEDIT DEBUG: directory:", os.path.dirname(__file__))
     print("*** MCEDIT DEBUG: current directory:", os.getcwd())
     try:
         file_image = get_image('file.png', prefix='')
         folder_image = get_image('folder.png', prefix='')
     except Exception as e:
         print("MCEDIT DEBUG: Could not load file dialog images.")
         print(e)
         from pygame import draw, Surface
         from pygame.locals import SRCALPHA
         from math import pi
         file_image = Surface((16, 16), SRCALPHA)
         file_image.fill((0, 0, 0, 0))
         draw.lines(file_image, (255, 255, 255, 255), False,
                    [[3, 15], [3, 1], [13, 1]], 2)
         draw.line(file_image, (255, 255, 255, 255), [3, 7], [10, 7], 2)
         folder_image = Surface((16, 16), SRCALPHA)
         folder_image.fill((0, 0, 0, 0))
         draw.line(folder_image, (255, 255, 255, 255), [3, 15], [3, 1], 2)
         draw.arc(folder_image, (255, 255, 255, 255), [0, 1, 13, 15], 0,
                  pi / 1.9, 2)
         draw.arc(folder_image, (255, 255, 255, 255), [0, 1, 13, 15],
                  3 * pi / 2, 2 * pi, 2)
     return file_image, folder_image
예제 #30
0
def redraw_bg(state, screen):
    width, height = screen.get_size()
    # Draw the background
    for x in range(width):
        h = get_height(x - (width // 2) + int(state.bus.pos), state)
        h -= state.bus.altitude  # Keep the bus centred
        draw.line(screen, Color(0, 0, 0), (x, height), (x, (height // 2) - h))
예제 #31
0
파일: stick.py 프로젝트: alextuck97/PyPool
    def __draw_dashed(self, __display_surface, cue_ball_pos):
        '''
        Draws the dashed line from the cursor to the cue ball
        
        Also draws a rough trajectory of the ball. No information given on how for it will travel
        '''

        line_30 = self.dashed_p1 - self.dashed_p2  #Line for updating dashes
        line_30.scale_to_length(30)
        mouse_pos = pm.Vector2(ms.get_pos() - self.offset)
        drw.circle(__display_surface, (255, 255, 255),
                   [round(self.dashed_p1.x),
                    round(self.dashed_p1.y)], 8, 1)

        if mouse_pos.distance_to(
                cue_ball_pos
        ) > self.max_dist:  #Limit the distance the stick can be drawn
            line_200 = self.dashed_p1 - self.dashed_p2
            line_200.scale_to_length(200)
            mouse_pos = cue_ball_pos - line_200

        #Draw dashed lines until hit the mouse cursor
        while mouse_pos.distance_to(self.dashed_p2 - self.offset) > 15:
            drw.line(__display_surface, (255, 255, 255), self.dashed_p1,
                     self.dashed_p2, 1)
            self.dashed_p1 = self.dashed_p1 - line_30
            self.dashed_p2 = self.dashed_p2 - line_30
예제 #32
0
 def _draw_handle(self, image, size):
     # Draw handle
     image.fill((245, 245, 244))
     w, h = size
     for x in range(2, 5):  # Grips
         draw.line(image, (227, 227, 224), ((w / 6) * x, h * .3),
                   ((w / 6) * x, h * .7), 3)
예제 #33
0
    def draw(self):

        bgrect = globals.background.get_rect()
        menupos = globals.menu_bg.get_rect()
        menupos.centery = globals.background.get_rect().centery

        self.label_rect.left = bgrect.centerx - self.label_rect.width - 7  #label X coord (left side from center)
        self.label_rect.top = menupos.top + 50 + (self.label_rect.height +
                                                  5) * self.pos

        self.text_rect.left = bgrect.centerx + 7  # text X coord (right size from center)
        self.text_rect.top = self.label_rect.top

        self.image = pygame.Surface(
            (self.label_rect.width + 14 + self.size, self.font.get_linesize()),
            pygame.SRCALPHA)
        self.rect = self.image.get_rect()
        self.rect.left = self.label_rect.left
        self.rect.top = self.label_rect.top
        self.image.blit(self.label_image, (0, 0))
        self.image.blit(self.text_image, (self.label_rect.width + 14, 0))

        if self.focus:
            #X coordinate of the cursor
            cursorx = self.font.size(self.text[:self.currpos])[0]
            cursorx += self.label_rect.width + 14
            draw.line(self.image, (255, 255, 255), (cursorx, 0),
                      (cursorx, self.font.get_height()))

        globals.background.blit(self.image, self.label_rect)
예제 #34
0
    def move(self):
        incrx = unitary[self.d][0] * self.vel
        incry = unitary[self.d][1] * self.vel
        try:
            if self.d == 0:
                if windowSurface.get_at(
                    (self.x + incrx, self.y + incry)) != BLACK:
                    return True

            elif self.d == 1:

                if windowSurface.get_at(
                    (self.x + incrx, self.y + incry)) != BLACK:
                    return True
            else:

                if windowSurface.get_at(
                    (self.x + incrx, self.y + incry)) != BLACK:
                    return True
        except IndexError:
            return True

        line(windowSurface, self.c, (self.x, self.y),
             (self.x + incrx, self.y + incry), 1)
        self.x += incrx
        self.y += incry
        return False
예제 #35
0
    def draw(self, surface):
        frame = self.get_margin_rect()
        fg = self.fg_color
        font = self.font
        focused = self.has_focus()
        text, i = self.get_text_and_insertion_point()
        if focused and i is None:
            if self.selection_start is None or self.selection_end is None:
                surface.fill(self.sel_color, frame)
            else:
                startStep = self.selection_start
                endStep = self.selection_end

                if startStep > endStep:
                    x1, h = font.size(text[0:endStep])[0], font.get_linesize()
                    x2, h = font.size(text[0:startStep])[0], font.get_linesize()
                    x1 += frame.left
                    x2 += frame.left
                    y = frame.top
                    selRect = pygame.Rect(x1, y, (x2 - x1), h)
                else:
                    x1, h = font.size(text[0:startStep])[0], font.get_linesize()
                    x2, h = font.size(text[0:endStep])[0], font.get_linesize()
                    x1 += frame.left
                    x2 += frame.left
                    y = frame.top
                    selRect = pygame.Rect(x1, y, (x2 - x1), h)
                draw.rect(surface, self.sel_color, selRect)
        image = font.render(text, True, fg)
        surface.blit(image, frame)
        if focused and i is not None:
            x, h = font.size(text[:i]) #[0], font.get_linesize()
            x += frame.left
            y = frame.top
            draw.line(surface, fg, (x, y), (x, y + h - 1))
예제 #36
0
def draw_graph_pygame(graph, size=(500, 500)):
    pygame.init()
    screen = pygame.display.set_mode(size)
    white = pygame.Color('white')
    black = pygame.Color('black')
    screen.fill(white)

    font = freetype.SysFont("monospace", 10)

    done = False

    for v in graph.V:
        draw.circle(screen, black, (int(v.pos[0]), int(v.pos[1])), v.radius)
        font.render_to(screen, (int(v.pos[0]), int(v.pos[1])), str(v.idx))

    for e in graph.E:
        draw.line(screen, black, (int(e.v1.pos[0]), int(e.v1.pos[1])),
                  (int(e.v2.pos[0]), int(e.v2.pos[1])))

    while not done:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                done = True

        pygame.display.flip()
예제 #37
0
 def draw_grid_lines(self):
     for i in range(self.rows):
         draw.line(self.win, GREY, (0, i * self.square_size),
                   (self.width, i * self.square_size))
         for j in range(self.rows):
             draw.line(self.win, GREY, (j * self.square_size, 0),
                       (j * self.square_size, self.width))
예제 #38
0
파일: gui.py 프로젝트: 249550148/mygame
 def refresh(self):
     self.offset = self.style['offset']
     if self.size[1] < self.style['font'].get_ascent() + self.offset[1] * 2:
         self.size = (self.size[0], self.style['font'].get_ascent() + self.offset[1] * 2)
     self.textsurf = self.style['font'].render(self.pwdtext, self.style['antialias'], self.style['font-color'])
     if not self.surf or self.surf.get_size() != self.size:
         self.surf = pygame.Surface(self.size, pygame.SRCALPHA)
     if self.hasFocus:
         suffix = '-focus'
     else:
         suffix = '-normal'
     self.surf.fill(self.style['bg-color' + suffix])
     textpos = (self.offset[0], self.size[1] / 2.0 - self.textsurf.get_height() / 2)
     cursorWidth = self.style['font'].size(self.pwdtext[:self.currpos])[0]
     cursorx = cursorWidth + self.offset[0]
     self.textWidth = self.textsurf.get_width()
     if cursorWidth - self._textStartX < self.size[0] - self.offset[0] * 2:
         if cursorx - self._textStartX < 0:
             self._textStartX = max(0, cursorx - (self.size[0] - self.offset[0] * 2))
     else:
         self._textStartX = cursorWidth - (self.size[0] - self.offset[0] * 2)
     self.surf.blit(self.textsurf, textpos, Rect(self._textStartX, 0, self.size[0] - self.offset[0] * 2, self.textsurf.get_height()))
     if self.hasFocus:
         cursorx -= self._textStartX
         draw.line(self.surf, (255, 255, 255), (cursorx, self.offset[1]), (cursorx, self.size[1] - self.offset[1]))
     if self.style['appearence'] == APP_FLAT:
         draw.rect(self.surf, self.style['border-color' + suffix], Rect((0, 0), self.size), self.style['border-width'])
     else:
         bgcolor = self.style['bg-color' + suffix]
         color_dark = colorLuminosity(bgcolor, -50)
         color_light = colorLuminosity(bgcolor, +30)
         draw.line(self.surf, color_dark, (0, 0), (self.size[0] - 2, 0))
         draw.line(self.surf, color_dark, (0, 0), (0, self.size[1] - 2))
         draw.line(self.surf, color_light, (1, self.size[1] - 1), (self.size[0], self.size[1] - 1))
         draw.line(self.surf, color_light, (self.size[0] - 1, 1), (self.size[0] - 1, self.size[1] - 1))
예제 #39
0
 def drawMoveLine(self, fromPos, toPos):
     if fromPos is not None and toPos is not None:
         r0, c0 = fromPos
         r1, c1 = toPos
         sqr = Dims.SQUARE_SIZE
         draw.circle(self.win, BLUELINE, (c1 * sqr + sqr//2, r1 * sqr + sqr//2), sqr/10)
         draw.line(self.win, BLUELINE, (c0 * sqr + sqr//2, r0 * sqr + sqr//2), (c1 * sqr + sqr//2, r1 * sqr + sqr//2), 7)    
예제 #40
0
파일: CConsole.py 프로젝트: geijoenr/pyXPS
 def _blit_cursor(self):
     """
     Blits the cursor at proper position
     """
     self.cursorx -= self._textStartX
     strt = self.cursorx ,self.size[1]-self.textsurf.get_height()
     end  = self.cursorx , self.size[1] - self.offset[1]
     draw.line(self.surf, (255,255,255), strt, end)
예제 #41
0
def test_vert_line_width(test_surf):
   """Draw several vertical lines, varying in width."""
   x = 10
   for width in range(20):
       x += 5 + 2*width
       length = 10 * width
       draw.line(test_surf, (255, 255, 255, 255), (x, 2*width),
                 (x, 2*width + length), width)
예제 #42
0
def test_horz_line_width(test_surf):
   """Draw several horizontal lines, varying in width."""
   y = 10
   for width in range(20):
       y += 5 + 2*width
       length = 10 * width
       draw.line(test_surf, (255, 255, 255, 255), (y, y), (y + length, y),
                 width)
예제 #43
0
def draw_quad_node(screen, qnode):
    print("xmid: ", qnode.xmid)
    print("ymid: ", qnode.ymid)
    draw.line(screen, (0,0,0), (qnode.xmid, qnode.ymin), (qnode.xmid, qnode.ymax), 2)
    draw.line(screen, (0,0,0), (qnode.xmin, qnode.ymid), (qnode.xmax, qnode.ymid), 2)
    if qnode.children:
        for child in qnode.children:
            draw_quad_node(screen, child)
예제 #44
0
파일: gui.py 프로젝트: danielz360/Maya
    def refresh(self):           
        #Save this information coz it's frequently used
        self.offset = self.style['offset']
        
        if self.size[1] < self.style['font'].get_ascent() + self.offset[1]* 2:
            self.size = self.size[0], self.style['font'].get_ascent() + self.offset[1]* 2
                
        #Creates the surface with the rendered text
        self.textsurf = self.style['font'].render(self.text, self.style['antialias'], self.style['font-color'])
        
        #Creates a new widget surface if None or different size from widget size
        if not self.surf or self.surf.get_size() != self.size:
            self.surf = pygame.Surface(self.size, pygame.SRCALPHA)
        
        if self.hasFocus:
            suffix = "-focus"
        else:
            suffix = "-focus"
        
        #Background
        self.surf.fill(self.style['bg-color' + suffix])
                
        #Calculates the position of the text surface
        textpos =  self.offset[0], self.size[1] / 2. - self.textsurf.get_height() / 2
        
        #Width of the text until the cursor
        cursorWidth = self.style['font'].size(self.text[:self.currpos])[0]
        #X coordinate of the cursor 
        cursorx = cursorWidth + self.offset[0]
        #Total width of the text
        self.textWidth = self.textsurf.get_width()
        
        if cursorWidth - self._textStartX < self.size[0] - self.offset[0] * 2 :
            if cursorx - self._textStartX < 0:
                self._textStartX = max(0, cursorx - (self.size[0] - self.offset[0] * 2))
        else:
            self._textStartX = cursorWidth - (self.size[0] - self.offset[0] * 2)
            
        #Blits the text surface in the appropriate position
        self.surf.blit(self.textsurf, textpos, Rect(self._textStartX ,0, self.size[0] - self.offset[0] * 2, self.textsurf.get_height()))
        
        #Draws the cursor
        cursorx -= self._textStartX
        draw.line(self.surf, (255,255,255), (cursorx ,self.offset[1]),(cursorx , self.size[1] - self.offset[1]))

        #Renders the border
        if self.style['appearence'] == APP_FLAT:
            draw.rect(self.surf, self.style['border-color' + suffix], Rect((0,0), self.size), self.style['border-width'])
        else:
            bgcolor = self.style['bg-color' + suffix]
            color_dark = colorLuminosity(bgcolor,-50)
            color_light = colorLuminosity(bgcolor,+30)
            #color_corner = mixColors(color_dark, color_light)
            
            draw.line(self.surf,color_dark, (0,0), (self.size[0]-2,0)) #TOP
            draw.line(self.surf,color_dark, (0,0), (0,self.size[1]-2)) #LEFT
            draw.line(self.surf,color_light, (1,self.size[1]-1), (self.size[0],self.size[1]-1)) #LEFT
            draw.line(self.surf,color_light, (self.size[0]-1,1), (self.size[0]-1,self.size[1]-1)) #LEFT
예제 #45
0
def test_lines(test_surf):
   """Draw a collection of angled and overlapping lines."""

   start = [(10, 10), (20, 20), (30, 30), (10, 40), (20, 80),
            (20, 100), (200, 10), (200, 200)]
   end = [(10, 100), (20, 100), (30, 300), (40, 400), (50, 500)]
   for p1 in start:
       for p2 in end:
           draw.line(test_surf, (255, 255, 255, 255), p1, p2)
예제 #46
0
파일: inter.py 프로젝트: chqiwang/gobang
def draw_board(screen, gobang):
    clear_screen(screen)
    size = gobang.board_size + 1
    lines = size + 1
    for i in xrange(lines):
        draw.line(screen, linecolor, (edge_width, edge_width + i * grid_size),\
                 (edge_width + size * grid_size, edge_width + i * grid_size))
        draw.line(screen, linecolor, (edge_width + i * grid_size, edge_width),\
                 (edge_width + i * grid_size, edge_width + size * grid_size))
    draw_chess(screen, gobang)
예제 #47
0
파일: input.py 프로젝트: rashrag/LogSim
 def show(self):
     h = self.FONT.get_height()
     x,y = self._x,self._y
     r = pygame.Rect(x,y,0,h)
     for e,i in enumerate(self.OUTPUT+'\n'):
         if e == self.CURSORINDEX+1: break
         if i not in '\n\t':
             r = pygame.Rect(x,y,*self.FONT.size(i))
             x = r.right
         elif i == '\n':
             r = pygame.Rect(x,y,1,h)
             x = self._x
             y = r.bottom
         else:
             t = self.FONT.size(self.TAB*' ')[0]
             t = ((((x-self._x) / t) + 1) * t ) - (x-self._x)
             r = pygame.Rect(x,y,t,h)
             x = r.right
     
     rclamp = r.clamp(self)
     self._x += rclamp.x - r.x
     self._y += rclamp.y - r.y
     
     clip = self.SRC.get_clip()
     self.SRC.set_clip(self.clip(clip))
     try: self.SRC.fill(self.BG,self)
     except: self.SRC.blit(self.BG,self)
     x = self._x
     y = self._y
     select1,select2 = sorted((self.SELECTSTART,self.CURSORINDEX))
     self.C = []
     for e,i in enumerate(self.OUTPUT):
         if i not in '\n\t':
             self.C.append(pygame.Rect(x,y,*self.FONT.size(i)))
             if select1 <= e < select2:
                 scr.blit(self.FONT.render(i,1,self.HLCOLOR),(x,y))
             else:
                 scr.blit(self.FONT.render(i,1,self.FGCOLOR),(x,y))
             x = self.C[-1].right
         elif i == '\n':
             self.C.append(pygame.Rect(x,y,0,h))
             x=self._x
             y = self.C[-1].bottom
         else:
             t = self.FONT.size(self.TAB*' ')[0]
             t = ((((x-self._x) / t) + 1) * t ) - (x-self._x)
             self.C.append(pygame.Rect(x,y,t,h))
             x = self.C[-1].right
     self.C.append(pygame.Rect(x,y,0,h))
     if self.CURSOR:
         p = self.C[self.CURSORINDEX]
         draw.line(scr,self.CURSCOLOR,p.topleft,(p.left,p.bottom),1)
     pygame.display.update(self)
     self.SRC.set_clip(clip)
예제 #48
0
  def draw( self ):
    width, height = self.surface.get_size()
    
    # vertical lines
    vertical_line_spacing = width / self.grid_lines
    for i in range( self.grid_lines ): 
      draw.line( self.surface, self.color, ( i * vertical_line_spacing, 0 ), ( i * vertical_line_spacing, height ), 1 )

    # horizontal lines
    horizontal_line_spacing = int( height / self.grid_lines )
    for j in range( self.grid_lines ): 
      draw.line( self.surface, self.color, ( 0, j * horizontal_line_spacing ), ( width, j * horizontal_line_spacing ), 1 )
예제 #49
0
	def draw(self, surface):
		frame = self.get_margin_rect()
		fg = self.fg_color
		font = self.font
		text, i = self.get_text_and_insertion_point()
		image = font.render(text, True, fg)
		surface.blit(image, frame)
		if self.has_focus():
			x, h = font.size(text[:i])
			x += frame.left
			y = frame.top
			draw.line(surface, fg, (x, y), (x, y + h - 1))
예제 #50
0
파일: Class.py 프로젝트: annie60/Xilarius
 def show(self, screen):
     W, H = self.wc, self.hc
     sx , sy = self.sx, self.sy
     #Print background cells
     for cell in self.cases:
         screen.blit(cell.background.surf, cell.background.pos)
     #Generates lines of walls
     for y in range(self.h - 1):
         for x in range(self.w - 1):
             c = self.get_cell(x, y)
             
             if c.gate[const.right]:
                 draw.line(screen, const.gray, (sx + ((x + 1) * W), (sy + (y * H))), (sx + ((x + 1) * W), sy + ((y+1) * H)), 3)
             if c.gate[const.down]:
                 draw.line(screen, const.gray, ((sx + (x * W)), (sy + ((y+1) * H))), (sx + ((x + 1) * W), sy + ((y+1) * H)), 3)
                                  
     x = self.w - 1
     #Creates walls from buttom to top
     for y in range(self.h - 1):
         c = self.get_cell(x, y)
         
         if c.gate[const.down]:
             draw.line(screen, const.gray, ((sx + (x * W)), (sy + ((y+1) * H))), (sx + ((x + 1) * W), sy + ((y+1) * H)), 3)
             
     y = self.h - 1
     #Creates walls from left to right
     for x in range(self.w - 1):
         c = self.get_cell(x, y)
         
         if c.gate[const.right]:
             draw.line(screen, const.gray, (sx + ((x + 1) * W), (sy + (y * H))), (sx + ((x + 1) * W), sy + ((y+1) * H)), 3)
             
     #Draws outline
     draw.rect(screen, const.gray, (sx, sy, W * self.w, H * self.h), 3)
예제 #51
0
파일: dialog.py 프로젝트: bpa/renegade
def draw_round_border(surface, width=4, color=None, bounds=None):
    """draw_round_border(Surface, line_width, Color, Rect) => None
       only Surface is required"""
    h = surface.get_height()
    w = surface.get_width()
    img = dialog.circle_border_image
    if color == None: color = pygame.color.Color("white")
    if bounds == None: bounds = surface.get_rect()

    r = Rect(0,0,8,8)
    border = bounds.inflate(-8,-8)
    border.topleft = bounds.topleft

    surface.blit(img, border.topleft, r)
    r.top = 8
    surface.blit(img, border.bottomleft, r)
    r.left = 8
    surface.blit(img, border.bottomright, r)
    r.top = 0
    surface.blit(img, border.topright, r)
    
    i = bounds.inflate(-17,-17)
    o = bounds.inflate(-3,-3)
    o.topleft = bounds.topleft
    draw.line(surface, color, (i.left,o.top),(i.right,o.top),       4 )
    draw.line(surface, color, (o.left,i.top),(o.left,i.bottom),     4 )
    draw.line(surface, color, (i.left,o.bottom),(i.right,o.bottom), 4 )
    draw.line(surface, color, (o.right,i.top),(o.right,i.bottom),   4 )
예제 #52
0
파일: Classe.py 프로젝트: tbourg/perso
    def show(self, screen):
        W, H = self.wc, self.hc
        sx , sy = self.sx, self.sy
        
        for y in range(self.h - 1):
            for x in range(self.w - 1):
                c = self.get_cell(x, y)
                
                if c.gate[const.right]:
                    draw.line(screen, const.black, (sx + ((x + 1) * W), (sy + (y * H))), (sx + ((x + 1) * W), sy + ((y+1) * H)), 2)
                if c.gate[const.down]:
                    draw.line(screen, const.black, ((sx + (x * W)), (sy + ((y+1) * H))), (sx + ((x + 1) * W), sy + ((y+1) * H)), 2)
                                     
        x = self.w - 1
        
        for y in range(self.h - 1):
            c = self.get_cell(x, y)
            
            if c.gate[const.down]:
                draw.line(screen, const.black, ((sx + (x * W)), (sy + ((y+1) * H))), (sx + ((x + 1) * W), sy + ((y+1) * H)), 2)
                
        y = self.h - 1
        
        for x in range(self.w - 1):
            c = self.get_cell(x, y)
            
            if c.gate[const.right]:
                draw.line(screen, const.black, (sx + ((x + 1) * W), (sy + (y * H))), (sx + ((x + 1) * W), sy + ((y+1) * H)), 2)
                
                

        draw.rect(screen, const.black, (sx, sy, W * self.w, H * self.h), 2)
예제 #53
0
 def redraw(self):
     """Basic screens do not have scrolling capabilities
     you'd need to use a subclass for that"""
     if time.time() < self._next_redraw:
         return
     
     surf = self.engine.display
     
     surf.fill(self.background_colour)
     
     # Draw divider lines
     draw.line(surf, (0,0,0), (200, 0), (200, 600), 5)
     draw.line(surf, (0,0,0), (400, 0), (400, 600), 5)
     
     draw.line(surf, (0,0,0), (0, 200), (600, 200), 5)
     draw.line(surf, (0,0,0), (0, 400), (600, 400), 5)
     
     
     # Draw game state
     for i in range(9):
         x = i % 3
         y = math.floor(i/3)
         
         self.draw_place(surf, x, y, self.state[i])
     
     self.draw_transition()
     
     pygame.display.flip()
     
     self._next_redraw = time.time() + self._redraw_delay
예제 #54
0
    def run(self):
        radius = 70
        (xoff, yoff) = (self.dim[0] / 2, self.dim[1] / 2)
        (xscale, yscale) = (1, 0.5)
        while True:
            if self.iter > 2 * math.pi:
                self.iter = 0
            self.iter += 0.01

            (x1, y1) = (math.cos(self.iter) * xscale, math.sin(self.iter) * yscale)
            (x2, y2) = (math.cos(self.iter + math.pi / 2) * xscale, math.sin(self.iter + math.pi / 2) * yscale)
            (x3, y3) = (int(-x1 * radius + xoff), int(-y1 * radius + yoff))
            (x4, y4) = (int(-x2 * radius + xoff), int(-y2 * radius + yoff))
            (x1, y1) = (int(x1 * radius + xoff), int(y1 * radius + yoff))
            (x2, y2) = (int(x2 * radius + xoff), int(y2 * radius + yoff))

            # self.lock.acquire()
            self.surface.fill(black)

            draw.lines(self.surface, green, True, [(x1, y1), (x2, y2), (x3, y3), (x4, y4)], 3)
            draw.lines(self.surface, green, True, [(x1, y1 - radius), (x2, y2 - radius), (x3, y3 - radius), (x4, y4 - radius)], 3)
            draw.line(self.surface, green, (x1, y1), (x1, y1 - radius), 3)
            draw.line(self.surface, green, (x2, y2), (x2, y2 - radius), 3)
            draw.line(self.surface, green, (x3, y3), (x3, y3 - radius), 3)
            draw.line(self.surface, green, (x4, y4), (x4, y4 - radius), 3)

            vdot = rotate_vector((0, 0.6), self.iter)
            draw.circle(self.surface, green, (int(vdot[0] * radius * xscale + xoff), int(vdot[1] * radius * yscale + yoff - radius)), 5)

            # self.clock.lock.acquire()
            self.surface.blit(self.clock.surface, (self.dim[0] - self.clock.get_dimensions()[0] - 10, 0))
            # self.clock.lock.release()

            # self.lock.release()
            time.sleep(0.005)
예제 #55
0
def img_border(screen, img_width, img_height, wpos, downpos):
    "draw a border around the image"
    ll = line(screen, gl.IMG_BORDER_COLOR, (wpos, downpos), (wpos, img_height + downpos + 2)) # left side of border
    rl = line(screen, gl.IMG_BORDER_COLOR, (wpos + img_width, downpos), (wpos + img_width, img_height + downpos + 2)) # right side
    tl = line(screen, gl.IMG_BORDER_COLOR, (wpos, downpos), ((wpos + img_width), downpos)) # top of border
    bl = line(screen, gl.IMG_BORDER_COLOR, (wpos, img_height + downpos + 2), ((wpos + img_width), img_height + downpos + 2)) # bottom
    update(ll)
    update(tl)
    update(rl)
    update(bl)
    # save the current border positions to be able to draw over them later:
    gl.LRECT = ll
    gl.RRECT = rl
    gl.TRECT = tl
    gl.BRECT = bl
예제 #56
0
	def forward(self, distance, color, width):
		#print "Turtle.forward:", distance, color ###
		a = self.heading * deg
		p0 = self.position
		x0, y0 = p0
		dx = distance * cos(a)
		dy = distance * sin(a)
		x1 = x0 + dx
		y1 = y0 + dy
		p1 = vector(x1, y1)
		#print "...", p0, p1 ###
		if self.enable_drawing:
			draw.line(self.surface, color, p0, p1, width)
		self.position = p1
		self.path.append(p1)
예제 #57
0
 def draw(self, surface):
     frame = self.get_margin_rect()
     fg = self.fg_color
     font = self.font
     focused = self.has_focus()
     text, i = self.get_text_and_insertion_point()
     if focused and i is None:
         surface.fill(self.sel_color, frame)
     image = font.render(text, True, fg)
     surface.blit(image, frame)
     if focused and i is not None:
         x, h = font.size(text[:i]) #[0], font.get_linesize()
         x += frame.left
         y = frame.top
         draw.line(surface, fg, (x, y), (x, y + h - 1))
예제 #58
0
 def draw_place(self, surf, x, y, value):
     if value == 1:# X
         x1 = 25 + x * 200
         x2 = 175 + x * 200
         
         y1 = 25 + y * 200
         y2 = 175 + y * 200
         
         draw.line(surf, (0,0,0), (x1, y1), (x2, y2), 5)
         draw.line(surf, (0,0,0), (x2, y1), (x1, y2), 5)
         
     elif value == 0:# O
         x = int(x)
         y = int(y)
         draw.circle(surf, (0,0,0), (100 + x * 200, 100 + y * 200), 75)
         draw.circle(surf, self.background_colour, (100 + x * 200, 100 + y * 200), 70)
예제 #59
-1
    def drawUpdatedMinimap(self, world, player, rays, coords):
        scale = self.minimap_scale
        player_coords = ((player.coords+1) * scale).rounded().toInt().toTuple()
        player_direction = player.direction * scale
        player_direction = (player_direction + player_coords).rounded().toInt().toTuple()
        minimap = self.minimap_surface.copy()
        draw.circle(
            minimap,
            player.map_color,
            player_coords,
            round(player.size*scale)
        )
        for ray in rays:
            draw.line(
                minimap,
                (0,255,0),
                player_coords,
                ((ray['coords'][0]+1)*scale, (ray['coords'][1]+1)*scale)
        )
        draw.line(
            minimap,
            player.map_color,
            player_coords,
            player_direction
        )

        self.screen.blit(minimap, coords)
예제 #60
-1
파일: gc2d.py 프로젝트: whiord/untangle3d
    def _draw(self):
        intersected = set()
        objs = self.objects
        for e1 in self.edges:
            for e2 in self.edges:
                if e1 != e2 and e1 not in intersected:
                    s1 = gd2.Segment(objs[e1[0]], objs[e1[1]])
                    s2 = gd2.Segment(objs[e2[0]], objs[e2[1]])
                    if gd2.intersect_seg(s1, s2, self.config.accuracy):
                        intersected.add(e1)
                        intersected.add(e2)

        for edge in self.edges:
            p1 = self.objects[edge[0]]
            p2 = self.objects[edge[1]]

            color = self.config.line.color
            if edge in intersected:
                color = self.config.line.bad_color
            if self.grub_id is not None:
                if edge[0] == self.grub_id or edge[1] == self.grub_id:
                    color = self.config.line.active_color

            pd.line(self.display, color, (p1.x, p1.y), (p2.x, p2.y), self.config.line.width)
            #pd.aaline(self.display, color, (p1.x, p1.y), (p2.x, p2.y), True)

        for id, point in self.objects.items():
            color = self.config.circle.color
            if id == self.grub_id:
                color = self.config.circle.active_color
            pd.circle(self.display, color, (int(round(point.x)), int(round(point.y))), int(round(point.radius)))
            #pgfx.aacircle(self.display, int(round(point.x)), int(round(point.y)), int(round(point.radius)), color)

        self._render_info("tangled: {}/{}".format(len(intersected), len(self.edges)))