目录
63.题目:画椭圆
1.tkinter画椭圆
2.turtle画椭圆
64.题目:利用ellipse 和 rectangle 画图
63.题目:画椭圆
1.tkinter画椭圆
#63
from tkinter import *
x = 360
y = 160
top = y - 30
bottom = y - 30canvas = Canvas(width = 500,height = 600,bg = 'white')
for i in range(20):canvas.create_oval(250 - top,250 - bottom,250 + top,250 + bottom)top -= 5bottom += 5
canvas.pack()
mainloop()
输出:
2.turtle画椭圆
import turtlepen=turtle.Turtle() #定义画笔实例
a=1
for i in range(120): if 0<=i<30 or 60<=i<90: #控制a的变化a=a+0.2pen.lt(3) #向左转3度pen.fd(a) #向前走a的步长else:a=a-0.2pen.lt(3)pen.fd(a)print(pen)
turtle.mainloop()
输出:
64.题目:利用ellipse 和 rectangle 画图
from tkinter import *
canvas = Canvas(width = 400,height = 600,bg = 'white')
left = 20
right = 50
top = 50
num = 15
for i in range(num):canvas.create_oval(250 - right,250 - left,250 + right,250 + left)canvas.create_oval(250 - 20,250 - top,250 + 20,250 + top)canvas.create_rectangle(20 - 2 * i,20 - 2 * i,10 * (i + 2),10 * ( i + 2))right += 5left += 5top += 10canvas.pack()
mainloop()
输出: