コード例 #1
0
def bfs(draw, grid, start, end):
    q = Queue()
    q.put((0, start, "#"))
    check = {}
    came_from = {}
    while not q.empty():
        vals = q.get()
        cur = vals[1]
        prev = vals[2]
        dist = vals[0]
        if check.get(cur, False):
            continue

        check[cur] = True
        if cur != start:
            came_from[cur] = prev

        if cur == end:
            reconstruct_path(came_from, end, draw)
            start.make_start()
            end.make_end()
            return True

        for neighbor in cur.neighbors:
            if check.get(neighbor, False):
                continue
            q.put((dist + 1, neighbor, cur))
            neighbor.make_close()

        draw()
コード例 #2
0
ファイル: pyfxr_gui.py プロジェクト: lordmauve/pyfxr
def main():
    global screen, font
    pygame.mixer.pre_init(44100, channels=1)
    pygame.init()
    pygame.display.set_caption("pyfxr")
    screen = pygame.display.set_mode((800, 600))
    font = pygame.font.SysFont('sans-serif', 24, bold=False)

    while True:
        draw()
        pygame.display.flip()

        ev = pygame.event.wait()
        if ev.type == pygame.QUIT:
            return
        elif ev.type == pygame.MOUSEBUTTONDOWN:
            if ev.button == pygame.BUTTON_LEFT:
                clicked = widget_at(ev.pos)
                if clicked:
                    clicked.on_click(ev.pos)
        elif ev.type == pygame.MOUSEMOTION:
            if pygame.BUTTON_LEFT in ev.buttons:
                if clicked:
                    clicked.on_drag(ev.pos)
        elif ev.type == pygame.MOUSEBUTTONUP:
            if ev.button == pygame.BUTTON_LEFT:
                if clicked:
                    clicked.on_release(ev.pos)
                    clicked = None
        elif ev.type == pygame.KEYDOWN:
            if ev.key == pygame.K_F1:
                tones_tab()
            elif ev.key == pygame.K_F2:
                fxr_tab()
コード例 #3
0
 def draw(self):
     for a in self.model.spacejunks:
         pygame.draw.rect(self.screen, pygame.Color(a.color[0], a.color[1], a.color[2]), pygame.Rect(a.x, a.y, a.width, a.height))
     for b in self.model.spacejunkm:
         pygame.draw.rect(self.screen, pygame.Color(b.color[0], b.color[1], b.color[2]), pygame.Rect(b.x, b.y, b.width, b.height))
     pygame.draw(self.screen, (self.model.sandra.width, self.model.sandra.height), pygame.Surface(self.model.sandra.x, self.model.sandra.y))
     pygame.display.update()
コード例 #4
0
def mouse_clique(x, y):
    global state
    if state == State.PLAY_STONE:
        s = get_square(x, y)
        if s != False and add_stone(s):
            state = State.MOVE
            draw()
コード例 #5
0
def draw_grid(surface, grid):
    sx=top_left_x
    sy=top_left_y

    for i in range(len(grid)):
        pygame.draw(surface,(128,128,128),(sx,sy+i*block_size), (sx+play_width,sy+i*block_size))
        for j in range(len(grid[i])):
            pygame.draw(surface,(128,128,128),(sx+j*block_size,sy), (sx+j*block_size,sy+play_height))
コード例 #6
0
ファイル: task_1.py プロジェクト: st2257st2257/mipt_inf
def all_move():
    """Сразу передвигаем все шарики"""
    for i in range(len(balls)):
        balls[i].move(h_max=screen_h_max - 50,
                      h_min=screen_h_min + 50,
                      w_max=screen_w_max - 50,
                      w_min=screen_w_min + 50)
        draw(screen, balls[i])
