py-sec-1
from turtle import *
for i in range(1,5):
penup()
fd(20)
pendown()
fd(40)
penup()
fd(20)
seth(i*90)
done()
py-sec-2
py-sec-2
import turtle#引入turtle库
turtle.setup(650, 350,)#设置画布大小
turtle.penup()#笔抬起
turtle.fd(-250)#后退250
turtle.pendown()#笔放下
turtle.pensize(25)#设置笔的宽度为25
turtle.pencolor("purple")#设置笔的颜色为紫色
turtle.seth(-40)#方向设置为右下方向40°
for i in range(4):#循环四次
turtle.circle(40, 80)#根据半径40(圆心为左侧),角度为顺时针80度绘制
turtle.circle(-40, 80)#根据半径40(圆心为右侧),角度为顺时针80度绘制
turtle.circle(40, 80/2)#根据半径40(圆心为左侧),角度为顺时针40度绘制
turtle.fd(40)#前进40
turtle.circle(16, 180)#根据半径16(圆心为左侧),角度为顺时针180度绘制
turtle.fd(40 * 2/3)#前进40 * 2/3
turtle.done()#停止画笔绘制,绘图窗体不关闭
py-sec-3
py-sec-3
import turtle
d = 0
turtle.fillcolor('red')
turtle.begin_fill()
for i in range(5):
turtle.fd(200)
d += 72
turtle.seth(d)
turtle.end_fill()
turtle.done()
py-sec-4
py-sec-4
from turtle import *
def trangle(i,j):
edge = j
penup()
seth(-135)
fd(200)
for num in range(1,i+1):
pendown()
edge = edge / 2
seth(60 - 60 * (num - 1))
fd(edge)
seth(-60 - 60 * (num - 1))
fd(edge)
seth(180 - 60 * (num - 1))
fd(edge)
penup()
#换个位置
seth(60 - 60 * (num - 1))
fd(edge / 2)
i=eval(input('你要嵌套几层'))
j=eval(input('最外边长为'))
trangle(i,j)
done()