当前位置: 首页 > 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.dtcms.com/a/292041.html

相关文章:

  • 知识库搭建之Meilisearch‘s 搜索引擎 测评-东方仙盟测评师
  • Agent架构与工作原理:理解智能体的核心机制
  • Apache Ignite 中 WHERE 子句中的子查询(Subqueries in WHERE Clause)的执行方式
  • 社交电商推客系统全栈开发指南:SpringCloud+分润算法+Flutter跨端
  • 深入浅出控制反转与依赖注入:从理论到实践
  • 深度学习的一些疑点整理
  • J2EE模式---拦截过滤器模式
  • 操作系统 —— A / 概述
  • 工业通信网关详解:2025年技术选型与物联网方案设计指南
  • 激活函数Focal Loss 详解​
  • Jenkins流水线中的核心概念
  • DearMom以“新生儿安全系统”重塑婴儿车价值,揽获CBME双项大奖
  • STM32 GPIO(通用输入输出)详解:从模式原理到实战应用
  • C++_Hello算法_队列
  • Word2Vec和Doc2Vec学习笔记
  • 用手机当外挂-图文并茂做报告纪要
  • AWS PrivateLink方式访问Redis
  • Windows游戏自动检测本地是否安装 (C++版)
  • 设计模式七:抽象工厂模式(Abstract Factory Pattern)
  • 技能系统详解(4)——运动表现
  • 面向对象高级:static
  • linux内核与GNU之间的联系和区别
  • 决策规划内容整理
  • Linux的磁盘存储管理实操——(下一)——标准分区扩容
  • 得物视觉算法面试30问全景精解
  • 图论的整合
  • 西门子 S7-1500分布式 I/O通信 :PROFINET IO 与 PROFIBUS DP核心技术详解(上)
  • Spring、Spring MVC、Spring Boot、Spring Cloud的联系和区别
  • Uni-App:跨平台开发的终极解决方案
  • uniapp app打包流程