python 的turtle库画“武汉加油”+加油表情

完成了武汉加油【加油加油】表情


import turtle as t

import time

#由于会重复用到多次以下操作,故写成函数

def hua(a,b,c,d):#从(a,b)点画直线到(c,d)点

    t.goto(a,b)

    t.down()

    t.goto(c,d)

    t.up()

def heng(a,b,c):#从(a,b)点画横线到(c,d)点

    hua(a,b,c,b)

def shu(a,b,c):#从点(a,b)画竖线到(a,c)点

    hua(a,b,a,c)

#设置画布大小参数(宽,高,)

t.screensize(1100,600)

#设置画笔的速度

t.speed(5)

#设置画笔的大小

t.pensize(3)

#画框

t.up()

time.sleep(5)#设置五秒钟的暂停

heng(-500,100,500)

heng(-500,-100,500)

for i in (-500,-300,-100,100,300,500):

    shu(-i,100,-100)

#1.武

#短横

heng(-470,80,-400)

#长横

heng(-490,50,-320)

#竖

shu(-430,20,-55)

#短横

heng(-430,-10,-400)

#竖

shu(-460,-10,-60)

#提

hua(-480,-70,-400,-40)

#斜勾

t.goto(-390,90)

t.down()

t.setheading(90)#将笔旋转90度

t.circle(-280,-38)

t.right(45)#将笔向右转45度

t.forward(20)#将笔向前画20个单位

t.up()

#点

hua(-365,80,-345,60)

#2.汉

#点

hua(-280,70,-250,40)

#点

hua(-285,10,-250,0)

#提

hua(-285,-70,-245,-30)

#横撇

heng(-230,60,-130)

t.down()

t.setheading(90)#将笔旋转90度

t.circle(130,-85)#撇

t.up()

#捺

t.goto(-230,60)

t.down()

t.setheading(90)#将笔旋转90度

t.circle(-130,-85)#捺

t.up()

#3.加

#横折钩

heng(-80,35,10)

t.down()

t.setheading(90)#将笔旋转90度

t.circle(280,-25)#撇

t.left(90)

t.forward(30)

t.up()

#竖撇

t.goto(-40,90)

t.down()

t.setheading(90)#将笔旋转90度

t.circle(280,-35)#撇

t.up()

#竖

t.goto(20,35)

shu(15,35,-50)

#横折

t.goto(20,35)

heng(20,35,90)

shu(90,35,-50)

#横

t.goto(0,0)

t.home()

t.goto(20,-50)

heng(20,-50,90)

#4.油

#点

hua(120,70,150,40)

#点

hua(115,10,150,0)

#提

hua(115,-70,155,-30)

#竖

shu(160,20,-80)

#横折

heng(160,20,280)

shu(280,20,-80)

#横

heng(160,-30,280)

#竖

shu(220,75,-80)

#横

heng(160,-80,280)

#5.表情-加油

#头

t.goto(400,-100)

t.down()

t.circle(100,360)

t.up()

#眉毛

t.pensize(6)

hua(355,35,375,30)

hua(445,35,425,30)

t.pensize(3)

#眼睛

t.goto(360,0)

t.down()

a=0.25#设置基础步长,之后m每次步长增加,画出来的便是一个椭圆,如果要改变椭圆的大小,则可改变a的值

for i in range(120):#

    if 0<=i<30 or 60<=i<90:

        a=a+0.02

        t.lt(3) #向左转3度

        t.fd(a) #向前走a的步长

    else:

        a=a-0.02

        t.lt(3)

        t.fd(a)

t.up()

t.goto(440,0)

t.down()

a=0.25

for i in range(120):

    if 0<=i<30 or 60<=i<90:

        a=a+0.02

        t.lt(3) #向左转3度

        t.fd(a) #向前走a的步长

    else:

        a=a-0.02

        t.lt(3)

        t.fd(a)

t.up()

#头巾

t.pencolor('red')

t.pensize(15)

heng(328,70,470)

for i in range(10):#画头巾,用把笔变宽的方法产生头巾逐渐变宽的感觉

    t.pensize(10+i)

    hua(470+i,70+i,471+i,71+i)

#口罩

t.pencolor('black')

t.pensize(3)

t.fillcolor('black')

t.begin_fill()

shu(440,-10,-60)

shu(360,-10,-60)

heng(360,-60,440)

heng(360,-10,440)

t.end_fill()

#口罩绳

t.pensize(3)

t.fillcolor('black')

hua(300,0,360,-25)

hua(320,-60,360,-45)

hua(500,0,440,-25)

#手势,不是很好画手势,因此取巧用了很粗的笔,画了两条短线来代替手

t.pensize(30)

t.pencolor('brown')

shu(470,-50,-80)

t.pensize(50)

heng(460,-25,480)

#结束

t.done()

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容