コード例 #7
0
ファイル: PlayerClass.py プロジェクト: lalaithion/nBodySim
	def draw(self, screen, offset, zoom):
		i = 1
		for point in self.path:
			i += 1
			pygame.draw.circle(screen, self.color, ((int((point[0]+offset[0]) * zoom),int((point[1]+offset[1])* zoom))), 0, 0)
		pygame.draw(screen, (11,223,0,0), ((int((self.position[0]+offset[0]) * zoom),int((self.position[1]+offset[1])* zoom))), 10, 0)
		pygame.draw(screen, (150,150,150,0), ((int((self.position[0]+offset[0]) * zoom),int((self.position[1]+offset[1])* zoom))), 15, 10)
		self.path.append((self.position[0],self.position[1]))
		self.path = self.path[-5000:] #This deletes any points older than 500
コード例 #8
0
def draw_tank(x, y, width, height, direction, **kwargs):
    print(kwargs)
    tank_c = (x + int(width / 2), y + int(width / 2))
    pygame.draw.rect(screen, (255, 0, 0), (x, y, width, width), 2)
    pygame.draw.circle(screen, (255, 0, 0), tank_c, int(width / 2))
    for x in state["gamefild"]['tanks']:
        color = (255, 255, 255)
        if x[id] == id:
            color = (0, 0, 0)
        pygame.draw()
コード例 #9
0
def main(win, width):
    ROWS = 50
    grid = make_grid(ROWS, width)

    start = None
    end = None

    run = True
    started = False

    while run:
        draw(win, grid, ROWS, width)
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                run = False

            if started:
                continue

            if pygame.mouse.get_pressed()[0]:
                pos = pygame.mouse.get_pos()
                row, col = get_clicked_pos(pos, ROWS, width)
                spot = grid[row][col]
                if not start and spot != end:
                    start = spot
                    start.make_start()

                elif not end and spot != start:
                    end = spot
                    end.make_end()

                elif spot != end and spot != start:
                    spot.make_barrier()

            elif pygame.mouse.get_pressed()[2]:
                pass

            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_SPACE and start and end:
                    for row in grid:
                        for spot in row:
                            spot.update_neighbors(grid)
                    algorithm(lambda: draw(win, grid, ROWS, width), grid,
                              start, end)

                if event.key == pygame.K_c:  # 키보드 c
                    start = None
                    end = None
                    grid = make_grid(ROWS, width)

    pygame.quit()
コード例 #10
0
def main(Win, width):
    ROWS = 50
    grid = makeGrid(ROWS, width)

    start = None
    end = None

    run = True
    started = False
    Win.fill((255, 0, 0))
    while run:

        draw(Win, grid, ROWS, width)
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                run = False

        if started:
            continue

        if pygame.mouse.get_pressed()[0]:
            print("clicked")
            position = pygame.mouse.get_pos()
            row, col = getClickedPosition(position, ROWS, width)
            print(row, col)
            node = grid[row][col]
            if not start and node != end:
                start = node
                start.makeStart()
            elif not end:
                end = node
                end.makeEnd()

            elif node != end and node != start:
                node.makeBarrier()

        elif pygame.mouse.get_pressed()[2]:
            position = pygame.mouse.get_pos()
            row, col = getClickedPosition(position, ROWS, width)
            node = grid[row][col]
            node.reset()
            if node == start:
                start = None
            elif node == end:
                end = None
        #pygame.display.update()
    pygame.quit()
コード例 #11
0
 def __init__(self):
     # makes player by calling parent class
     super().__init__()
     
     self.image = pygame.draw([20, 20])
     self.image.fill = (GREEN)
     
     self.rect = self.image.get_rect:() 
コード例 #12
0
def a_star(draw, grid, start, end):
    count = 0
    open_set = PriorityQueue()
    open_set.put((0, count, start))
    came_from = {}
    g_score = {spot: float("inf") for row in grid for spot in row}
    g_score[start] = 0
    f_score = {spot: float("inf") for row in grid for spot in row}
    f_score[start] = h(start.get_pos(), end.get_pos())
    open_set_hash = {start}

    while not open_set.empty():
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()

        current = open_set.get()[2]
        open_set_hash.remove(current)

        if current == end:
            reconstruct_path(came_from, end, draw)
            start.make_start()
            end.make_end()
            return True  #make_path

        for neighbor in current.neighbors:
            temp_g_score = g_score[current] + 1

            if temp_g_score < g_score[neighbor]:
                came_from[neighbor] = current
                g_score[neighbor] = temp_g_score
                f_score[neighbor] = temp_g_score + h(neighbor.get_pos(),
                                                     end.get_pos())
                if neighbor not in open_set_hash:
                    open_set.put((f_score[neighbor], count, neighbor))
                    open_set_hash.add(neighbor)
                    neighbor.make_open()

        draw()

        if current != start:
            current.make_close()
