用python画哆啦a梦的身体_用Python画一个哆啦A梦

39a0558f-cd01-4fbe-83f7-f6009d2f97ca

Python自带的turtle海龟绘图库功能十分强大,使用起来也很简单方便,今天我们就使用海龟绘图画一个我们都很喜欢的卡通形象-哆啦A梦头像。我们将整个头像分为几个部分分别定义相关的绘制函数,下面分别来看下:

头(head)

#头

def head():

t.pensize(8)

t.fillcolor("#00A1E8")

t.begin_fill()

t.circle(120)

t.end_fill()

fef79ea3-fbef-41bf-88d6-1bc59d9420e2

head函数效果

脸(face)

def face():

t.pensize(3)

t.fillcolor("white")

t.begin_fill()

t.circle(100)

t.end_fill()

779d4ac205dc4b81aa66e1b0c2902eb2

face函数效果

鼻子(nose)

def nose():

t.penup()

t.home()

t.goto(0, 134)

t.pendown()

t.pensize(4)

t.fillcolor("#EA0014")

t.begin_fill()

t.circle(18)

t.end_fill()

#鼻子上的白点

t.penup()

t.goto(7, 155)

t.pensize(2)

t.color("white", "white")

t.pendown()

t.begin_fill()

t.circle(4)

t.end_fill()

145bd32bbc6447449e75014603802b37

nose函数效果

眼睛(eyes)

#眼睛

def eye(x, y):

t.penup()

t.goto(x, y)

t.setheading(0)

t.pensize(4)

t.pendown()

t.color("black", "white")

t.begin_fill()

a = 0.4

for i in range(120):

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

a = a+0.08

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

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

else:

a = a-0.08

t.left(3)

t.forward(a)

t.end_fill()

#绘制眼睛

def eyes(x, y, style=0):

eye(x, y)

if style==0: #眨眼样式

t.penup()

t.goto(-38,190)

t.pensize(8)

t.pendown()

t.right(-30)

t.forward(15)

t.right(70)

t.forward(15)

else:

#眼珠

t.penup()

t.goto(23, 185)

t.pensize(4)

t.pendown()

t.color("black", "black")

t.begin_fill()

t.circle(13)

t.end_fill()

#眼白

t.pu()

t.goto(17, 190)

t.pensize(2)

t.pd()

t.color("white", "white")

t.begin_fill()

t.circle(5)

t.end_fill()

bc879b19110b4d4681d1829aea149190

eyes函数效果

胡子(whiskers)

#胡子

def whiskers(iscenter, x=0, y=0, f=0, h=0):

#中间胡子

if iscenter==1:

t.penup()

t.home()

t.goto(0, 134)

t.pensize(4)

t.pencolor('black')

t.pendown()

t.right(90)

t.forward(40)

else:

t.penup()

t.home()

t.setheading(h)

t.goto(x, y)

t.pensize(3)

t.pencolor("black")

t.pendown()

t.forward(f)

6e9e855388ba4f9f870918037caf7d86

whiskers函数效果

嘴(mouth)

#嘴

def mouth():

t.penup()

t.goto(-70, 70)

t.pendown()

t.color("black", "red")

t.pensize(6)

t.setheading(-60)

t.begin_fill()

t.circle(80, 40)

t.circle(80, 80)

t.end_fill()

t.penup()

t.home()

t.goto(-80,70)

t.pendown()

t.forward(160)

#舌头

t.penup()

t.home()

t.goto(-50,50)

t.pendown()

t.pensize(1)

t.fillcolor("#eb6e1a")

t.setheading(40)

t.begin_fill()

t.circle(-40, 40)

t.circle(-40, 40)

t.setheading(40)

t.circle(-40, 40)

t.circle(-40, 40)

t.setheading(220)

t.circle(-80, 40)

t.circle(-80, 40)

t.end_fill()

3b59d41423fb4658a7a87f87a600751d

mouth函数效果

项圈(collar)

#项圈

def collar():

t.penup()

t.goto(-70, 12)

t.pensize(14)

t.pencolor("red")

t.pendown()

t.setheading(-20)

t.circle(200, 40)

47d4f54af2aa43e495ac046cb8042f70

collar函数效果

铃铛(bell)

#铃铛

def bell():

t.penup()

t.goto(0, -46)

t.pendown()

t.pensize(3)

t.color("black", "#f8d102")

t.begin_fill()

t.circle(25)

t.end_fill()

t.penup()

t.goto(-5, -40)

t.pendown()

t.pensize(2)

t.color("black", "#79675d")

t.begin_fill()

t.circle(5)

t.end_fill()

t.pensize(3)

t.right(115)

