理解函数的概念,函数的定义及参数的使用学会将等腰直角三角形、正方形、平行四边形等图形定义为函数。
1 七巧板的关系
七巧板由2个大三角、1个中三角、2个小三角、1个平行四边形组成
![](https://img2020.cnblogs.com/blog/114370/202008/114370-20200812221942106-2119603764.png)
2 代码
from turtle import *
len=200
坐标=[]
def writestr(a):
write(a, False, "left", ("Arial", 10, "normal"))
def 平行四边形(x,y):
坐标.clear()
penup()
goto(x,y)
writestr(1)
坐标.append([xcor(),ycor()])
pendown()
begin_fill()
forward(len/2)
writestr(2)
坐标.append([xcor(),ycor()])
right(45)
forward(len/2*1.414/2)
writestr(3)
坐标.append([xcor(),ycor()])
right(135)
forward(len/2)
writestr(4)
坐标.append([xcor(),ycor()])
right(45)
forward(len/2*1.414/2)
right(135)
end_fill()
def 正方形(x,y):
begin_fill()
坐标.clear()
penup()
goto(x, y)
writestr(1)
坐标.append([xcor(), ycor()])
pendown()
forward(len/2/1.414)
writestr(2)
坐标.append([xcor(), ycor()])
left(90)
forward(len/2/1.414)
writestr(3)
坐标.append([xcor(), ycor()])
left(90)
forward(len/2/1.414)
writestr(4)
坐标.append([xcor(), ycor()])
left(90)
forward(len/2/1.414)
end_fill()
def 大三角形(x,y):
begin_fill()
坐标.clear()
penup()
goto(x, y)
writestr(1)
坐标.append([xcor(), ycor()])
pendown()
forward(len/1.414)
writestr(2)
坐标.append([xcor(), ycor()])
left(135)
forward(len)
writestr(3)
坐标.append([xcor(), ycor()])
left(135)
forward(len/1.414)
left(90)
end_fill()
def 中三角形(x,y):
begin_fill()
坐标.clear()
penup()
goto(x, y)
writestr(1)
坐标.append([xcor(), ycor()])
pendown()
forward(len/2)
writestr(2)
坐标.append([xcor(), ycor()])
left(135)
forward(len/2*1.414)
writestr(3)
坐标.append([xcor(), ycor()])
left(135)
forward(len/2)
left(90)
end_fill()
def 小三角形(x,y):
begin_fill()
坐标.clear()
penup()
goto(x, y)
writestr(1)
坐标.append([xcor(), ycor()])
pendown()
forward(len/2/1.414)
writestr(2)
坐标.append([xcor(), ycor()])
left(135)
forward(len/2)
writestr(3)
坐标.append([xcor(), ycor()])
left(135)
forward(len/2/1.414)
left(90)
end_fill()
color("blue")
平行四边形(-100,-100)
color("red")
setheading(-45)
正方形(坐标[1][0],坐标[1][1])
color("orange")
setheading(-45)
大三角形(坐标[3][0],坐标[3][1])
紫色x=坐标[1][0]-abs(坐标[1][0]-坐标[0][0])*1/4
紫色y=坐标[1][1]+abs(坐标[0][1]-坐标[1][1])*1/4-len/2
color("yellow")
setheading(-90)
大三角形(坐标[2][0],坐标[2][1])
绿色x=坐标[2][0]-abs(坐标[2][0]-坐标[0][0])*1/4
绿色y=坐标[0][1]
棕色x=(坐标[1][0]+坐标[2][0])/2
棕色y=(坐标[1][1]+坐标[2][1])/2
color("purple")
setheading(0)
中三角形(紫色x,紫色y)
color("green")
setheading(0)
小三角形(绿色x,绿色y)
color("brown")
setheading(-45)
小三角形(棕色x,棕色y)
mainloop()
3 效果图
![](https://img2020.cnblogs.com/blog/114370/202008/114370-20200812222309647-1189068103.png)
顶
Top
关注
评论
博文分享:
许可协议:
![Creative Commons License](http://i.creativecommons.org/l/by-nc/3.0/88x31.png) 本文基于署名-非商业性使用 3.0许可协议发布,欢迎转载,演绎,且不得用于商业目的。如您有任何疑问或者授权方面的协商,请与我联系。
|