コード例 #13
0
def algorithm(draw, grid, start, end):
    count = 0
    open_set = PriorityQueue()
    open_set.put((0, count, start))
    came_from = {}
    g_score = {spot: float("inf") for row in grid for spot in row}
    g_score[start] = 0
    f_score = {spot: float("inf") for row in grid for spot in row}
    f_score[start] = h(start.get_pos(), end.get_pos())
    open_set_hash = {start}

    while not open_set.empty():
        current = open_set.get()[2]
        open_set_hash.remove(current)

        if current == end:
            shortest_path(came_from, end, draw)
            end.make_end()
            return True

        for neighbor in current.neighbors:
            temp_g_score = g_score[current] + 1

            if temp_g_score < g_score[neighbor]:
                came_from[neighbor] = current
                g_score[neighbor] = temp_g_score
                f_score[neighbor] = temp_g_score + h(neighbor.get_pos(),
                                                     end.get_pos())
                if neighbor not in open_set_hash:
                    count += 1
                    open_set.put((f_score[neighbor], count, neighbor))
                    open_set_hash.add(neighbor)
                    neighbor.make_open()

        draw()

        if current != start:
            current.make_closed()

    return False
コード例 #14
0
def dfs(draw, grid, start, end):
    stack = deque([])
    stack.append((0, start, "#"))
    check = {}
    came_from = {}
    while len(stack) > 0:
        vals = stack[-1]
        cur = vals[1]
        prev = vals[2]
        dist = vals[0]

        check[cur] = True
        if cur != start:
            came_from[cur] = prev

        if cur == end:
            reconstruct_path(came_from, end, draw)
            start.make_start()
            end.make_end()
            return True

        pushed = False
        for neighbor in cur.neighbors:
            if check.get(neighbor, False):
                continue
            stack.append((dist + 1, neighbor, cur))
            neighbor.make_close()
            pushed = True
            break

        if pushed == False:
            stack.pop()

        draw()

    return False
コード例 #15
0
    balls[i] = new_ball()

pygame.display.update()
clock = pygame.time.Clock()
finished = False

while not finished:
    clock.tick(FPS)
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            finished = True
            print("Всего очков:", score)
        elif event.type == pygame.MOUSEBUTTONDOWN:
            for i, ball in enumerate(balls):
                x1, y1 = event.pos
                x = ball[X]
                y = ball[Y]
                r = ball[R]
                if (x - x1)**2 + (y - y1)**2 <= r**2:
                    balls[i] = new_ball()
                    score += 100 - r
                    text(str(score))

    for ball in balls:
        ball = move_ball(ball)
        draw(ball)

    pygame.display.update()
    screen.fill(BLACK)

pygame.quit()
コード例 #16
0
    def draw(self):

        for p in self.projectilelist:
            p.draw()
コード例 #17
0
def spike(x, y):
    for i in range (20):
        a = random.randint(0, 60)
        b = random.randint(-10, 20)
        polygon(screen, (0, 0, 0), [[x+a, y+b], [x+a+3, y+b-60], [x+a+6, y+b]], 0)
        polygon(screen, (255, 255, 255), [[x+a, y+b], [x+a+3, y+b-60], [x+a+6, y+b]], 1)

def sonic(x, y):
    body(x, y)
    mushroom(x, y, 1, 0.5)
    mushroom(x+70, y-20, -1, 0.7)
    spike(x, y)

pygame.init()
FPS = 30
screen = pygame.display.set_mode((400, 400))

