forked from tks2103/visualizer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpoints.py
More file actions
72 lines (49 loc) · 1.38 KB
/
points.py
File metadata and controls
72 lines (49 loc) · 1.38 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
63
64
65
66
67
import sys
#import and init pygame
import pygame
import random
WINDOW_WIDTH = 640
WINDOW_HEIGHT = 480
random.seed()
pygame.init()
#create the screen
window = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT))
window.fill((255,255,255))
def generatePoint():
x = random.randint(0,WINDOW_WIDTH)
y = random.randint(0,WINDOW_HEIGHT)
return (x,y)
def generatePoints(num):
points = []
for i in range(0,num):
points.append(generatePoint())
return points
def generateSegments(num):
segments = []
for i in range(0,num):
segments.append((generatePoint(),generatePoint()))
return segments
def drawPoint(pos):
pygame.draw.circle(window, (0,0,0), pos, 2, 2)
def drawSegment(segment):
pygame.draw.line(window, (0,0,0), segment[0], segment[1], 2)
def drawSegments(segments):
for segment in segments:
drawSegment(segment)
def drawPoints(positions):
for position in positions:
drawPoint(position)
#draw a line - see http://www.pygame.org/docs/ref/draw.html for more
#pygame.draw.line(window, (255, 023, 255), (0, 0), (30, 50))
#drawPoints(generatePoints(10))
#drawSegment( (generatePoint(), generatePoint()) )
drawSegments(generateSegments(50))
#draw it to the screen
pygame.display.flip()
#input handling (somewhat boilerplate code):
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit(0)
else:
print event