Python画一个HelloKitty

Python-turtle画出HelloKitty(有趣小游戏)

一、效果图

请添加图片描述

二、安装库

1.常用镜像源

1. 豆瓣http://pypi.douban.com/simple/
2. 清华大学:https://pypi.tuna.tsinghua.edu.cn/simple 
3. 清华大学开源镜像站 https://mirrors.tuna.tsinghua.edu.cn/ 
4. 网易开源镜像站  http://mirrors.163.com/
5. 阿里巴巴开源镜像站 https://opsx.alibaba.com/mirror/
6. 华为开源镜像站:mirrors.huaweicloud.com/
7. 华中理工大学http://pypi.hustunique.com/simple/

2.库下载

#基础语句
pip install turtle
# 使用镜像源快速下载
pip install xxx -i http://pypi.douban.com/simple/
#如果出现错误,加入--user进去
pip install --user xxx -i http://pypi.douban.com/simple/

三、Python代码

import math
import turtle as t


# 计算长度、角度 t1:画笔对象  r:半径  angle:扇形(圆形)的角度
def myarc(t1, r, angle):
    arc_length = 2 * math.pi * r * angle / 360  # angle角度的扇形的弧长
    n = int(arc_length / 3) + 1  # 线段条数
    step_length = arc_length / n  # 每条线段的长度
    step_angle = angle / n  # 每条线段的角度
    polyline(t1, n, step_length, step_angle)


# 画弧线 t1:画笔对象  n:线段条数  length:每条线段长度  angle:每条线段的角度
def polyline(t1, n, length, angle):
    for index in range(n):
        t1.fd(length)
        t1.lt(angle)


# 小花
def flower(n):
    for X in range(n):
        t.forward(0.5)
        if X < 80:
            t.left(1)
        elif X < 120:
            t.left(2.3)
        else:
            t.left(1)



# 画布
t.screensize(500, 500, "white")
t.pensize(8)
t.pencolor("black")
t.speed(0) # 设置绘图速度为10
# t.tracer(1)  # 开启动画
#直接出结果
# wn = t.Screen()
# wn.tracer(0)



# 头
t.penup()
t.goto(-130, 170)
t.pendown()
t.setheading(220)
for x in range(580):
    t.forward(1)
    if x < 250:
        t.left(0.5)
    elif x < 350:
        t.left(0.1)
    else:
        t.left(0.5)

# 耳朵
t.setheading(70)
for y in range(150):
    t.forward(1)
    if y < 80:
        t.left(0.2)
    elif y < 90:
        t.left(10)
    else:
        t.left(0.2)
t.setheading(160)
for y1 in range(140):
    t.forward(1)
    t.left(0.15)
t.setheading(140)
for y2 in range(157):
    t.forward(1)
    if y2 < 65:
        t.left(0.2)
    elif y2 < 75:
        t.left(8)
    else:
        t.left(0.5)

t.pensize(5)
# 左眼睛
t.penup()
t.goto(-100, 60)
t.setheading(350)
t.pendown()
t.fillcolor("#000")
t.begin_fill()
step = 0.3
for i in range(2):
    for j in range(60):
        if j < 30:
            step += 0.02
        else:
            step -= 0.02
        t.forward(step)
        t.left(3)
t.end_fill()
# 右眼睛
t.penup()
t.goto(50, 40)
t.setheading(350)
t.pendown()
t.fillcolor("#000")
t.begin_fill()
step = 0.3
for i in range(2):
    for j in range(60):
        if j < 30:
            step += 0.02
        else:
            step -= 0.02
        t.forward(step)
        t.left(3)
t.end_fill()
# 鼻子
t.penup()
t.goto(-40, 30)
t.setheading(260)
t.pendown()
t.fillcolor("#ebc80e")
t.begin_fill()
step = 0.3
for i in range(2):
    for j in range(60):
        if j < 30:
            step += 0.02
        else:
            step -= 0.02
        t.forward(step)
        t.left(3)
t.end_fill()

# 小花
t.penup()
t.goto(20, 180)
t.pendown()
t.fillcolor("#dd4a76")
t.begin_fill()
t.setheading(175)
flower(200)
t.setheading(250)
flower(200)
t.setheading(325)
flower(200)
t.setheading(40)
flower(200)
t.setheading(115)
flower(170)
t.end_fill()
t.penup()
t.goto(30, 180)
t.setheading(270)
t.pendown()
t.fillcolor("#e7be04")
t.begin_fill()
t.circle(10)
t.end_fill()
# 胡子
t.penup()
t.goto(-150, 65)
t.pendown()
t.setheading(170)
t.pensize(6)
for y in range(40):
    t.forward(1)
    t.left(0.3)

t.penup()
t.goto(-150, 85)
t.pendown()
t.setheading(160)
for y in range(50):
    t.forward(1)
    t.left(0.3)

t.penup()
t.goto(-150, 45)
t.pendown()
t.setheading(180)
for y in range(55):
    t.forward(1)
    t.left(0.3)

t.penup()
t.goto(110, 10)
t.setheading(340)
t.pendown()
for y in range(40):
    t.forward(1)
    t.right(0.3)
t.penup()
t.goto(120, 30)
t.setheading(350)
t.pendown()
for y in range(30):
    t.forward(1)
    t.right(0.3)
t.penup()
t.goto(115, 50)
t.setheading(360)
t.pendown()
for y in range(50):
    t.forward(1)
    t.right(0.3)

# 身子
t.pensize(8)
t.penup()
t.goto(-100, -30)
t.setheading(230)
t.pendown()
t.fillcolor("#efa9c1")
t.begin_fill()
for z in range(140):
    t.forward(1)
    t.left(0.2)
