用Python Turtle 画可爱的熊猫

本文通过Python的Turtle库详细介绍了如何一步步绘制出一只可爱的熊猫,适合初学者学习Python图形编程。
摘要由CSDN通过智能技术生成

用Python画一只可爱的熊猫(附带源码)
在这里插入图片描述

import turtle as t

t.setup(width=1450, height=1450, startx=0, starty=0)
t.speed(0)
t.rt(-120)
t.up()
t.pensize(6)
t.goto(180, 150)
t.bgcolor('white')
t.title("My Panda")
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()
t.goto(-70, -16)
t.setheading(245)
t.down()
for i in range(35):
    t.fd(1.5)
    t.lt(0.5)
for i in range(5):
    t.fd(1.5)
    t.lt(0.0125)
for i in range(9):
    t.fd(0.75)
    t.lt(1.5)
for i in range(22):
    t.fd(1)
    t.lt(0.3)
for i in range(20):
    t.fd(1)
    t.lt(3)
for i in range(180):
    t.fd(1)
    t.lt(0.20)
for i in range(20):
    t.fd(1)
    t.lt(3)
for i in range(22):
    t.fd(1)
    t.lt(0.3)
for i in range(9):
    t.fd(0.75)
    t.lt(1.5)
for i in range(5):
    t.fd(1.5)
    t.lt(0.0125)
for i in range(25):
    t.fd(1.5)
    t.lt(0.5)
t.up()
t.goto
好的,可以使用Python中的turtle模块来小动物。下面是熊猫和小鸟的示例代码: 熊猫: ```python import turtle # 设置笔 t = turtle.Turtle() t.pensize(3) t.speed(10) t.color("black") # 身体 t.penup() t.goto(0,-100) t.pendown() t.begin_fill() t.circle(100) t.end_fill() # 耳朵 t.penup() t.goto(-50,80) t.pendown() t.begin_fill() t.circle(30) t.end_fill() t.penup() t.goto(50,80) t.pendown() t.begin_fill() t.circle(30) t.end_fill() # 眼睛 t.penup() t.goto(-30,30) t.pendown() t.color("white") t.begin_fill() t.circle(20) t.end_fill() t.color("black") t.begin_fill() t.circle(10) t.end_fill() t.penup() t.goto(30,30) t.pendown() t.color("white") t.begin_fill() t.circle(20) t.end_fill() t.color("black") t.begin_fill() t.circle(10) t.end_fill() # 鼻子 t.penup() t.goto(0,10) t.pendown() t.color("black") t.begin_fill() t.circle(15) t.end_fill() # 嘴巴 t.penup() t.goto(0,-20) t.pendown() t.right(45) t.circle(30,90) t.penup() t.goto(0,-20) t.pendown() t.left(90) t.circle(-30,90) # 完成 turtle.done() ``` 小鸟: ```python import turtle # 设置笔 t = turtle.Turtle() t.pensize(3) t.speed(10) t.color("black") # 身体 t.penup() t.goto(-50,0) t.pendown() t.begin_fill() t.circle(30) t.end_fill() # 翅膀 t.penup() t.goto(-20,0) t.pendown() t.begin_fill() t.right(45) t.forward(30) t.right(135) t.forward(30) t.right(45) t.forward(20) t.end_fill() t.penup() t.goto(-20,0) t.pendown() t.begin_fill() t.left(90) t.right(45) t.forward(30) t.right(135) t.forward(30) t.right(45) t.forward(20) t.end_fill() # 头 t.penup() t.goto(20,35) t.pendown() t.begin_fill() t.circle(20) t.end_fill() # 眼睛 t.penup() t.goto(10,50) t.pendown() t.color("white") t.begin_fill() t.circle(7) t.end_fill() t.color("black") t.begin_fill() t.circle(3) t.end_fill() t.penup() t.goto(30,50) t.pendown() t.color("white") t.begin_fill() t.circle(7) t.end_fill() t.color("black") t.begin_fill() t.circle(3) t.end_fill() # 嘴巴 t.penup() t.goto(30,35) t.pendown() t.color("orange") t.begin_fill() t.right(45) t.circle(10,90) t.right(135) t.circle(10,90) t.end_fill() # 完成 turtle.done() ``` 你可以根据自己的需求和创意来修改代码,出更多可爱的小动物。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值