画八卦图,需要思路和计算
可以用turtle的粗画笔来实现挖空操作
import turtle
# 创建一个新的画布
win = turtle.Screen()
# 设置窗口大小和背景颜色
win.setup(500,500)
win.bgcolor("white")
# 创建一个turtle对象
t = turtle.Turtle()
#设置八卦图大小
r = 100
# 画圆
t.speed(10)
t.penup()
t.goto(0,-r)
t.pendown()
t.circle(r)
# 画上下部分的黑色圆弧
t.penup()
t.goto(0,0)
t.pendown()
t.begin_fill()
t.pencolor("black")
t.fillcolor("black")
t.circle(r/2,180)
t.circle(r,180)
t.circle(r/2,-180)
t.end_fill()
# 添加两个小圆点
t.pencolor("black")
t.fillcolor("white")
t.begin_fill()
t.penup()
t.goto(0,r/2)
t.pendown()
t.circle(r/15)
t.end_fill()
t.pencolor("black")
t.fillcolor("black")
t.begin_fill()
t.penup()
t.goto(0,-r/2)
t.pendown()
t.circle(r/15)
t.end_fill()
# 三个八边形
t.pensize(12)
t.pencolor("black")
t.penup()
t.goto(-45,108)
t.seth(360)
t.pendown()
for i in range(8):
t.forward(90)
t.right(45)
t.penup()
t.goto(-55,132)
t.seth(360)
t.pendown()
for i in range(8):
t.forward(110)
t.right(45)
t.penup()
t.goto(-65,156)
t.seth(360)
t.pendown()
for i in range(8):
t.forward(130)
t.right(45)
# 画白线
t.penup()
t.pencolor("white")
t.pensize(12)
t.goto(-42,100.8)
t.pendown()
t.seth(112.5)
t.forward(300)
t.pensize(12)
t.penup()
t.goto(42,100.8)
t.pendown()
t.seth(67.5)
t.forward(300)
t.pensize(12)
t.penup()
t.goto(85,85)
t.pendown()
t.seth(45)
t.forward(300)
t.pensize(12)
t.penup()
t.goto(100.8,42)
t.pendown()
t.seth(22.5)
t.forward(300)
t.pensize(12)
t.penup()
t.goto(105.5,0)
t.pendown()
t.seth(0)
t.forward(35)
t.pensize(12)
t.penup()
t.goto(100.8,-42)
t.pendown()
t.seth(-22.5)
t.forward(300)
t.pensize(12)
t.penup()
t.goto(108,-108)
t.pendown()
t.seth(-45)
t.forward(300)
t.pensize(12)
t.penup()
t.goto(42,-100.8)
t.pendown()
t.seth(-67.5)
t.forward(300)
t.penup()
t.goto(-42,-100.8)
t.pendown()
t.seth(-112.5)
t.forward(300)
t.penup()
t.goto(-74.5,-74.5)
t.pendown()
t.seth(-135)
t.forward(300)
t.penup()
t.goto(-100.8,-42)
t.pendown()
t.seth(-157.5)
t.forward(300)
t.penup()
t.goto(-105.5,0)
t.pendown()
t.seth(-180)
t.forward(13)
t.penup()
t.goto(-100.8,42)
t.pendown()
t.seth(-202.5)
t.forward(300)
t.penup()
t.goto(0,105.5)
t.pendown()
t.seth(90)
t.forward(10)
t.penup()
t.goto(0,150)
t.pendown()
t.seth(90)
t.forward(30)
t.penup()
t.goto(0,-127)
t.pendown()
t.seth(-90)
t.forward(12)
# 隐藏turtle
t.hideturtle()
# 程序图形化界面待用户关闭
turtle.done()