python绘画之哆啦A梦

本文通过Python的turtle库绘制了哆啦A梦的形象,包括脸部、眼睛、鼻子、胡须等特征,并添加了领带和铃铛等装饰。通过调整线条粗细和颜色填充实现了细致的描绘。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

import turtle as t
# 脸
t.fillcolor('#00A1E8')
t.begin_fill()
t.circle(120)
t.end_fill()
 
t.pensize(3)
t.fillcolor('white')
t.begin_fill()
t.circle(100)
t.end_fill()
 
t.pu()
t.home()
t.goto(0, 134)
t.pd()
t.pensize(4)
t.fillcolor("#EA0014")
t.begin_fill()
t.circle(18)
t.end_fill()
 
t.pu()
t.goto(7, 155)
t.pensize(2)
t.color('white', 'white')
t.pd()
t.begin_fill()
t.circle(4)
t.end_fill()
 
t.pu()
t.goto(-30, 160)
t.pensize(4)
t.pd()
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.lt(3)
        t.fd(a)
    else:
        a = a-0.08
        t.lt(3)
        t.fd(a)
t.end_fill()
 
t.pu()
t.goto(30, 160)
t.pensize(4)
t.pd()
t.color('black', 'white')
t.begin_fill()
for i in range(120):
    if 0 <= i < 30 or 60 <= i < 90:
        a = a+0.08
        t.lt(3)
        t.fd(a)
    else:
        a = a-0.08
        t.lt(3)
        t.fd(a)
t.end_fill()
 
t.pu()
t.goto(-38,190)
t.pensize(8)
t.pd()
t.right(-30)
t.forward(15)
t.right(70)
t.forward(15)
 
t.pu()
t.goto(15, 185)
t.pensize(4)
t.pd()
t.color('black', 'black')
t.begin_fill()
t.circle(13)
t.end_fill()
 
t.pu()
t.goto(13, 190)
t.pensize(2)
t.pd()
t.color('white', 'white')
t.begin_fill()
t.circle(5)
t.end_fill()
 
t.pu()
t.home()
t.goto(0, 134)
t.pensize(4)
t.pencolor('black')
t.pd()
t.right(90)
t.forward(40)
 
t.pu()
t.home()
t.goto(0, 124)
t.pensize(3)
t.pencolor('black')
t.pd()
t.left(10)
t.forward(80)
 
t.pu()
t.home()
t.goto(0, 114)
t.pensize(3)
t.pencolor('black')
t.pd()
t.left(6)
t.forward(80)
 
t.pu()
t.home()
t.goto(0,104)
t.pensize(3)
t.pencolor('black')
t.pd()
t.left(0)
t.forward(80)
 
# 胡子
t.pu()
t.home()
t.goto(0,124)
t.pensize(3)
t.pencolor('black')
t.pd()
t.left(170)
t.forward(80)
 
t.pu()
t.home()
t.goto(0, 114)
t.pensize(3)
t.pencolor('black')
t.pd()
t.left(174)
t.forward(80)
 
t.pu()
t.home()
t.goto(0, 104)
t.pensize(3)
t.pencolor('black')
t.pd()
t.left(180)
t.forward(80)
 
t.pu()
t.goto(-70, 70)
t.pd()
t.color('black', 'red')
t.pensize(6)
t.seth(-60)
t.begin_fill()
t.circle(80,40)
t.circle(80,80)
t.end_fill()
 
t.pu()
t.home()
t.goto(-80,70)
t.pd()
t.forward(160)
 
t.pu()
t.home()
t.goto(-50,50)
t.pd()
t.pensize(1)
t.fillcolor("#eb6e1a")
t.seth(40)
t.begin_fill()
t.circle(-40, 40)
t.circle(-40, 40)
t.seth(40)
t.circle(-40, 40)
t.circle(-40, 40)
t.seth(220)
t.circle(-80, 40)
t.circle(-80, 40)
t.end_fill()
 
# 领带
t.pu()
t.goto(-70, 12)
t.pensize(14)
t.pencolor('red')
t.pd()
t.seth(-20)
t.circle(200, 30)
t.circle(200, 10)
 
# 铃铛
t.pu()
t.goto(0, -46)
t.pd()
t.pensize(3)
t.color("black", '#f8d102')
t.begin_fill()
t.circle(25)
t.end_fill()
 
 
t.pu()
t.goto(-5, -40)
t.pd()
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.mainloop()

哆啦A梦

Python中绘制一个简单的啦A图案通常需要结合PIL(Python Imaging Library)或其后续版本Pillow库。啦A的脸部特征包括大大的眼睛、鼻子、嘴巴以及耳朵和身体轮廓。下面是一个简化的示例,展示如何使用矩形和圆形来创建基本形状: ```python from PIL import Image, ImageDraw # 创建一个新的图像背景 image = Image.new('RGB', (200, 200), color='white') draw = ImageDraw.Draw(image) # 定义啦A头部和身体的基本形状 eye_radius = 15 mouth_width = 40 body_height = image.height // 2 # 绘制眼睛 left_eye_x = image.width // 4 right_eye_x = image.width * 3 // 4 draw.ellipse((left_eye_x - eye_radius, image.height // 2 - eye_radius, left_eye_x + eye_radius, image.height // 2 + eye_radius), fill='black') draw.ellipse((right_eye_x - eye_radius, image.height // 2 - eye_radius, right_eye_x + eye_radius, image.height // 2 + eye_radius), fill='black') # 绘制鼻子 nose_x = (left_eye_x + right_eye_x) // 2 - 5 nose_y = image.height // 2 - 10 nose_size = 15 draw.rectangle([(nose_x - nose_size, nose_y - nose_size), (nose_x + nose_size, nose_y + nose_size)], fill='yellow') # 绘制嘴 mouth_left_x = nose_x - mouth_width // 2 mouth_right_x = nose_x + mouth_width // 2 mouth_top_y = image.height // 2 + 10 mouth_height = 20 draw.polygon([(mouth_left_x, mouth_top_y), (mouth_left_x, mouth_top_y - mouth_height), (mouth_right_x, mouth_top_y - mouth_height)], fill='red') # 绘制身体 body_top_y = image.height // 4 body_bottom_y = image.height * 3 // 4 body_width = image.width * 2 / 3 draw.rectangle([(body_width // 2, body_top_y), (image.width - body_width // 2, body_bottom_y)], fill='blue') # 显示结果 image.show()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值