画图,综合例子。
1 #! /usr/bin/env python
2 # -*- coding:utf-8 -*-
3 '''
4 画图,综合例子。
5 '''
6 if __name__ == '__main__':
7 from tkinter import *
8
9 canvas = Canvas(width=300, height=300, bg='#00f0e9')
10 canvas.pack(expand=YES, fill=BOTH)
11 x0 = 150
12 y0 = 100
13 canvas.create_oval(x0 - 10, y0 - 10, x0 + 10, y0 + 10)
14 canvas.create_oval(x0 - 20, y0 - 20, x0 + 20, y0 + 20)
15 canvas.create_oval(x0 - 50, y0 - 50, x0 + 50, y0 + 50)
16 import math
17
18 B = 0.809
19 for i in range(16):
20 a = 2 * math.pi / 16 * i
21 x = math.ceil(x0 + 48 * math.cos(a))
22 y = math.ceil(y0 + 48 * math.sin(a) * B)
23 canvas.create_line(x0, y0, x, y, fill='red')
24 canvas.create_oval(x0 - 60, y0 - 60, x0 + 60, y0 + 60)
25
26 for k in range(501):
27 for i in range(17):
28 a = (2 * math.pi / 16) * i + (2 * math.pi / 180) * k
29 x = math.ceil(x0 + 48 * math.cos(a))
30 y = math.ceil(y0 + 48 + math.sin(a) * B)
31 canvas.create_line(x0, y0, x, y, fill='red')
32 for j in range(51):
33 a = (2 * math.pi / 16) * i + (2 * math.pi / 180) * k - 1
34 x = math.ceil(x0 + 48 * math.cos(a))
35 y = math.ceil(y0 + 48 * math.sin(a) * B)
36 canvas.create_line(x0, y0, x, y, fill='red')
37 mainloop()