Python小熊猫(完整代码)

95 篇文章 119 订阅 ¥29.90 ¥99.00
这篇博客介绍了Python面向对象编程的实验,包括向量类的实现,增加了内积功能,并设计了自定义栈类模拟栈的操作。此外,还实现了一个双端队列,具备入队、出队、判断队列状态以及调整队列大小等功能。实验旨在掌握类的定义、数据成员与成员方法、继承以及特殊方法的用法。
摘要由CSDN通过智能技术生成

目录

写在前面

完整代码

下载代码

代码分析

系列文章

写在后面


写在前面

用Python画一只可爱的小熊猫,期待你的支持~

完整代码

import turtle

# 设置初始画布和画笔
t = turtle.Turtle()
t.screen.delay(0)
turtle.setup(width=1.0, height=1.0)
turtle.bgcolor('white')
turtle.title("小熊猫")
t.speed(0)
t.rt(-120)
t.up()
t.pensize(6)
t.goto(180, 150)
t.down()
t.color('black')
# 头轮廓
t.circle(190, 100)
t.fd(20)
for i in range(260):
    t.fd(1)
    t.lt(0.5)
for i in range(8):
    t.fd(19)
    t.lt(1)
for i in range(260):
    t.fd(1)
    t.lt(0.5)
t.up
import turtle # 设置绘制窗口的大小和背景颜色 turtle.setup(800, 600) turtle.bgcolor("white") # 定义画笔颜色函数 def set_color(color1, color2): turtle.pencolor(color1) turtle.fillcolor(color2) # 绘制熊猫的头部 def draw_head(): turtle.penup() turtle.goto(0, -200) turtle.pendown() turtle.setheading(45) set_color("black", "white") turtle.begin_fill() turtle.circle(200, steps=4) turtle.end_fill() # 绘制熊猫的耳朵 def draw_ears(): turtle.penup() turtle.goto(0, 0) turtle.pendown() turtle.setheading(45) set_color("black", "black") turtle.begin_fill() turtle.circle(60, steps=4) turtle.end_fill() turtle.penup() turtle.goto(0, 0) turtle.pendown() turtle.setheading(135) turtle.begin_fill() turtle.circle(60, steps=4) turtle.end_fill() # 绘制熊猫的眼睛 def draw_eyes(): turtle.penup() turtle.goto(-50, 50) turtle.pendown() set_color("black", "black") turtle.begin_fill() turtle.circle(30) turtle.end_fill() turtle.penup() turtle.goto(50, 50) turtle.pendown() set_color("black", "black") turtle.begin_fill() turtle.circle(30) turtle.end_fill() # 绘制熊猫的鼻子 def draw_nose(): turtle.penup() turtle.goto(0, -20) turtle.pendown() set_color("black", "black") turtle.begin_fill() turtle.circle(20) turtle.end_fill() # 绘制熊猫的嘴巴 def draw_mouth(): turtle.penup() turtle.goto(-50, -60) turtle.pendown() set_color("black", "black") turtle.right(90) turtle.circle(50, 180) # 绘制熊猫的身体 def draw_body(): turtle.penup() turtle.goto(0, -200) turtle.pendown() set_color("black", "white") turtle.begin_fill() turtle.circle(200) turtle.end_fill() # 绘制熊猫的手 def draw_hands(): turtle.penup() turtle.goto(100, -250) turtle.pendown() set_color("black", "white") turtle.setheading(-30) turtle.begin_fill() turtle.circle(80, 120) turtle.left(60) turtle.circle(80, 120) turtle.end_fill() # 绘制熊猫的脚 def draw_feet(): turtle.penup() turtle.goto(-100, -250) turtle.pendown() set_color("black", "white") turtle.setheading(-150) turtle.begin_fill() turtle.circle(80, 120) turtle.left(60) turtle.circle(80, 120) turtle.end_fill() # 调用各个函数绘制熊猫 draw_head() draw_ears() draw_eyes() draw_nose() draw_mouth() draw_body() draw_hands() draw_feet() # 隐藏画笔 turtle.hideturtle() #
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Want595

感谢小伙伴的支持!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值