-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathorbits with fade.py
68 lines (49 loc) · 1.68 KB
/
orbits with fade.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import math
import time
import random
import pygame
pygame.init()
display = pygame.display.set_mode((1920, 1080), pygame.FULLSCREEN, vsync=1)
clock = pygame.time.Clock()
start = time.perf_counter()
class Planet():
def __init__(self):
self.x = 0
self.y = 0
self.r = random.randint(1, 20)
self.d = random.randint(1,display.get_height()/2)
self.color = [random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)]
self.s = random.random()
def render(self):
self.x = c[0] + self.d * math.sin(d*self.s)
self.y = c[1] + self.d * math.cos(d*self.s)
pygame.draw.circle(display, self.color, (self.x, self.y), self.r)
p = []
for _ in range(20):
p.append(Planet())
while True:
d = time.perf_counter()-start
c = display.get_width() / 2, display.get_height() / 2
window_size = display.get_width(), display.get_height()
Surface = pygame.Surface(window_size).convert()
Surface.fill((0, 0, 0))
Surface.set_colorkey((0, 0, 0))
Surface2 = pygame.Surface(window_size)
Surface2.fill((0, 0, 0))
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
quit()
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
pygame.quit()
quit()
if event.key == pygame.K_SPACE:
display.fill([0, 0, 0])
for object in p:
object.render()
Surface2.set_alpha(1) # 10
display.blit(Surface2, (0, 0))
display.blit(Surface, (0, 0))
pygame.display.flip()
clock.tick(60)