-
Notifications
You must be signed in to change notification settings - Fork 0
/
Circle.py
84 lines (62 loc) · 2.59 KB
/
Circle.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import math
import random
from numpy import *
from numpy.linalg import *
import pygame
from pygame.locals import *
from Planet import Planet
class Display:
def main_loop(self):
planet = Planet(100,1,0)
pygame.init()
screen = pygame.display.set_mode((planet.max_row,planet.row_count),
HWSURFACE)
pygame.display.set_caption('Planet')
background = pygame.Surface(screen.get_size())
background.fill((128,128,128))
def in_bounds(x,y):
return (x > planet.row_offsets[y] and
x < planet.row_offsets[y] + planet.row_lengths[y])
background.lock()
for y in range(0, screen.get_height()):
for x in range(0, screen.get_width()):
if in_bounds(x,y):
value = planet.rows[y][x - planet.row_offsets[y]]
background.set_at((x,y),(value,value,value))
background.unlock()
screen.blit(background, (0,0))
points = pygame.sprite.Group()
for n in range(5):
point = pygame.sprite.Sprite()
point.image = pygame.Surface((10,10))
pygame.draw.circle(point.image, (255,0,0), (5,5), 5)
row = random.randint(1, planet.row_count-1)
a = array([random.uniform(-1) for i in range(3)])
point.p = a / norm(a)
point.theta = 0 if n == 0 else random.uniform(0, 2 * math.pi)
u = zeros(3)
u[min(range(len(a)), key=lambda i: abs(point.p[i]))] = 1
v = cross(point.p, u)
point.v = 0.01 * planet.rotate(v / norm(v), point.p,
random.uniform(0, 2*math.pi))
point.rect = pygame.Rect((0,0), point.image.get_size())
points.add(point)
limit = pygame.time.Clock()
done = False
while not done:
for event in pygame.event.get():
if event.type == QUIT:
done = True
elif event.type == KEYDOWN:
if event.key == K_ESCAPE:
done = True
for point in points:
point.p, point.v = planet.apply_velocity(point.p, point.v)
point.rect.topleft = planet.vector_to_xy(point.p,
point.image.get_size())
points.clear(screen, background)
points.draw(screen)
pygame.display.flip()
limit.tick()
if __name__ == '__main__':
Display().main_loop()