draw() # - function for drawing

pygame.display.update()
clock = pygame.time.Clock()
finished = False

while not finished:
    clock.tick(FPS)
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            finished = True

pygame.quit()
コード例 #18
0
def things(thingx, thingy, thingw, thingh, color):
    pygame.draw(gameDisplay, color, [thingx, thingy, thingw, thingh])
コード例 #19
0
def update_highscores(score):  #запись результатов игры
    time = datetime.datetime.now()
    temp = str(time.day) + "." + str(time.month) + "." + str(
        time.year) + " " + str(time.hour) + ":" + str(time.minute) + ":" + str(
            time.second) + " score :" + str(score) + "\n"
    hsfile.write(temp)


pygame.display.update()
clock = pygame.time.Clock()
finished = False

init_balls()
init_rects()
#основоной цикл
while not finished:
    clock.tick(FPS)
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            update_highscores(score)
            finished = True
        elif event.type == pygame.MOUSEBUTTONDOWN:
            score = update_score(event, score)
            points = update_points(event, points)
    update_balls()
    update_rects()
    draw(score, points)

pygame.quit()
コード例 #20
0
            polygon(DISPLAYSURF, RED,
                    ((x, y + (SIZE / 5)), (x, y + SIZE),
                     (x + SIZE / 2, y + (SIZE / 5 * 6)), (x + SIZE, y + SIZE),
                     (x + SIZE, y + SIZE / 5), (x + SIZE / 2, y),
                     (x, y + SIZE / 5)), 2)
    for s in position_now.stones:
        pos = calculate_position(s[0], s[1], True)
        DISPLAYSURF.blit(stoneImg, pos)
    perso_x_pix, perso_y_pix = calculate_position(position_now.x_perso,
                                                  position_now.y_perso, True)

    DISPLAYSURF.blit(perso, (perso_x_pix, perso_y_pix))
    pygame.display.flip()


draw()


def move():
    global state, position_now
    if state == State.MOVE:
        if is_border(position_now.x_perso, position_now.y_perso):
            state = State.GAME_OVER
        else:
            pos = get_direction(position_now)
            if pos == False:
                state = State.GAME_OVER
            else:
                position_now.setPerson(pos[0], pos[1])
                # print("Person is moved on ", pos)
                #draw()
コード例 #21
0
    text = f.render(s, 0, (0, 30, 100))
    screen.blit(text, (x + m*40, y + m*80))
    



while not finished:
    polygon(screen, (100, 100, 200), [(0, 0), (0,160), (1200, 160), (1200, 0)])
    polygon(screen, (100, 120, 100), [(0, 400), (0,160), (1200, 160), (1200, 400)])

    d = 0

    dt = pygame.time.get_ticks() % 2000 / 2000

    for i in range(len(u)):
        draw(dt, u[i][0], d, 100, 0.35*u[i][1])
        d += u[i][1]*100 + 15
    
    d += 50
    draw(dt, "боманка", d, 100 + pygame.time.get_ticks()/130, 0.4)
    polygon(screen, (100, 120, 100), [(d, 400), (d, 220), (1200, 220), (1200, 400)])

    pygame.display.update()
    clock.tick(FPS)

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            finished = True

pygame.quit()
コード例 #22
0
def shortest_path(came_from, current, draw):
    while current in came_from:
        current = came_from[current]
        current.make_path()
        draw()
コード例 #23
0
import pygame

pygame.init()

screen = pygame.display.set_mode([500 , 500])

running = True 
while running :
	for event in pygame.event.get():
		if event.type == pygame.QUIT :
			running = False 
			
	screen.fill((0,0,0))
	
	pygame.draw(screen ,(255 , 250 , 255) , (250,250))
	
	
	pygame.display.flip()
	
pygame.quit()
	