t.forward(7)

调用各函数

t.speed(10) #画笔速度为10

t.hideturtle() #隐藏画笔

head() #头

face() #脸

nose() #鼻子

eyes(-30, 160) #左眼

eyes(30, 160, 1) #右眼

whiskers(1) #中间胡子

#右边胡子

whiskers(0, 0, 124, 80, 10)

whiskers(0, 0, 114, 90, 0)

whiskers(0, 0, 104, 80, -10)

#左边胡子

whiskers(0, 0, 124, 80, 170)

whiskers(0, 0, 114, 90, 180)

whiskers(0, 0, 104, 80, -170)

mouth() #嘴

collar() #项圈

bell() #铃铛

最终效果如下

2a7a89c65f1748d1bdeb4efb080124dc

最终效果

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,下面是用Python哆啦A梦的代码: ``` # -*- coding:utf-8 -*- import turtle # 定义一个函数,用于哆啦A梦的头部 def draw_head(): turtle.color('blue','lightblue') turtle.penup() turtle.goto(0, 120) turtle.pendown() turtle.setheading(-45) turtle.begin_fill() for i in range(2): turtle.forward(150) turtle.circle(-50, 90) turtle.forward(150) turtle.circle(-50, 90) turtle.end_fill() turtle.penup() turtle.goto(-30, 20) turtle.pendown() turtle.setheading(0) turtle.begin_fill() turtle.circle(30) turtle.end_fill() turtle.penup() turtle.goto(30, 20) turtle.pendown() turtle.begin_fill() turtle.circle(30) turtle.end_fill() turtle.color('white') turtle.penup() turtle.goto(-20, 38) turtle.pendown() turtle.begin_fill() turtle.circle(10) turtle.end_fill() turtle.penup() turtle.goto(20, 38) turtle.pendown() turtle.begin_fill() turtle.circle(10) turtle.end_fill() turtle.color('black') turtle.penup() turtle.goto(-20, 50) turtle.pendown() turtle.dot(5) turtle.penup() turtle.goto(20, 50) turtle.pendown() turtle.dot(5) # 定义一个函数,用于哆啦A梦身体 def draw_body(): turtle.color('blue','lightblue') turtle.penup() turtle.goto(0, 0) turtle.pendown() turtle.setheading(-180) turtle.begin_fill() turtle.circle(70, -180) turtle.circle(200, -60) turtle.circle(70, -180) turtle.end_fill() turtle.penup() turtle.goto(-140, -120) turtle.pendown() turtle.begin_fill() turtle.circle(50) turtle.end_fill() turtle.penup() turtle.goto(140, -120) turtle.pendown() turtle.begin_fill() turtle.circle(50) turtle.end_fill() turtle.color('white') turtle.penup() turtle.goto(-95, -60) turtle.pendown() turtle.begin_fill() turtle.circle(15) turtle.end_fill() turtle.penup() turtle.goto(95, -60) turtle.pendown() turtle.begin_fill() turtle.circle(15) turtle.end_fill() turtle.color('black') turtle.penup() turtle.goto(-95, -60) turtle.pendown() turtle.dot(5) turtle.penup() turtle.goto(95, -60) turtle.pendown() turtle.dot(5) # 定义一个函数,用于哆啦A梦的胳膊 def draw_arm(): turtle.color('blue','lightblue') turtle.penup() turtle.goto(-210, -70) turtle.pendown() turtle.begin_fill() turtle.circle(30, 150) turtle.forward(40) turtle.circle(10, 180) turtle.forward(40) turtle.circle(30, 150) turtle.forward(60) turtle.end_fill() turtle.penup() turtle.goto(210, -70) turtle.pendown() turtle.begin_fill() turtle.circle(-30, -150) turtle.forward(40) turtle.circle(-10, -180) turtle.forward(40) turtle.circle(-30, -150) turtle.forward(60) turtle.end_fill() # 定义一个函数,用于哆啦A梦的腿 def draw_leg(): turtle.color('blue','lightblue') turtle.penup() turtle.goto(-80, -300) turtle.pendown() turtle.begin_fill() turtle.circle(30) turtle.end_fill() turtle.penup() turtle.goto(80, -300) turtle.pendown() turtle.begin_fill() turtle.circle(-30) turtle.end_fill() # 设置布和笔属性 turtle.setup(800, 600) turtle.hideturtle() turtle.speed(10) turtle.tracer(False) # 哆啦A梦的头部 draw_head() # 哆啦A梦身体 draw_body() # 哆啦A梦的胳膊 draw_arm() # 哆啦A梦的腿 draw_leg() turtle.done() ``` 希望能够帮到你!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值