当前位置: 首页 > news >正文

Python实例之画小猪佩奇

效果图:

 

python代码以及解释,没有运用模块。 

"""
绘制小猪佩奇
"""
from turtle import *def nose(x,y):"""画鼻子"""penup()# 将海龟移动到指定的坐标goto(x,y)pendown()# 设置海龟的方向(0-东、90-北、180-西、270-南)setheading(-30)begin_fill()a = 0.4for i in range(120):if 0 <= i < 30 or 60 <= i <90:a = a + 0.08# 向左转3度left(3)# 向前走forward(a)else:a = a - 0.08left(3)forward(a)end_fill()penup()setheading(90)forward(25)setheading(0)forward(10)pendown()# 设置画笔的颜色(红, 绿, 蓝)pencolor(255, 155, 192)setheading(10)begin_fill()circle(5)color(160, 82, 45)end_fill()penup()setheading(0)forward(20)pendown()pencolor(255, 155, 192)setheading(10)begin_fill()circle(5)color(160, 82, 45)end_fill()def head(x, y):"""画头"""color((255, 155, 192), "pink")penup()goto(x,y)setheading(0)pendown()begin_fill()setheading(180)circle(300, -30)circle(100, -60)circle(80, -100)circle(150, -20)circle(60, -95)setheading(161)circle(-300, 15)penup()goto(-100, 100)pendown()setheading(-30)a = 0.4for i in range(60):if 0<= i < 30 or 60 <= i < 90:a = a + 0.08lt(3) #向左转3度fd(a) #向前走a的步长else:a = a - 0.08lt(3)fd(a)end_fill()def ears(x,y):"""画耳朵"""color((255, 155, 192), "pink")penup()goto(x, y)pendown()begin_fill()setheading(100)circle(-50, 50)circle(-10, 120)circle(-50, 54)end_fill()penup()setheading(90)forward(-12)setheading(0)forward(30)pendown()begin_fill()setheading(100)circle(-50, 50)circle(-10, 120)circle(-50, 56)end_fill()def eyes(x,y):"""画眼睛"""color((255, 155, 192), "white")penup()setheading(90)forward(-20)setheading(0)forward(-95)pendown()begin_fill()circle(15)end_fill()color("black")penup()setheading(90)forward(12)setheading(0)forward(-3)pendown()begin_fill()circle(3)end_fill()color((255, 155, 192), "white")penup()seth(90)forward(-25)seth(0)forward(40)pendown()begin_fill()circle(15)end_fill()color("black")penup()setheading(90)forward(12)setheading(0)forward(-3)pendown()begin_fill()circle(3)end_fill()def cheek(x,y):"""画脸颊"""color((255, 155, 192))penup()goto(x,y)pendown()setheading(0)begin_fill()circle(30)end_fill()def mouth(x,y):"""画嘴巴"""color(239, 69, 19)penup()goto(x, y)pendown()setheading(-80)circle(30, 40)circle(40, 80)def setting():"""设置参数"""pensize(4)# 隐藏海龟hideturtle()colormode(255)color((255, 155, 192), "pink")setup(840, 500)speed(10)def main():"""主函数"""setting() nose(-100, 100)head(-69, 167)ears(0, 160)eyes(0, 140)cheek(80, 10)mouth(-20, 30)done()if __name__ == '__main__':main()

http://www.lryc.cn/news/596703.html

相关文章:

  • Java函数指南:从Function到BiFunction的深度解析
  • AI AgentLLM架构演进的大逻辑和小脉络
  • rocky9-zabbix简单部署
  • 第十一章 用Java实现JVM之异常处理
  • C++11--锁分析
  • 华为视觉算法面试30问全景精解
  • What Does “Directory of the Script Being Run” Mean?
  • final修饰符不可变的底层
  • SpringBoot PO VO BO POJO实战指南
  • Pycharm下载、安装及配置
  • 力扣 hot100 Day52
  • RabbitMQ03——面试题
  • 为什么要微调大语言模型
  • 论文笔记 | Beyond Pick-and-Place: Tackling Robotic Stacking of Diverse Shapes
  • 解决pip指令超时问题
  • 数据结构 堆(2)---堆的实现
  • LeetCode 热题100:42.接雨水
  • Unity UI的未来之路:从UGUI到UI Toolkit的架构演进与特性剖析(1)
  • 业务流逻辑如何搭建?为何橙武平台选用了 LogicFlow?​
  • day19 链表
  • 程序是如何生成的-以c语言为例
  • 信息学奥赛一本通 1553:【例 2】暗的连锁
  • 前端_CSS复习
  • 【React 入门系列】React 组件通讯与生命周期详解
  • 高可用架构模式——数据集群和数据分区
  • 单细胞转录组学+空间转录组的整合及思路
  • OneCode3.0 UI组件注解详解手册
  • 【vscode】vscode中python虚拟环境的创建
  • 回调地狱及解决方法
  • error C++17 or later compatible compiler is required to use ATen.