-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
62 lines (51 loc) · 1.68 KB
/
main.py
File metadata and controls
62 lines (51 loc) · 1.68 KB
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
import sys
import random
import pygame
import time
from librender.renderer import Renderer
from libgeo.segment import Segment
from libgeo.point import Point
from libgeo.parabola import Parabola
from libstructures.tree import Tree
from libstructures.tree import Node
def prn(x):
print x
WINDOW_WIDTH = 800
WINDOW_HEIGHT = 600
random.seed()
pygame.init()
window = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT))
renderer = Renderer(window)
framect = 300
tree = Tree(None)
rng = 11
num = 10
randopoints = [random.uniform(-rng, rng) for x in range(0, num)]
randopoints.sort(reverse=True)
randopoints = [Point(random.uniform(-rng, rng), x) for x in randopoints]
#queue = [Point(5, 5), Point(1, 4.5), Point(1.1, 4.25), Point(-2, 3), Point(3, -1), Point(-5, -2), Point(-3, -3)]
queue = randopoints
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit(0)
framect -= 1
renderer.draw_segment(Segment(Point(-20, 0), Point(20, 0)))
renderer.draw_segment(Segment(Point(0, -15), Point(0, 15)))
ind = framect / 20.0
if len(queue) == 0:
pass
else:
if queue[0].y > ind:
tree.insert(queue[0])
queue = queue[1:]
pt = Point(0, ind)
points = tree.serialize()
parabolas = map(lambda x: Parabola.generate_from_directrix_and_focus(pt.y, x), points)
map(lambda parabola: renderer.draw_parabola(parabola), parabolas)
map(lambda point: renderer.draw_point(point), points)
map(lambda point: renderer.draw_point(point), queue)
if not parabolas == []:
renderer.draw_parabola(pt.nearest_vertical_parabola(parabolas), (255, 0, 0))
renderer.draw_segment(Segment(Point(-20, ind), Point(20, ind)), (0, 255, 0))
renderer.draw()