前幾天想着用py畫一個校徽,找了好多方法,都說要用傅里葉,但是那個看着不簡單,就沒有去研究。就自己整了整,用了 點動成線這個原理畫了一下,沒想到還成了,只不過繞着半圓打圈的字沒有往上整,那個有點內容。
#1.引入模塊、定義函數
from turtle import *
#自定義向左拐的for循環函數
def forleft(x,y,z):
for i in range(x):
left(y)
fd(z)
#自定義向右拐的for循環函數
def forright(x,y,z):
for i in range(x):
right(y)
fd(z)
2.建立畫布
setup(600,600,350,35)
#3.畫左邊的字“禾”
def he():
begin_fill()
color("red")
pendown()
pencolor("red")
#speed(10)
forleft(1,125,8)
forleft(4,10,5)
forleft(1,15,26)
forright(2,90,28)
forleft(5,10,5)
#第二個拐
forleft(1,40,54)
forleft(13,12,2)
#拐圓彎
forleft(1,24,53)
forright(2,90,31)
forleft(8,10,6)
forleft(1,10,33)
forleft(13,12,2)
forleft(1,24,28)
forright(10,9,3)
fd(24)
forright(1,90,28)
forright(10,9,1)
fd(12)
forleft(15,12,2)
fd(21)
forleft(9,10,2)
fd(40)
forright(2,90,31)
fd(10)
forleft(9,10,2)
fd(80)
for i in range(2):
forleft(15,12,2)
fd(68)
for i in range(2):
forright(8,11,2)
fd(11.5)
right(2)
fd(60)
fd(-5)
forleft(15,12,2)
fd(78)
end_fill()
penup()
#4.畫右邊的字“口”
def kou():
goto(45,75)
pendown()
begin_fill()
color("red")
fd(35)
forleft(13,12,2)
#拐圓彎
forleft(1,24,53)
fd(125)
forleft(3,30,15)
fd(45)
forleft(3,30,15)
fd(160)
forleft(13,12,2)
forleft(1,24,35)
forright(1,90,65)
end_fill()
penup()
goto(45,55)
pendown()
begin_fill()
color('white')
forleft(1,90,115)
forleft(3,30,10)
fd(30)
forleft(3,30,10)
fd(107)
forleft(1,90,70)
end_fill()
penup()
#裏面那個圓
def innercircle():
goto(0,210)
pendown()
pensize(8)
pencolor('red')
circle(190)
penup()
# 外面那個圓
def excircle():
goto(0,260)
pendown()
pensize(4)
pencolor('red')
circle(235)
penup()
goto(0,273)
pendown()
pensize(15)
pencolor('red')
circle(249)
penup()
def main():
he()
kou()
innercircle()
excircle()
main()
done()
結果如下:
真正的校徽如下:
整體來看還是不錯的!這個編輯器我不怎麼會用,代碼可能會錯行,請諒解。