完成的内容:创建两个线程,分别控制两个不同的画笔画出黑白两部分,保留绘画轨迹。
结果图:
不过太极图的半径设的较大的话,太极图会画到一半停下,我也不太清楚为什么
import turtle
import threading
# 设置画笔初始属性
turtle.pensize(2)
turtle.color('black')
turtle.hideturtle()#隐藏画笔
# 设置两个画笔来进行双线程绘画
p1 = turtle.Pen()
p2 = turtle.Pen()
# 绘制黑色部分的函数
def draw_black():
p1.penup()
p1.goto(0,50)
p1.pendown()
p1.seth(180)
p1.fillcolor('black')
p1.begin_fill()
p1.circle(50,180)
p1.circle(25,-180)
p1.circle(-25,-180)
p1.end_fill()
# 绘制小圆点
p1.penup()
p1.goto(0,14)
p1.pendown()
p1.fillcolor('white')
p1.begin_fill()
p1.circle(6,360)
p1.end_fill()
# 绘制白色部分函数
def draw_white():
p2.color('black')
p2.penup()
p2.goto(0,-50)
p2.pendown()
p2.seth(0)
p2.fillcolor('white')
p2.begin_fill()
p2.circle(50,180)
p2.circle(25,-180)
p2.circle(-25,-180)
p2.end_fill()
# 绘制小圆点
p2.penup()
p2.goto(0, -14)
p2.pendown()
p2.fillcolor('black')
p2.begin_fill()
p2.circle(6, 360)
p2.end_fill()
# 设置双线程
t1= threading.Thread(target=draw_black)
t2 = threading.Thread(target=draw_white)
t1.start()
t2.start()
turtle.mainloop()