从csdn看到的,什么都不用说了,copy ctrl+v就是干。。。

基本原理

选好画板大小,设置好画笔颜色、粗细,定位好位置,依次画鼻子、头、耳朵、眼睛、腮、嘴、身体、手脚、尾巴,完事儿。

都知道,Turtle 是 Python 内置的一个比较有趣味的模块,俗称“海龟绘图”,它是基于 Tkinter 模块打造,提供一些简单的绘图工具。

在海龟作图中,我们可以编写指令让一个虚拟的(想象中的)海龟在屏幕上来回移动。这个海龟带着一只钢笔,我们可以让海龟无论移动到哪都使用这只钢笔来绘制线条。通过编写代码,以各种很酷的模式移动海龟,我们可以绘制出令人惊奇的图片。使用海龟作图,我们不仅能够只用几行代码就创建出令人印象深刻的视觉效果,而且还可以跟随海龟看看每行代码如何影响到它的移动。这能够帮助我们理解代码的逻辑。

所以,海龟作图也常被用作新手学习 Python 的一种方式。更丰富详细的功能及知识可以参考官方文档:

https://docs.python.org/3/library/turtle.html

from turtle import*
def nose(x,y):#鼻子penup()#提起笔goto(x,y)#定位pendown()#落笔,开始画setheading(-30)#将乌龟的方向设置为to_angle/为数字(0-东、90-北、180-西、270-南)begin_fill()#准备开始填充图形a=0.4for i in range(120):if 0<=i<30 or 60<=i<90:a=a+0.08left(3) #向左转3度forward(a) #向前走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)#返回或设置pencolor和fillcolorend_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)      #将其设置为1.0或255.随后 颜色三元组的r,g,b值必须在0 .. cmode范围内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()

python之画个小猪佩奇相关推荐

  1. python画-使用python画个小猪佩奇的示例代码

    基本原理 选好画板大小,设置好画笔颜色.粗细,定位好位置,依次画鼻子.头.耳朵.眼睛.腮.嘴.身体.手脚.尾巴,完事儿. 都知道,Turtle 是 Python 内置的一个比较有趣味的模块,俗称&qu ...

  2. python画图小猪佩奇_吊炸天!Python 20秒画出小猪佩奇

    原标题:吊炸天!Python 20秒画出小猪佩奇 今年社交平台上的带货女王是谁?范冰冰?杨幂?Angelababy?不,是猪猪女孩小猪佩奇. 小猪佩奇在构图基本是各种曲线,类抛物线.类圆.类椭圆.类二 ...

  3. 用python画小猪佩奇代码_用python画个小猪佩奇(turtle示例源码)

    [实例简介]来副小猪佩奇,用python画个小猪佩奇 [实例截图] [核心代码]# coding:utf-8 import turtle as t def nose(x,y):#鼻子 t.pu() t ...

  4. python画图小猪佩奇_用python画个小猪佩奇

    突发奇想,拿python画个小猪佩奇,大家可以运行着玩玩 draw.py # -*- coding:utf-8 -*- from turtle import * def nose(x,y):#鼻子 p ...

  5. python海龟画小猪佩奇动画片全集_用python画个小猪佩奇

    突发奇想,拿python画个小猪佩奇,大家可以运行着玩玩 draw.py # -*- coding:utf-8 -*- from turtle import * def nose(x,y):#鼻子 p ...

  6. 用python画佩奇_使用python画个小猪佩奇的示例代码

    基本原理 选好画板大小,设置好画笔颜色.粗细,定位好位置,依次画鼻子.头.耳朵.眼睛.腮.嘴.身体.手脚.尾巴,完事儿. 都知道,Turtle 是 Python 内置的一个比较有趣味的模块,俗称&qu ...

  7. python画图小猪佩奇_python 画个小猪佩奇

    不知道大家小时候有没有学习过logo语言,就是操纵一只小王八,来画各种图案.博主小学微机课就学习了这个,最近发现python的turtle包就是logo语言,所以画个小猪佩奇和大家分享. 代码来自知乎 ...

  8. 用python画苹果的代码_使用python画个小猪佩奇的示例代码

    基本原理 选好画板大小,设置好画笔颜色.粗细,定位好位置,依次画鼻子.头.耳朵.眼睛.腮.嘴.身体.手脚.尾巴,完事儿. 都知道,Turtle 是 Python 内置的一个比较有趣味的模块,俗称&qu ...

  9. 用python画甜小兔_Python 实现画一个小猪佩奇

    ===================================== 看到 佩奇的广告片刷红,为了迎接猪年,咱们也来用Python  画板实现一个效果吧 from turtle import* ...

最新文章

  1. 收缩临时库 shrink tempdb
  2. Palindrome Linked List
  3. Replicate(网络复制),ActorRole(角色),Ownership(所有权)以及RPC(远程调用)等等...
  4. adb install 和adb uninstall
  5. window安装mysql5.7解压版(解决乱码问题)
  6. mysql-connector-mysql 8.0 (spring-boot-starter-parent 管理的版本) + Activiti 6.x 自动建表失败
  7. layuimini 图标颜色便捷指定
  8. 图论/暴力 Codeforces Beta Round #94 (Div. 2 Only) B. Students and Shoelaces
  9. H5调用摄像头扫码详解
  10. python制作通讯录
  11. 读计算机视觉综述做的脑图(11.09更新)
  12. 视频教程-程序员的数学:线性代数-Python
  13. matlab median filter,matlab--fftshift,filter2,median用法. (转)
  14. 电机控制的fast decay与slow decay
  15. 有什么方法判断网站后台是用什么语言写的
  16. 那些你投的基金没告诉你的事
  17. (攻防世界)(pwn)forgot
  18. android程序安装空间不足,vivo x9总提示内存不足安装软件失败怎么办?
  19. 梦想在此起航,定要全力以赴。
  20. 为什么很多公司都不招大龄码农?

热门文章

  1. PPT提示“office未获得合适的许可…”及快捷键复制一次粘贴两次问题的解决办法
  2. 仿京东严选商城项目,集购物+支付+发货一体化架构项目解决方案
  3. 前端页面布局CSS实操Demo1
  4. 微会动资讯:2018年中国展览业发展回顾与2019年展望
  5. 百城巡展 | 人大金仓深耕区域市场 续力行业数字化转型升级
  6. 东华大学计算机复试难度,东华大学计算机复试回忆
  7. php生成超链接完整代码_PHP 超链接 抓取实现代码
  8. 法国制药巨头赛诺菲将利用人工智能来打击流感
  9. 【思路】月月查华华的手机
  10. maven项目解决pom.xml头部 httpmaven.apache.orgxsdmaven-4.0.0.xsd报错的问题