初学Python用Trutle画哆啦A梦

初学Python用Trutle画哆啦A梦

这是刚学Python第一次使用trutle画哆啦A梦,没有任何花里胡哨的东西,都是自己一笔一划调试出来的,所以大佬们可能看了会辣眼睛。可能结果和效果图有小小小小的区别,舌头不见了(青椒炒哆啦A梦舌头)。
效果图来自:(两个水印重叠了)
https://blog.csdn.net/qq_41564807/article/details/83796814

图片来自以上链接的作者
话不多说直接上代码

import turtle as t

#画两个圈圈 头
t.speed(10)
t.pensize(9)
t.fillcolor('#00A1E8')
t.begin_fill()
t.circle(160)
t.end_fill()

t.pensize(3)
t.fillcolor('#FFFFFF')
t.begin_fill()
t.circle(135)
t.end_fill()

#画项圈
t.pensize(17)
t.pencolor('#FF0000')
t.circle(180,35)

t.circle(180,-70)

t.penup()
t.goto(0, 0)
t.pendown()

#画铃铛
t.pensize(4)
t.color('#000000', '#FFD700')
t.begin_fill()
t.circle(-30)
t.end_fill()

#画铃铛里面的线条
t.penup()
t.goto(-15, -55)
t.pendown()

t.goto(-15, -40)
t.fillcolor('#808080')
t.begin_fill()
t.circle(8)
t.end_fill()

#画嘴巴
t.penup()
t.goto(-80, 80)
t.pendown()
t.seth(300)

t.fillcolor('#FF0000')
t.begin_fill()
t.circle(90, 120)
t.end_fill()

t.penup()
t.seth(0)
t.fd(10)
t.pendown()

t.pensize(7)
t.bk(180)

#画鼻子
t.pensize(5)
t.penup()
t.seth(90)
t.goto(0, 110)
t.pendown()

t.fd(55)
t.seth(0)
t.fillcolor('#FF0000')
t.begin_fill()
t.circle(20)
t.end_fill()

#画胡须
t.pensize(3)
t.penup()
t.seth(270)
t.fd(45)
t.seth(0)
t.fd(90)
t.pendown()

t.bk(180)

t.penup()
t.goto(0, 130)
t.seth(10)
t.pendown()

t.fd(95)

t.penup()
t.goto(0, 130)
t.seth(170)
t.pendown()

t.fd(95)

t.penup()
t.goto(0, 150)
t.seth(10)
t.pendown()

t.fd(95)

t.penup()
t.goto(0, 150)
t.seth(170)
t.pendown()

t.fd(95)


#画眼睛

#左眼
t.penup()
t.goto(-50, 200)
t.seth(90)
t.pendown()



t.fillcolor('#FFFFFF')
t.begin_fill()
t.pendown()
t.setheading(0)
len = 1
for k in range(2):         
    for j in range(60):
        if j < 30:
            len += 0.06
        else:
            len -= 0.06
        t.forward(len)
        t.left(3)
        
t.end_fill()

#右眼
t.penup()
t.goto(50, 200)
t.seth(90)
t.pendown()



t.fillcolor('#FFFFFF')
t.begin_fill()
t.pendown()
t.setheading(0)
len = 1
for k in range(2):         
    for j in range(60):
        if j < 30:
            len += 0.06
        else:
            len -= 0.06
        t.forward(len)
        t.left(3)
        
t.end_fill()


#画右眼珠子
t.penup()
t.goto(26, 240)
t.seth(270)
t.pendown()

t.fillcolor('#000000')
t.begin_fill()
t.circle(17)
t.end_fill()

t.fillcolor('#FFFFFF')
t.begin_fill()
t.circle(10)
t.end_fill()

#画左眼珠子
t.penup()
t.goto(-32, 233)
t.seth(145)
t.pendown()

t.pensize(10)
t.fd(17)
t.seth(225)
t.fd(17)

画椭圆那部分代码(眼睛)

修改椭圆大小可以修改循环里面的 len变化的值(两个值应该相同)
修改角度则修改 setheading(0)

这部分trutle绘画椭圆参考以下博主
https://segmentfault.com/a/1190000017873112?utm_source=tag-newest

import turtle as t

t.pendown()
t.setheading(0)
len = 1
t.fillcolor('#000000')
t.begin_fill()
for k in range(2):         
    for j in range(60):
        if j < 30:
            len += 0.05
        else:
            len -= 0.05
        t.forward(len)
        t.left(3)

t.end_fill()
t.penup()
t.done()

转载请注明出处

猜你喜欢

转载自blog.csdn.net/d875708765/article/details/104968454