python画八卦图
生活随笔
收集整理的這篇文章主要介紹了
python画八卦图
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
畫八卦圖,需要思路和計算
可以用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()?
總結
以上是生活随笔為你收集整理的python画八卦图的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: OSB集群故障2
- 下一篇: 请仅用一笔画四根直线,将下图9各点全部连