运行结果:
代码:
import turtle
turtle.setup(1024,1024,200,200)
# 移动画笔
turtle.penup()
turtle.goto(-200,200)
turtle.pendown()
# 绘制第一条实线
turtle.setheading(0)
turtle.forward(300)
# 绘制第二条实线
turtle.setheading(180+45)
turtle.forward(100)
# 绘制第三条实线
turtle.setheading(180)
turtle.forward(300)
# 绘制第四条实线
turtle.setheading(45)
turtle.forward(100)
# 绘制第一条虚线
turtle.setheading(-90)
for i in range(8):
turtle.forward(10)
turtle.penup()
turtle.forward(10)
turtle.pendown()
# 绘制第二条虚线
turtle.setheading(0)
for i in range(15):
turtle.forward(10)
turtle.penup()
turtle.forward(10)
turtle.pendown()
# 绘制下第一条实线
turtle.setheading(180+45)
turtle.forward(100)
# 绘制下第二条实线
turtle.setheading(180)
turtle.forward(300)
# 绘制下第一条虚线
turtle.setheading(45)
for i in range(5):
turtle.forward(10)
turtle.penup()
turtle.forward(10)
turtle.pendown()
#抬笔画
turtle.penup()
turtle.setheading(0)
turtle.forward(300)
turtle.setheading(90)
turtle.pendown()
turtle.forward(160)
turtle.penup()
turtle.setheading(180+45)
turtle.forward(100)
turtle.setheading(-90)
turtle.pendown()
turtle.forward(160)
turtle.penup()
turtle.setheading(180)
turtle.forward(300)
turtle.setheading(90)
turtle.pendown()
turtle.forward(160)
# 消除------------------------------------------------------------
turtle.pencolor('white')
turtle.penup()
turtle.goto(-200,200)
turtle.pendown()
# 绘制
turtle.setheading(0)
turtle.forward(300)
turtle.setheading(180+45)
turtle.forward(100)
turtle.setheading(180)
turtle.forward(300)
turtle.setheading(45)
turtle.forward(100)
turtle.setheading(-90)
for i in range(8):
turtle.forward(10)
turtle.penup()
turtle.forward(10)
turtle.pendown()
turtle.setheading(0)
for i in range(15):
turtle.forward(10)
turtle.penup()
turtle.forward(10)
turtle.pendown()
turtle.setheading(180+45)
turtle.forward(100)
turtle.setheading(180)
turtle.forward(300)
turtle.setheading(45)
for i in range(5):
turtle.forward(10)
turtle.penup()
turtle.forward(10)
turtle.pendown()
turtle.penup()
turtle.setheading(0)
turtle.forward(300)
turtle.setheading(90)
turtle.pendown()
turtle.forward(160)
turtle.penup()
turtle.setheading(180+45)
turtle.forward(100)
turtle.setheading(-90)
turtle.pendown()
turtle.forward(160)
turtle.penup()
turtle.setheading(180)
turtle.forward(300)
turtle.setheading(90)
turtle.pendown()
turtle.forward(160)
turtle.done()