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)

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章