还在简单的写生日祝福吗?自从学了python,我们可以更高大上一点,利用python的海龟画图来“画”个生日祝福。
from turtle import *
lf=left
bd=backward
sh=setheading
def sheng(x,y):
pu()
goto(x,y)
pd()
width(10)
pencolor('purple')
left(45)
fd(45)
backward(22)
rt(135)
pu()
for i in range(3):
left(90)
pd()
forward(100)
backward(100)
pu()
rt(90)
if i!=2:
fd(35)
left(90)
pu()
fd(50)
lf(90)
fd(90)
lf(180)
pd()
fd(90)
pu()
setheading(0)
def ri(x,y):
width(10)
pu()
#goto(x,y)
pencolor('red')
for i in range(3):
goto(x,y-40*i)
pd()
fd(80)
rt(90)
fd((2-i)*40)
pu()
lt(90)
setheading(0)
goto(x,y)
pd()
rt(90)
fd(90)
pu()
setheading(0)
def kuai(x,y):
width(10)
pu()
goto(x,y)
pd()
pencolor('pink')
rt(90)
fd(26)
pu()
bd(30)
setheading(0)
goto(x+15,y+50)
pd()
rt(90)
fd(130)
pu()
setheading(0)
goto(x+31,y)
pd()
rt(90)
fd(32)
pu()
goto(x+55,y+10)
pd()
setheading(0)
fd(60)
rt(90)
fd(30)
pu()
goto(x+50,y-30)
setheading(0)
pd()
fd(77)
pu()
goto(x+85,y+30)
setheading(270)
pd()
fd(55)
circle(-110,35)
pu()
goto(x+85,y-25)
pd()
setheading(270)
circle(110,35)
pu()
setheading(0)
def le(x,y):
pencolor('yellow')
width(10)
pu()
goto(x,y)
pd()
circle(90,40)
pu()
goto(x,y)
setheading(270)
pd()
fd(40)
lt(90)
fd(70)
pu()
bd(31)
lf(90)
fd(36)
pd()
rt(180)
fd(99)
rt(152)
fd(21)
pu()
setheading(90)
fd(20)
setheading(180)
fd(10)
setheading(90)
lt(130)
pd()
fd(30)
pu()
bd(30)
setheading(0)
fd(40)
sh(90)
rt(130)
pd()
fd(30)
pu()
同时,画这些字的代码我写成了函数,这样需要写那个字时可以直接调用函数。还可以多写几个字,组成个字体库,在不同的人过生日,或不同的场景下,可以自由组合,既有心意,又轻松简单。