绘制正方形内嵌圆形

image

基本方法:

import turtle as t
def draw():
    t.hideturtle()
    t.pensize(4)
    t.color("red")
    t.goto(50,0)
    t.seth(90)
    t.forward(50)
    t.left(90)
    t.forward(100)
    t.left(90)
    t.forward(100)
    t.left(90)
    t.forward(100)
    t.left(90)
    t.forward(50)

def draw_circle():
    t.begin_fill()
    t.hideturtle()
    t.pensize(4)
    l=50
    t.color("red")
    t.circle(l,360)
    t.fillcolor("yellow")
    t.end_fill()

draw()
draw_circle()



t.exitonclick() #turtle执行完后保留那个页面



image
image

用循环来实现

import turtle as t
def draw():
    t.hideturtle()
    t.pensize(4)
    t.color("red")
    t.forward(100)
    t.left(90)
def draw_circle():
    t.begin_fill()
    t.hideturtle()
    t.pensize(4)
    l=50
    t.color("red")
    t.circle(l,360)
    t.fillcolor("yellow")
    t.end_fill()

t.goto(50,0)
t.left(90)
t.back(50)
t.clear()
for i in range(4):
    draw()

t.seth(90)
t.forward(50)
draw_circle()



t.exitonclick() #turtle执行完后保留那个页面



image

posted @ 2022-10-15 09:51  Selina风乎舞雩  阅读(194)  评论(0)    收藏  举报