1. 程式人生 > 其它 >基於python的turtle模組畫國旗

基於python的turtle模組畫國旗

基於python的turtle模組畫國旗,願祖國早日戰勝病毒,武漢加油,中國加油!

基於python的turtle模組畫國旗,願祖國早日戰勝病毒

  • 畫國旗是很嚴肅的問題,一定要按照規定去畫
  • 國旗寬高比為:3:2
  • 國旗標準圖
  • 繪製五角星需要嚴格的計算
  • 科學計算器網站:http://www.ab126.com/
  • 知道三角函式值求角度方法,使用excel =ASIN(A1)*180/PI()
import turtle

# 設定畫筆速度和畫布大小和位置
turtle.speed(10)
turtle.setup(650, 450)
# 畫國旗大背景
# 移動畫筆需要先把筆抬起來
turtle.up()
turtle.goto(-300, 200)
turtle.down()
turtle.begin_fill()
turtle.fillcolor("red")
turtle.pencolor("red")
# 畫出邊界
for i in range(2):
    turtle.forward(600)
    turtle.right(90)
    turtle.forward(400)
    turtle.right(90)
# 填充國旗顏色
turtle.end_fill()

# 畫大五角星
turtle.up()
turtle.goto(-200, 160)
turtle.seth(-72)
turtle.down()
turtle.begin_fill()
turtle.fillcolor("yellow")
turtle.pencolor("yellow")
for x in range(5):
    turtle.forward(120)
    turtle.right(144)
turtle.end_fill()

# 畫第一個小五角星
turtle.up()
turtle.goto(-100 - 17.3145, 160 - 6.174)
turtle.seth(48.96347)
turtle.down()
turtle.begin_fill()
turtle.fillcolor("yellow")
turtle.pencolor("yellow")
for x in range(5):
    turtle.forward(38.0417418)
    turtle.right(144)
turtle.end_fill()

# 畫第二個小五角星
turtle.up()
turtle.goto(-60 - 19.7948663580, 120 - 2.857143)
turtle.seth(36.213211)
turtle.down()
turtle.begin_fill()
turtle.fillcolor("yellow")
turtle.pencolor("yellow")
for x in range(5):
    turtle.forward(38.0417418)
    turtle.right(144)
turtle.end_fill()

# 畫第三個小五角星
turtle.up()
turtle.goto(-60 - 19.5, 60 + 5.714285848)
turtle.seth(5)
turtle.down()
turtle.begin_fill()
turtle.fillcolor("yellow")
turtle.pencolor("yellow")
for x in range(5):
    turtle.forward(38.0417418)
    turtle.right(144)
turtle.end_fill()

# 畫第四個小五角星
turtle.up()
turtle.goto(-100 - 17.2, 20 + 15.99999)
turtle.seth(-35.1301)
turtle.down()
turtle.begin_fill()
turtle.fillcolor("yellow")
turtle.pencolor("yellow")
for x in range(5):
    turtle.forward(38.0417418)
    turtle.right(144)
turtle.end_fill()

# 寫文字
turtle.up()
turtle.goto(0, -100)
turtle.pencolor('violet')
turtle.write('武漢加油,中國加油!', move=True, align='center', font=('華文新魏', 30, 'normal'))

# 隱藏畫筆,繪畫完成
turtle.hideturtle()
turtle.done()

效果圖

版權宣告:本文為博主原創文章,轉載請附上博文連結!