Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- from numpy import pi, sin
- import pygame
- import copy
- # colors
- BLACK = (0, 0, 0)
- WHITE = (255, 255, 255)
- # size
- SIZE_ARR_POINTS = 11
- SIZE_CELL = 60
- DOT_RADIUS = 2
- pygame.init()
- canvas = pygame.display.set_mode((1900, 1000))
- speeds = np.linspace(1/SIZE_ARR_POINTS, 1, SIZE_ARR_POINTS)
- init_points = [[0 for i in range(SIZE_ARR_POINTS)] for j in range(SIZE_ARR_POINTS)]
- prev_points = copy.deepcopy(init_points)
- pygame.display.set_caption("trygonometry test")
- exit = False
- i = 0
- def get_step(speed, orientation):
- return sin((i*speed-pi/2 if orientation else i*speed))*SIZE_CELL/2-DOT_RADIUS + DOT_RADIUS
- def draw_speed(surface, position, orientation, speed):
- field = pygame.Surface([SIZE_CELL, 20] if orientation else[20, SIZE_CELL])
- step = get_step(speed, orientation)
- pygame.draw.circle(field, WHITE, [SIZE_CELL/2+step, 10] if orientation else [10, SIZE_CELL/2+step], DOT_RADIUS)
- surface.blit(field, position)
- def draw_step(surface, pos, place):
- point = pos[0] + get_step(speeds[place[0]], True), pos[1] + get_step(speeds[place[1]], False)
- prev_point = prev_points[place[1]][place[0]]
- pygame.draw.line(surface, WHITE, [point[0], point[1]] if prev_point == 0 else [prev_point[0], prev_point[1]], [point[0], point[1]])
- prev_points[place[1]][place[0]] = point
- def restart():
- i = 0
- prev_points = copy.deepcopy(init_points)
- canvas.fill(BLACK)
- while not exit:
- for event in pygame.event.get():
- if event.type == pygame.QUIT:
- exit = True
- if event.type == pygame.KEYDOWN:
- if event.key == pygame.K_r:
- restart()
- for j, speed in enumerate(speeds):
- draw_speed(canvas, [135 + j*(SIZE_CELL+10), 100], True, speed)
- draw_speed(canvas, [100, 135 + j*(SIZE_CELL+10)], False, speed)
- for j in range(SIZE_ARR_POINTS):
- for k in range(SIZE_ARR_POINTS):
- draw_step(canvas, [165 + k*(SIZE_CELL+10), 165 + j*(SIZE_CELL+10)], [k, j])
- i += pi/180
- pygame.display.update()
Advertisement
Add Comment
Please, Sign In to add comment