-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrandom circles using pygame.py
More file actions
executable file
·60 lines (48 loc) · 1.24 KB
/
random circles using pygame.py
File metadata and controls
executable file
·60 lines (48 loc) · 1.24 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
import pygame
import random
import time
pygame.init()
white = (255,255,255)
width = 800
height = 600
running = 1
gameDisplay = pygame.display.set_mode((width,height))
gameDisplay.fill(white)
r = int(35*random.random())
x = int(width*random.random())
y = int(height*random.random())
def randomColor():
return (255*random.random(),255*random.random(),255*random.random())
pygame.draw.circle(gameDisplay, randomColor(), (x,y), r)
l=[[x,y,r]]
ct=0
r = int(50*random.random())
while 1:
flag = 1
x = int(width*random.random())
y = int(height*random.random())
for i in l:
d = ( (x-i[0])**2 + (y-i[1])**2 )**0.5
if d < r+i[2]:
flag = 0
break
#print(x,y,r, i, d,' ',r+i[2])
break
if flag:
pygame.draw.circle(gameDisplay, randomColor(), (x,y), r)
pygame.display.update()
ct+=1
print(ct)
time.sleep(0.1)
l.append([x,y,r])
r = int(50*random.random())
#print(l)
try:
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
pygame.display.quit()
pygame.quit()
except SystemExit:
pygame.quit()