python turtle 太极八卦图

from turtle import *
import math
speed(10)

# 设置尺寸为400*400,背景为黄色的画布
screensize(400, 400, "yellow")

# 太极图
pencolor("black")
pensize(3)
penup()
goto(0, -100)
pendown()

fillcolor("black")
begin_fill()
circle(100, 180)
circle(50, -180)
circle(-50, -180)
end_fill()

fillcolor("white")
begin_fill()
circle(-100, 180)
circle(-50, 180)
circle(50, 180)
end_fill()

penup()
goto(0, -65)
pendown()
pencolor("white")
begin_fill()
circle(15)
end_fill()

penup()
goto(0, 35)
pendown()
pencolor("black")
fillcolor("black")
begin_fill()
circle(15)
end_fill()

# 八卦图
pencolor("red")
pensize(8)

length = 80
r_list = [160, 180, 200]
line_lists = [[0, 1, 0, 0, 1, 1, 0, 1],
              [1, 1, 0, 0, 0, 1, 1, 0],
              [0, 1, 1, 0, 1, 0, 1, 0]]
for r, line_list in zip(r_list, line_lists):
    penup()
    goto(0, 0)
    seth(112.5)
    forward(r)
    seth(0)
    pendown()
    side = math.sin(math.radians(22.5))*r*2
    for type in line_list:
        penup()
        forward((side-length)/2)
        pendown()
        if type is 0:
            forward(length)
        else:
            forward(length*0.375)
            penup()
            forward(length*0.25)
            pendown()
            forward(length*0.375)
        penup()
        forward((side-length)/2)
        pendown()
        right(45)

 

  • 3
    点赞
  • 33
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值