当女朋友要求你用Python画一个粉粉的Hello Kitty的时候

2023-11-01 10:36

本文主要是介绍当女朋友要求你用Python画一个粉粉的Hello Kitty的时候,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

先看效果图

在这里插入图片描述

完整代码

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(10)# 头
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.02else:step -= 0.02t.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.02else:step -= 0.02t.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.02else:step -= 0.02t.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.1else:step -= 0.1t.forward(step)t.left(3)
t.end_fill()t.hideturtle()
t.mainloop()

画笔速度可以通过下面的代码自己调哦!

t.speed(50)

这篇关于当女朋友要求你用Python画一个粉粉的Hello Kitty的时候的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/322352

相关文章

Python包管理工具pip的升级指南

《Python包管理工具pip的升级指南》本文全面探讨Python包管理工具pip的升级策略,从基础升级方法到高级技巧,涵盖不同操作系统环境下的最佳实践,我们将深入分析pip的工作原理,介绍多种升级方... 目录1. 背景介绍1.1 目的和范围1.2 预期读者1.3 文档结构概述1.4 术语表1.4.1 核

基于Python实现一个图片拆分工具

《基于Python实现一个图片拆分工具》这篇文章主要为大家详细介绍了如何基于Python实现一个图片拆分工具,可以根据需要的行数和列数进行拆分,感兴趣的小伙伴可以跟随小编一起学习一下... 简单介绍先自己选择输入的图片,默认是输出到项目文件夹中,可以自己选择其他的文件夹,选择需要拆分的行数和列数,可以通过

Python中反转字符串的常见方法小结

《Python中反转字符串的常见方法小结》在Python中,字符串对象没有内置的反转方法,然而,在实际开发中,我们经常会遇到需要反转字符串的场景,比如处理回文字符串、文本加密等,因此,掌握如何在Pyt... 目录python中反转字符串的方法技术背景实现步骤1. 使用切片2. 使用 reversed() 函

Python中将嵌套列表扁平化的多种实现方法

《Python中将嵌套列表扁平化的多种实现方法》在Python编程中,我们常常会遇到需要将嵌套列表(即列表中包含列表)转换为一个一维的扁平列表的需求,本文将给大家介绍了多种实现这一目标的方法,需要的朋... 目录python中将嵌套列表扁平化的方法技术背景实现步骤1. 使用嵌套列表推导式2. 使用itert

使用Docker构建Python Flask程序的详细教程

《使用Docker构建PythonFlask程序的详细教程》在当今的软件开发领域,容器化技术正变得越来越流行,而Docker无疑是其中的佼佼者,本文我们就来聊聊如何使用Docker构建一个简单的Py... 目录引言一、准备工作二、创建 Flask 应用程序三、创建 dockerfile四、构建 Docker

Python使用vllm处理多模态数据的预处理技巧

《Python使用vllm处理多模态数据的预处理技巧》本文深入探讨了在Python环境下使用vLLM处理多模态数据的预处理技巧,我们将从基础概念出发,详细讲解文本、图像、音频等多模态数据的预处理方法,... 目录1. 背景介绍1.1 目的和范围1.2 预期读者1.3 文档结构概述1.4 术语表1.4.1 核

Python使用pip工具实现包自动更新的多种方法

《Python使用pip工具实现包自动更新的多种方法》本文深入探讨了使用Python的pip工具实现包自动更新的各种方法和技术,我们将从基础概念开始,逐步介绍手动更新方法、自动化脚本编写、结合CI/C... 目录1. 背景介绍1.1 目的和范围1.2 预期读者1.3 文档结构概述1.4 术语表1.4.1 核

Conda与Python venv虚拟环境的区别与使用方法详解

《Conda与Pythonvenv虚拟环境的区别与使用方法详解》随着Python社区的成长,虚拟环境的概念和技术也在不断发展,:本文主要介绍Conda与Pythonvenv虚拟环境的区别与使用... 目录前言一、Conda 与 python venv 的核心区别1. Conda 的特点2. Python v

Python使用python-can实现合并BLF文件

《Python使用python-can实现合并BLF文件》python-can库是Python生态中专注于CAN总线通信与数据处理的强大工具,本文将使用python-can为BLF文件合并提供高效灵活... 目录一、python-can 库:CAN 数据处理的利器二、BLF 文件合并核心代码解析1. 基础合

Python使用OpenCV实现获取视频时长的小工具

《Python使用OpenCV实现获取视频时长的小工具》在处理视频数据时,获取视频的时长是一项常见且基础的需求,本文将详细介绍如何使用Python和OpenCV获取视频时长,并对每一行代码进行深入解析... 目录一、代码实现二、代码解析1. 导入 OpenCV 库2. 定义获取视频时长的函数3. 打开视频文