用python哆啦a梦的代码_使用Python的Turtle绘制哆啦A梦实例

这是我几年前为了练习python的turtle库而画的,今天翻出了代码,分享给大家。

这是我初学python时画的,当时还没有面向对象的概念,也没有采取类方法之类,纯原始手工,供大家参考。

若有兴趣可以自行优化简洁代码,有时间我也会重新写一遍。

画出来的效果如下图:

20191121104729.jpg

代码如下:

# * -- utf-8 -- *

# Author: Tang

import turtle as t

t.speed(10)

t.pensize(8)

t.hideturtle()

t.screensize(500, 500, bg='white')

# 猫脸

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.en

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,下面是利用Pythonturtle模块绘制哆啦A梦代码: ```python import turtle # 设置turtle窗口的大小和背景颜色 turtle.setup(800, 600) turtle.bgcolor('white') # 绘制哆啦A梦的头部 turtle.pensize(3) turtle.color('blue', 'lightblue') turtle.begin_fill() turtle.circle(120) turtle.end_fill() # 绘制哆啦A梦的耳朵 turtle.penup() turtle.goto(-80, 80) turtle.pendown() turtle.color('blue', 'white') turtle.begin_fill() turtle.circle(40) turtle.end_fill() turtle.penup() turtle.goto(80, 80) turtle.pendown() turtle.color('blue', 'white') turtle.begin_fill() turtle.circle(40) turtle.end_fill() # 绘制哆啦A梦的眼睛 turtle.penup() turtle.goto(-50, 20) turtle.pendown() turtle.color('black', 'white') turtle.begin_fill() turtle.circle(20) turtle.end_fill() turtle.penup() turtle.goto(50, 20) turtle.pendown() turtle.color('black', 'white') turtle.begin_fill() turtle.circle(20) turtle.end_fill() turtle.penup() turtle.goto(-50, 30) turtle.pendown() turtle.color('black', 'black') turtle.begin_fill() turtle.circle(10) turtle.end_fill() turtle.penup() turtle.goto(50, 30) turtle.pendown() turtle.color('black', 'black') turtle.begin_fill() turtle.circle(10) turtle.end_fill() # 绘制哆啦A梦的鼻子 turtle.penup() turtle.goto(0, 0) turtle.pendown() turtle.color('black', 'pink') turtle.begin_fill() turtle.circle(15) turtle.end_fill() # 绘制哆啦A梦的嘴巴 turtle.penup() turtle.goto(-50, -40) turtle.pendown() turtle.color('red', 'red') turtle.begin_fill() turtle.circle(30, 180) turtle.end_fill() # 绘制哆啦A梦的身体 turtle.penup() turtle.goto(-170, -120) turtle.pendown() turtle.color('blue', 'lightblue') turtle.begin_fill() turtle.forward(340) turtle.circle(100, 180) turtle.forward(340) turtle.end_fill() # 绘制哆啦A梦的手和脚 turtle.penup() turtle.goto(-130, -160) turtle.pendown() turtle.color('blue', 'white') turtle.begin_fill() turtle.circle(30) turtle.end_fill() turtle.penup() turtle.goto(130, -160) turtle.pendown() turtle.color('blue', 'white') turtle.begin_fill() turtle.circle(30) turtle.end_fill() turtle.penup() turtle.goto(-150, -270) turtle.pendown() turtle.color('blue', 'white') turtle.begin_fill() turtle.circle(30) turtle.end_fill() turtle.penup() turtle.goto(150, -270) turtle.pendown() turtle.color('blue', 'white') turtle.begin_fill() turtle.circle(30) turtle.end_fill() # 绘制哆啦A梦的口袋 turtle.penup() turtle.goto(-80, -120) turtle.pendown() turtle.color('black', 'white') turtle.begin_fill() turtle.circle(60) turtle.end_fill() # 绘制哆啦A梦的口袋口 turtle.penup() turtle.goto(-60, -130) turtle.pendown() turtle.color('red', 'red') turtle.begin_fill() turtle.circle(25, 180) turtle.end_fill() # 绘制哆啦A梦的铃铛 turtle.penup() turtle.goto(-60, -200) turtle.pendown() turtle.color('yellow', 'yellow') turtle.begin_fill() turtle.circle(20) turtle.end_fill() turtle.penup() turtle.goto(-80, -240) turtle.pendown() turtle.color('black', 'black') turtle.begin_fill() turtle.circle(5) turtle.end_fill() turtle.penup() turtle.goto(-40, -240) turtle.pendown() turtle.color('black', 'black') turtle.begin_fill() turtle.circle(5) turtle.end_fill() # 隐藏turtle画笔 turtle.hideturtle() # 点击关闭turtle窗口 turtle.done() ``` 运行上述代码,即可在turtle窗口中看到绘制哆啦A梦
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值