Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from numpy import pi, sin, cos
- import pygame
- from time import sleep
- # colors
- BLACK = (0, 0, 0)
- WHITE = (255, 255, 255)
- GREEN = (0, 255, 0)
- BLUE = (0, 0, 255)
- pygame.init()
- canvas = pygame.display.set_mode((800, 800))
- canvas.fill(BLACK)
- pygame.display.set_caption("trygonometry test")
- exit = False
- center = x, y = [400, 400]
- iterations = 360
- radius = 400
- points = []
- for j in range(iterations):
- step_x = sin(2*pi/iterations * j) * radius + x
- step_y = cos(2*pi/iterations * j) * radius + y
- points.append([step_x, step_y])
- i = 0
- step = 2
- 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:
- canvas.fill(BLACK)
- step=3
- if event.unicode == "+":
- canvas.fill(BLACK)
- step += 1
- if event.unicode == "-":
- canvas.fill(BLACK)
- step -= 1
- pygame.draw.circle(canvas, WHITE, center, radius, 1)
- pygame.draw.line(canvas, BLUE, points[i], points[i*step % iterations])
- for j, point in enumerate(points):
- pygame.draw.circle(canvas, GREEN, point, 2)
- # pygame.draw.line(canvas, BLUE, point, points[j*6 % iterations])
- i += 1
- i = 0 if i == iterations else i
- pygame.display.update()
Advertisement
Add Comment
Please, Sign In to add comment