コード例 #24
0
    circle(screen,
           (250, 200 - 50 * math.sin(t * 6.28), 200 - 50 * math.sin(t * 6.28)),
           (130, 140), 40)
    circle(screen,
           (250, 200 - 50 * math.cos(t * 6.28), 200 - 50 * math.cos(t * 6.28)),
           (270, 140), 40)
    circle(screen, (0, 0, 0), (130, 140), 20)
    circle(screen, (0, 0, 0), (270, 140), 20)

    polygon(screen, (50, 50, 50), [(70, 80), (170, 100), (170, 80), (70, 60)])
    polygon(screen, (50, 50, 50), [(330, 80), (230, 100), (230, 80),
                                   (330, 60)])

    polygon(screen, (170, 80, 100), [(300, 280), (200, 250), (200, 230),
                                     (300, 260)])
    polygon(screen, (170, 80, 100), [(100, 280), (200, 250), (200, 230),
                                     (100, 260)])

    pygame.display.update()


while not finished:
    draw(pygame.time.get_ticks() % 2000 / 2000)
    clock.tick(FPS)
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            finished = True

pygame.quit()
コード例 #25
0
p.init()

s = p.display.set_mode((900, 700))
done = False
# x=Rect(10,10,100,100)
rectab = [[0 for _ in range(28)] for _ in range(28)]
while not done:
    for event in p.event.get():
        if event.type == p.QUIT:
            done = True

    for x_n in range(28):
        for y_n in range(28):
            color = (255, 255, 255) if rectab[x_n][y_n] == 0 else (0, 0, 0)
            dx = x_n * 25
            dy = y_n * 25
            p.draw.rect(s, color, p.Rect(dx + 1, dy + 1, 23, 23))
    p.draw.rect(s, (150, 150, 150), p.Rect(760, 350, 100, 50))
    if p.mouse.get_pressed()[0]:
        # reset
        x, y = p.mouse.get_pos()
        if 760 < x < 860 and 350 < y < 400:
            rectab = [[0 for _ in range(28)] for _ in range(28)]
        if 0 < x < 700:
            x_n = x // 25
            y_n = y // 25
            rectab[x_n][y_n] = 1
    p.draw(f.render(15))

    p.display.flip()
コード例 #26
0
ファイル: projectile.py プロジェクト: xhalo32/advpy
	def draw( self ):

		for p in self.projectilelist:
			p.draw(  )
コード例 #27
0
    y = y0 + int(320/620*height)
    girl1(x0 + int(550/1500*width), y0 + int(320/620*height), width, height)
    x = x0 + int(850/1500*width)
    y = y0 + int(320/620*height)
    girl2(x0 + int(850/1500*width), y0 + int(320/620*height), width, height)
    icecreamgirl(x0, y0, width, height)
    heart(x0, y0, width, height)
    icecreamboy(x0, y0, width, height)


n = int(input('Введите количество рисунков '))
for i in range (n):
    x0 = int(input('Координата х  '))
    y0 = int(input('Координата y  '))
    width = int(input('Введите ширину изображения  '))
    height = int(input('Введите высоту изображения  '))
    draw(x0, y0, width, height)



pygame.display.update()
clock = pygame.time.Clock()
finished = False

while not finished:
    clock.tick(FPS)
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            finished = True

pygame.quit()
コード例 #28
0
    125,
), (485, 690), 3, 1)
# иголки прямо
j = 1


def draw(x, y):

    polygon(screen, (36, 28, 28), [(360 + x, 680), (370 + x, 680),
                                   (365 + x, 642)])
    polygon(screen, (8, 6, 6), [(360 + x, 680), (370 + x, 680),
                                (365 + x, 642)], 1)


while j <= 11:
    draw(-15 + (10 * j), 15)
    j += 1

