-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgraphics_bubbles.py
More file actions
36 lines (24 loc) · 877 Bytes
/
graphics_bubbles.py
File metadata and controls
36 lines (24 loc) · 877 Bytes
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
##############################################################################
# The program shows many circles
##############################################################################
import tkinter
import random
width = 640
height = 480
canvas = tkinter.Canvas(width=width, height=height, bg="gray")
canvas.pack()
def paint_circle(x, y, size, color):
coordinates = x - size / 2, y - size / 2, x + size / 2, y + size / 2
canvas.create_oval(coordinates, fill=color)
def size_def(x, y):
return ((x - width / 2)**2 + (y - height / 2)**2)**.5
def color_def(size):
x = 255 - int((size / 400) * 255)
return '#{:02x}{:02x}{:02x}'.format(x, x, x)
for x in range(2000):
x = random.randrange(width)
y = random.randrange(height)
size = size_def(x, y)
color = color_def(size)
paint_circle(x, y, size / 4, color)
canvas.mainloop()