forked from yangdd1205/python3-100-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example65.py
53 lines (40 loc) · 1.06 KB
/
example65.py
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
#!/usr/bin/python3
from tkinter import *
import math
__author__ = "yang.dd"
"""
example 065
"""
class PTS:
def __init__(self):
self.x = 0
self.y = 0
points = []
def linetodemo():
screenx = 400
screeny = 400
canvas = Canvas(width=screenx, height=screeny, bg='white')
AspectRatio = 0.85
MAXPTS = 15
h = screeny
w = screenx
xcenter = w / 2
ycenter = h / 2
radius = (h - 30) / (AspectRatio * 2) - 20
step = 360 / MAXPTS
angle = 0.0
for i in range(MAXPTS):
rads = angle * math.pi / 180.0
p = PTS()
p.x = xcenter + int(math.cos(rads) * radius)
p.y = ycenter - int(math.sin(rads) * radius * AspectRatio)
angle += step
points.append(p)
canvas.create_oval(xcenter - radius, ycenter - radius, xcenter + radius, ycenter + radius)
for i in range(MAXPTS):
for j in range(i, MAXPTS):
canvas.create_line(points[i].x, points[i].y, points[j].x, points[j].y)
canvas.pack()
mainloop()
if __name__ == '__main__':
linetodemo()