|
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转新大榭论坛!
您需要 登录 才可以下载或查看,没有账号?注册
x
题目:画图,综合例子。6 }+ `& ^! q- T, M$ c1 Y! Z A
程序分析:丑。* o3 }* a W: O) u
- if __name__ == '__main__':
4 l" W4 ~5 l# E1 b. F1 D - from tkinter import *0 Z! ?8 i6 K: E3 Z5 y+ f0 N2 l" R
- canvas = Canvas(width = 300,height = 300,bg = 'green')- b. _# _) O/ x& W' s9 [$ O* q* M
- canvas.pack(expand = YES,fill = BOTH)
/ E* k8 u6 e/ p0 q! i: N* s$ `! y& a - x0 = 150
/ w- a, N: s- N8 p - y0 = 1004 R* G# z3 a5 g
- canvas.create_oval(x0 - 10,y0 - 10,x0 + 10,y0 + 10)
, Q: ~6 V9 Z& O+ g$ G) n% h; T8 V - canvas.create_oval(x0 - 20,y0 - 20,x0 + 20,y0 + 20)( Z) K& \4 H7 s: j0 J' e, u; @+ z
- canvas.create_oval(x0 - 50,y0 - 50,x0 + 50,y0 + 50)
8 m4 |% _) P8 ~+ s - import math
/ q2 B j4 c+ |5 ^: s' L) n" Y& p - B = 0.809
3 _: Q# e: i% w6 f - for i in range(16):
/ R) Z6 o4 G! C3 G& O - a = 2 * math.pi / 16 * i
$ d) ~ d$ |; ~2 q# s( F7 p" ? - x = math.ceil(x0 + 48 * math.cos(a))
$ j' R$ o; f' I1 ?# R - y = math.ceil(y0 + 48 * math.sin(a) * B)
* J1 j+ {1 v+ s5 J - canvas.create_line(x0,y0,x,y,fill = 'red')( U- k7 Y: `; |4 d! Y# k
- canvas.create_oval(x0 - 60,y0 - 60,x0 + 60,y0 + 60)
+ ~4 |; V3 U, F% ]3 h; \ - ' s, T' k6 T0 b" k `* [; d! j
- * E8 }: f% Y7 w9 Y' Q/ \
- for k in range(501):
7 m2 S" B0 J5 Y2 b - for i in range(17):
8 B. P% O8 a n# Q9 a# t/ B - a = (2 * math.pi / 16) * i + (2 * math.pi / 180) * k
$ w1 c. H/ o' B" m. P - x = math.ceil(x0 + 48 * math.cos(a))
9 u& R' w! E( D; m% m, e1 P - y = math.ceil(y0 + 48 + math.sin(a) * B): z! Z' w) b/ S" V+ g" x' w$ y9 X
- canvas.create_line(x0,y0,x,y,fill = 'red'): X+ \8 T" x8 b$ T) e
- for j in range(51):" |6 k: S/ [( C! l- t
- a = (2 * math.pi / 16) * i + (2* math.pi / 180) * k - 16 c; X) N9 m$ g: u! T3 O: n5 {! q
- x = math.ceil(x0 + 48 * math.cos(a))* K& a4 Q8 ?0 Y6 y0 W3 J: ]
- y = math.ceil(y0 + 48 * math.sin(a) * B)
. V1 D0 ]2 m2 V - canvas.create_line(x0,y0,x,y,fill = 'red'), `4 X- F6 p; O5 M5 E3 K {
- mainloop()
复制代码 |
|