-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdots.py
More file actions
executable file
·62 lines (46 loc) · 1.37 KB
/
Copy pathdots.py
File metadata and controls
executable file
·62 lines (46 loc) · 1.37 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 random
import pygame
import time
# All the pygame setup
pygame.init()
width = 1000
height = width / 2
screen = pygame.display.set_mode([width, int(height)])
pygame.display.set_caption("Geometry")
white = (255, 255, 255)
dots = []
velocity = []
def new():
side = random.randint(1,2) #1=x #2=y
x = random.uniform(1, width)
y = random.uniform(1, height)
o = random.randint(0, 1)
if side==1:
x = width * o
else:
y = height * o
if o == 0:
o = 1
else:
o = -1
speedx = (random.uniform(0, 2)/10 * o)
speedy = (random.uniform(0, 2)/10 * o)
dots.append([x, y])
velocity.append([speedx,speedy])
for m in range(0, 35):
new()
while True:
pygame.event.get()
screen.fill((0, 0, 0))
for i in range(len(dots)):
dots[i][0] += velocity[i][0]
dots[i][1] += velocity[i][1]
pygame.draw.circle(screen, white, dots[i], 3)
for g in range(i, len(dots)):
if ((abs((dots[i][0])-(dots[g][0]))**2 )+ (abs((dots[i][1])-(dots[g][1]))**2 ))**0.5 <150:
pygame.draw.line(screen, white, dots[i], dots[g], 2)
if dots[i][0] > width or dots[i][0] < 0 or dots[i][1] > height or dots[i][1] < 0:
new()
del dots[i]
del velocity[i]
pygame.display.flip()