用户:mark_car查看:0 回复:0 评论:0 创建时间:2020-07-27T18:14:35
【作品展示】

【作品介绍】
运行就行了,但不能转成积木哦~不然会报错!!!!
【作品源代码】
import turtle as t
def draw_triangle(penlist,loc_x,loc_y,b_fill,colora,b_inside,colorb,iLevel):
if iLevel>=1:
for pen in penlist:
if iLevel==5:
pen.penup()
pen.setx(loc_x[0])
pen.sety(loc_y[0])
pen.pendown()
if b_fill:
pen.fillcolor(colora[5-iLevel])
pen.begin_fill()
pen.goto(loc_x[1],loc_y[1])
pen.goto(loc_x[2],loc_y[2])
pen.goto(loc_x[0],loc_y[0])
if b_fill:
pen.end_fill()
pen.penup()
pen.setx((loc_x[0]+loc_x[1])/2.0)
pen.sety((loc_y[0]+loc_y[1])/2.0)
pen.pendown()
if b_inside:
pen.fillcolor(colorb[5-iLevel])
pen.begin_fill()
pen.goto((loc_x[1]+loc_x[2])/2.0,(loc_y[1]+loc_y[2])/2.0)
pen.goto((loc_x[2]+loc_x[0])/2.0,(loc_y[2]+loc_y[0])/2.0)
pen.goto((loc_x[0]+loc_x[1])/2.0,(loc_y[0]+loc_y[1])/2.0)
if b_inside:
pen.end_fill()
#递归
new_x,new_y=[],[]
new_x.append(loc_x[0])
new_y.append(loc_y[0])
new_x.append((loc_x[0]+loc_x[1])/2.0 )
new_y.append((loc_y[0]+loc_y[1])/2.0 )
new_x.append((loc_x[0]+loc_x[2])/2.0 )
new_y.append((loc_y[0]+loc_y[2])/2.0 )
draw_triangle(penlist,new_x,new_y,b_fill,colora,b_inside,colorb,iLevel-1)
new_x,new_y=[],[]
new_x.append(loc_x[1])
new_y.append(loc_y[1])
new_x.append((loc_x[1]+loc_x[2])/2.0 )
new_y.append((loc_y[1]+loc_y[2])/2.0 )
new_x.append((loc_x[1]+loc_x[0])/2.0 )
new_y.append((loc_y[1]+loc_y[0])/2.0 )
draw_triangle(penlist,new_x,new_y,b_fill,colora,b_inside,colorb,iLevel-1)
new_x,new_y=[],[]
new_x.append(loc_x[2])
new_y.append(loc_y[2])
new_x.append((loc_x[2]+loc_x[0])/2.0 )
new_y.append((loc_y[2]+loc_y[0])/2.0 )
new_x.append((loc_x[2]+loc_x[1])/2.0 )
new_y.append((loc_y[2]+loc_y[1])/2.0 )
draw_triangle(penlist,new_x,new_y,b_fill,colora,b_inside,colorb,iLevel-1)
#
#
#t.screensize() #返回默认大小(400, 300)
#t.setup(width=800,height=800, startx=100, starty=100)
#t.screensize(800,600, "green")
t.speed(1000)
# t.hideturtle()
t.pensize(0.001)
t.color('#FF0000','#0000FF')
b_drawa=True
b_drawinside=True
x=[-300,300,0]
y=[-300,-300,300]
penlist=[]
penlist.append(t)
colora_list=['lightcoral','lightcoral','lightcoral','lightcoral','lightcoral']
colorb_list=['#FF0000','#FFFF00','#0000FF','#00FF33','#330000']
draw_triangle(penlist,x,y,b_drawa,colora_list,b_drawinside,colorb_list,5)
t.done()
【提示】
部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:
https://python.codemao.cn