turtle画图
刚开始画这个是学校里学python一开始就学的turtle画图,正好作业里也有要画一个卡通图,就画了这个,我一开始是在草稿本子上一点一点的去想他要转多少度角,然后goto_到哪个位置去画鼻子眼睛,要正转还是反转,还挺麻烦的。
首先的准备工作
定义一个goto_()函数,让goto的时候不会留下痕迹,比较方便
def goto_(x, y):
pu()
goto(x, y)
pd(
##画头
def head():
goto_(100, 0)
fillcolor(“blue”)
begin_fill()
lt(45)
circle(150, 270)
lt(45)
fd(15)
lt(135)
circle(-128.78, 270)
lt(135)
fd(15)
end_fill()
fillcolor(“red”)
begin_fill()
circle(-9, 180)
fd(212)
circle(-9, 180)
fd(212)
end_fill()
##画眼睛
def eye():
fillcolor(“white”)
begin_fill()
goto_(0, 219.82746)
lt(90)
circle(25,180)
fd(25)
circle(25, 180)
fd(25)
goto_(0, 219.82746)
circle(-25, 180)
fd(25)
circle(-25, 180)
fd(25)
end_fill()
pensize(10)
goto_(-10, 194.82746)
circle(10, 180)
goto_(10, 194.82746)
rt(180)
circle(-10,180)
pensize(2)
##画鼻子和嘴巴
def nose_mouth():
fillcolor(“red”)
begin_fill()
goto_(0, 149.82746)
lt(90)
circle(15)
end_fill()
rt(90)
fd(130)
lt(90)
circle(100, 70)
goto_(0, 19.82746)
rt(250)
circle(-100, 70)
##画胡子
def beard():
lt(70)
goto_(-30, 83.79672)
lt(10)
fd(100)
goto_(-30, 83.79672+15.333)
rt(10)
fd(110)
goto_(-30, 83.79672+15.333+15.333)
rt(15)
fd(110)
rt(165)
goto_(30, 83.79672)
rt(10)
fd(100)
goto_(30, 83.79672+15.333)
lt(10)
fd(110)
goto_(30, 83.79672+15.333+15.333)
lt(15)
fd(110)
rt(15)
##画铃铛
def bell():
fillcolor(“gold”)
begin_fill()
goto_(0, -39)
circle(15)
end_fill()
##源码
from turtle import*
pensize(2)
def goto_(x, y):
pu()
goto(x, y)
pd()
def head():
goto_(100, 0)
fillcolor("blue")
begin_fill()
lt(45)
circle(150, 270)
lt(45)
fd(15)
lt(135)
circle(-128.78, 270)
lt(135)
fd(15)
end_fill()
fillcolor("red")
begin_fill()
circle(-9, 180)
fd(212)
circle(-9, 180)
fd(212)
end_fill()
def eye():
fillcolor("white")
begin_fill()
goto_(0, 219.82746)
lt(90)
circle(25,180)
fd(25)
circle(25, 180)
fd(25)
goto_(0, 219.82746)
circle(-25, 180)
fd(25)
circle(-25, 180)
fd(25)
end_fill()
pensize(10)
goto_(-10, 194.82746)
circle(10, 180)
goto_(10, 194.82746)
rt(180)
circle(-10,180)
pensize(2)
def nose_mouth():
fillcolor("red")
begin_fill()
goto_(0, 149.82746)
lt(90)
circle(15)
end_fill()
rt(90)
fd(130)
lt(90)
circle(100, 70)
goto_(0, 19.82746)
rt(250)
circle(-100, 70)
def beard():
lt(70)
goto_(-30, 83.79672)
lt(10)
fd(100)
goto_(-30, 83.79672+15.333)
rt(10)
fd(110)
goto_(-30, 83.79672+15.333+15.333)
rt(15)
fd(110)
rt(165)
goto_(30, 83.79672)
rt(10)
fd(100)
goto_(30, 83.79672+15.333)
lt(10)
fd(110)
goto_(30, 83.79672+15.333+15.333)
lt(15)
fd(110)
rt(15)
def bell():
fillcolor("gold")
begin_fill()
goto_(0, -39)
circle(15)
end_fill()
def main():
head()
eye()
nose_mouth()
beard()
bell()
hideturtle()
if __name__ == '__main__':
main()
done()
作者:Don 任