t.setheading(340)
for z in range(200):
    t.forward(1)
    t.left(0.1)
t.setheading(85)
for z in range(140):
    t.forward(1)
    t.left(0.1)
t.end_fill()
t.penup()
t.goto(-73, -33)
t.pendown()
t.setheading(250)
t.fillcolor("#da4b76")
t.begin_fill()
myarc(t, 40, 205)
t.setheading(170)
t.pensize(6)
t.forward(75)
t.end_fill()
# 左胳膊
t.pensize(8)
t.penup()
t.goto(-120, -17)
t.setheading(230)
t.pendown()
t.fillcolor("#d64b75")
t.begin_fill()
t.forward(50)
t.setheading(320)
for k in range(27):
    t.forward(1)
    t.left(1)
t.setheading(55)
for k in range(50):
    t.forward(1)
    t.right(0.1)
t.end_fill()
# 左手
t.penup()
t.goto(-125, -15)
t.setheading(140)
t.pendown()
t.fillcolor("#fff")
t.begin_fill()
t.forward(8)
t.setheading(50)
myarc(t, 10, 190)
t.setheading(150)
for j in range(80):
    t.forward(1)
    t.left(2.2)
t.forward(24)
t.end_fill()
# 右胳膊
t.penup()
t.goto(27, -45)
t.pendown()
t.fillcolor("#db4e79")
t.setheading(350)
t.begin_fill()
for x in range(50):
    t.forward(1)
    t.right(1)
t.setheading(220)
t.forward(40)
t.setheading(100)
for x in range(50):
    t.forward(1)
    t.left(0.2)
t.end_fill()
# 右手
t.penup()
t.goto(70, -75)
t.pendown()
t.setheading(300)
t.forward(8)
t.setheading(30)
for x in range(40):
    t.forward(1)
    t.right(5)
t.setheading(280)
for x in range(70):
    t.forward(1)
    t.right(2)
# 右脚
t.penup()
t.goto(-70, -180)
t.pendown()
t.setheading(250)
for x in range(30):
    t.forward(1)
    t.left(0.3)
for x in range(160):
    t.forward(1)
    if x < 30:
        t.left(3)
    elif x < 65:
        t.left(0.1)
    else:
        t.left(1)
# 左脚
t.penup()
t.goto(-150, -210)
t.setheading(340)
t.pendown()
t.fillcolor("#fff")
t.begin_fill()
step = 1.5
for i in range(2):
    for j in range(60):
        if j < 30:
            step += 0.1
        else:
            step -= 0.1
        t.forward(step)
        t.left(3)
t.end_fill()

t.hideturtle()

t.up()
t.goto(-500, 400)
t.down()
t.pencolor('pink')
t.write('TO:宝子', font=('宋体', 40, 'bold'))

t.up()
t.goto(300, -460)
t.down()
t.pencolor('pink')
t.write('BY:Jorya', font=('宋体', 40, 'bold'))

t.up()
t.goto(-300, -380)
t.down()
t.pencolor('pink')
t.write('HelloKitty', font=('宋体', 80, 'bold'))

t.hideturtle()
t.mainloop()

  • 3
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
这是一个比较复杂的绘图需求,但是你可以使用 Python 的 turtle 模块来绘制 Hello Kitty。以下是一个简单的示例代码,可以让你开始绘制 Hello Kitty: ```python import turtle # 设置笔的初始位置和方向 turtle.penup() turtle.goto(-100, 100) turtle.pendown() # 绘制头部 turtle.fillcolor('pink') turtle.begin_fill() turtle.circle(100) turtle.end_fill() # 绘制左耳 turtle.fillcolor('white') turtle.begin_fill() turtle.penup() turtle.goto(-150, 200) turtle.pendown() turtle.circle(50) turtle.end_fill() # 绘制右耳 turtle.fillcolor('white') turtle.begin_fill() turtle.penup() turtle.goto(50, 200) turtle.pendown() turtle.circle(50) turtle.end_fill() # 绘制左眼 turtle.fillcolor('blue') turtle.begin_fill() turtle.penup() turtle.goto(-50, 150) turtle.pendown() turtle.circle(20) turtle.end_fill() # 绘制右眼 turtle.fillcolor('blue') turtle.begin_fill() turtle.penup() turtle.goto(50, 150) turtle.pendown() turtle.circle(20) turtle.end_fill() # 绘制左腮红 turtle.fillcolor('red') turtle.begin_fill() turtle.penup() turtle.goto(-70, 50) turtle.pendown() turtle.circle(30) turtle.end_fill() # 绘制右腮红 turtle.fillcolor('red') turtle.begin_fill() turtle.penup() turtle.goto(70, 50) turtle.pendown() turtle.circle(30) turtle.end_fill() # 绘制鼻子 turtle.fillcolor('black') turtle.begin_fill() turtle.penup() turtle.goto(0, 100) turtle.pendown() turtle.circle(10) turtle.end_fill() # 绘制嘴巴 turtle.fillcolor('white') turtle.begin_fill() turtle.penup() turtle.goto(-30, 50) turtle.pendown() turtle.circle(30, 180) turtle.end_fill() # 隐藏笔 turtle.hideturtle() # 等待用户关闭窗口 turtle.done() ``` 这是一个比较简单的 Hello Kitty 的绘制代码,你可以根据需要进行修改和扩展。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

威威猫的栗子

你的鼓励将是我创作的最大动力

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

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

打赏作者

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

抵扣说明:

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

余额充值