# гриб
ellipse(screen, (225, 225, 225), (395, 622, 10, 40))
ellipse(screen, (154, 143, 143), (395, 622, 10, 40), 1)
ellipse(screen, (225, 0, 0), (380, 620, 40, 15))
ellipse(screen, (154, 143, 143), (380, 620, 40, 15), 1)
ellipse(screen, (225, 225, 225), (389, 622, 4, 2))
ellipse(screen, (154, 143, 143), (389, 621, 4, 2), 1)
ellipse(screen, (225, 225, 225), (400, 625, 6, 3))
ellipse(screen, (154, 143, 143), (400, 625, 6, 3), 1)
ellipse(screen, (225, 225, 225), (392, 628, 6, 4))
ellipse(screen, (154, 143, 143), (392, 628, 6, 4), 1)
ellipse(screen, (225, 225, 225), (410, 622, 3, 4))
ellipse(screen, (154, 143, 143), (410, 622, 3, 4), 1)
コード例 #29
0
ファイル: architecture.py プロジェクト: uni-crot/GroupB
    top(screen, width, length)
    front(screen, width, column_x)
    side(screen, length, column_y)




# рисует проекцию дома первый раз
number_l = 1
number_w = 1
column_x = 0
column_y = 0
length = number_l * match  # длина домика
width = number_w + match  # ширина домика
rect(screen, (255, 255, 255), (0, 0, w, h))
draw(screen, width, length, column_x, column_y)
pygame.display.update()

# основное тело программы
while not finished:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            finished = True
        elif event.type == pygame.KEYDOWN:
            if event.key == pygame.K_BACKSPACE:
                user_input = user_input[:-1]
            elif event.key == pygame.K_TAB:
                if count == 1:             number_w = int(user_input)
                    user_input = ''
                elif count == 2:
                    number_l = int(user_input)
コード例 #30
0
 def dibujarFicha(self):
     pygame.draw(self.window, self.color, (self.x, self.y), 20)
コード例 #31
0
    for j in range(3):
        roofcolor[i][j] = randint(0, 255)
        housecolor[i][j] = randint(0, 255)

pygame.display.update()
clock = pygame.time.Clock()
finished = False

while not finished:
    polygon(screen, (20, 193, 224), [(0, 0), (2000, 0), (2000, 1000),
                                     (0, 1000)])
    polygon(screen, (48, 140, 9), [(0, 500), (2000, 500), (2000, 1000),
                                   (0, 1000)])
    circle(screen, (255, 255, 0), (110, 120), 100)
    cloud(x + 300, y)
    cloud(x + 600, y + 100)
    cloud(x + 900, y - 40)
    x = x + 1
    for i in range(0, 6, 1):
        draw(k1[i], x0, housecolor[i], windowtype[i], rooftype[i],
             roofcolor[i])
        x0 = x0 + 70 * k1[i]
    x0 = 20

    pygame.display.update()
    clock.tick(FPS)
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            finished = True

pygame.quit()
コード例 #32
0
ファイル: Game.py プロジェクト: DavinParish/SnakeGame
            if event.key == pygame.K_n:
                game.wait = False
                SNAKES = [snake, robot]

            if event.key == pygame.K_x:
                snake.dead = True

            if event.key == pygame.K_o:
                # save the highest score out of all the players
                if snake.score < snake_2.score:
                    save(snake_2)
                if snake.score > snake_2.score:
                    save(snake)

            if event.key == pygame.K_SPACE:
                snake.size += 20


    # Mover the snakes and the robot
    if not game.paused and not game.wait and not any([s.dead for s in SNAKES]):
        for s in SNAKES:
            update_snake(s)
    move()

    game_timer = pygame.time
    game_timer.wait(1)
    update_board()

    # Render
    draw()
コード例 #33
0
ファイル: solar.py プロジェクト: IpatenkovaV/cat-dog
Scale = getScale(planets)

while not finished:
	clock.tick(FPS)
	for event in pygame.event.get():
		if event.type == pygame.QUIT:
			finished = True

	i = 0
	while (i < len(planets)):
		p = planets[i]
		if i > 0:
			p.move(DT)
			R = p.getPos()

		for p2 in planets:
			if p != p2:
				gravitate(p, p2, DT)
		draw(p, Scale)

		if i>0 and (R < CRASH_DIST):
			planets.pop(i)
		else:
			i+=1
	pygame.display.update()
	screen.fill(BLACK)
	
	if R < CRASH_DIST:
		finished = True
		print("Crashed")