python基础训练营06
任务六 时长:
啥是佩奇代码复现
参考链接:https://mp.weixin.qq.com/s/whtJOrlegpWzgisYJabxOg
画一只佩奇:
代码:
- from turtle import *
- def nose(x,y):#鼻子
- penup()#提起笔
- goto(x,y)#定位
- pendown()#落笔,开始画
- setheading(-30)#将乌龟的方向设置为to_angle/为数字(0-东、90-北、180-西、270-南)
- begin_fill()#准备开始填充图形
- a=0.4
- for i in range(120):
- if 0<=i<30 or 60<=i<90:
- a=a+0.08
- left(3) #向左转3度
- forward(a) #向前走a的步长
- else:
- a=a-0.08
- left(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和fillcolor
- 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.4
- for i in range(60):
- if 0<=i<30 or 60<=i<90:
- a=a+0.08
- lt(3) #向左转3度
- fd(a) #向前走a的步长
- else:
- a=a-0.08
- lt(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 body(x,y):
- color("red",(255,99,71))
- penup()
- goto(x,y)
- pendown()
- begin_fill()
- setheading(-130)
- circle(100,10)
- circle(300,30)
- setheading(0)
- forward(230)
- setheading(90)
- circle(300,30)
- circle(100,3)
- color((255,155,192),(255,100,100))
- setheading(-135)
- circle(-80,63)
- circle(-150,24)
- end_fill()
- def hands(x,y):
- color((255,155,192))
- penup()
- goto(x,y)
- pendown()
- setheading(-160)
- circle(300,15)
- penup()
- setheading(90)
- forward(15)
- setheading(0)
- forward(0)
- pendown()
- setheading(-10)
- circle(-20,90)
- penup()
- setheading(90)
- forward(30)
- setheading(0)
- forward(237)
- pendown()
- setheading(-20)
- circle(-300,15)
- penup()
- setheading(90)
- forward(20)
- setheading(0)
- forward(0)
- pendown()
- setheading(-170)
- circle(20,90)
- def foot(x,y):
- pensize(10)
- color((240,128,128))
- penup()
- goto(x,y)
- pendown()
- setheading(-90)
- forward(40)
- setheading(-180)
- color("black")
- pensize(15)
- fd(20)
- pensize(10)
- color((240,128,128))
- penup()
- setheading(90)
- forward(40)
- setheading(0)
- forward(90)
- pendown()
- setheading(-90)
- forward(40)
- setheading(-180)
- color("black")
- pensize(15)
- fd(20)
- def tail(x,y):
- pensize(4)
- color((255,155,192))
- penup()
- goto(x,y)
- pendown()
- seth(0)
- circle(70,20)
- circle(10,330)
- circle(70,30)
- 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) #嘴
- body(-32,-8) #身体
- hands(-56,-45) #手
- foot(2,-177) #脚
- tail(148,-155) #尾巴
- done()
- if __name__ == '__main__':
- main()
效果图:
python基础训练营06的更多相关文章
- python基础训练营01
一.基础讲解: 1.1 文件末尾的.py后缀,指出这个文件,是一个python文件,因此,系统将使用python解释器来运行该文件,确定文件中每一个单词的含义. 1.2 python编辑/运行方法: ...
- python 基础篇 06 编码 以及小知识点补充
本节主要内容: 1. is和==的区别2. 编码的问题 ⼀. is和==的区别1. id()通过id()我们可以查看到⼀个变量表⽰的值在内存中的地址 注 ----<<<在pytho ...
- python基础训练营05
任务五 时长:2天 1.file a.打开文件方式(读写两种方式) b.文件对象的操作方法 c.学习对excel及csv文件进行操作 2.os模块 3.datetime模块 4.类和对象 5.正则表达 ...
- python基础训练营04-函数
任务四 函数的关键字 函数的定义 函数参数与作用域 函数返回值 一.函数的关键字: def 二.函数的定义: 在Python中,定义一个函数要使用def语句,依次写出函数名.括号.括号中的参数和冒号 ...
- python基础训练营03——字典、集合、判断、循环
一.字典dict: 相比列表list而言,列表list像一本书,如果要查书中的某一个内容,需要把书从前往后翻一遍,直到找到想要获取的东西:而字典dict,就像现实中的字典一样,通过查找特定的字或者词( ...
- python基础训练营02
任务二 时长:2天 1. 列表 a. 标志 b. 基本操作(创建,append( ),pop( ) ,del( ), 拷贝) c. 列表相关方法 2. 元组 a. 标志 b. 基本操作(创建及不可变性 ...
- 零基础学Python-第二章 :Python基础语法-06.变量的定义和常用操作
网络带宽计算器的原理 输出的内容用print 引入变量,在前面写一个变量,是一个有意义的单词.把123这个数值赋值给变量a 下面的代码可读性 要比上面高很多. 变量其他需要掌握的知识点 一般这样是用做 ...
- Python基础:06条件和循环
1:条件表达式(三元操作符) Python 在很长的一段时间里没有条件表达式(C ? X : Y), 或称三元运算符.人们试着用 and 和 or 来模拟它, 但大多都是错误的. 根据 FAQ , 正 ...
- python基础——访问限制
python基础——访问限制 在Class内部,可以有属性和方法,而外部代码可以通过直接调用实例变量的方法来操作数据,这样,就隐藏了内部的复杂逻辑. 但是,从前面Student类的定义来看,外部代码还 ...
随机推荐
- java GZIP 压缩数据
package com.cjonline.foundation.cpe.action; import java.io.ByteArrayInputStream; import java.io.Byte ...
- Python 学习笔记(五)常用函数
Python内建函数 四舍五入: round() 绝对值: abs() >>> round(1.543,2) 保留两位小数,四舍五入为1.54 1.54 >>> r ...
- 菜鸟笔记 -- Chapter 6.2.3 成员变量
6.2.3 成员变量 在Java中对象的属性也称为成员变量[也叫字段].成员变量的类型可以设置为Java中合法的数据类型,其实成员变量就是普通的变量,可以为它设置初始值,也可以不设置初始值,如果不设 ...
- TCP套接字
端口的概念 每个电脑一根网线,但是你挂着QQ的同时还可以浏览网页.两个不同应用的数据在同一根网线里是如何传输的呢?根据七层互联网模型,这个功能由运输层(TCP是运输层主要协议)实现.怎么实现呢,在网络 ...
- js对URL的相关操作集锦
1.location.href..... (1)self.loction.href="/url" window.location.href="/url" ...
- js的事件流你真的弄明白了吗?
当浏览器发展到第四代时候,浏览器开发团队遇到了一个有意思的问题:页面的哪一部分会拥有某个特地的事件?要明白这个问题问的是什么,可以想象画在纸上的一组同心圆,如果你把手指放在圆心上,那么你的手指指向的不 ...
- 自定义组件v-model的实质性理解
用了几个月Vue一直很纠结自定义组件的v-model实现,最近开始学习React时,React中受控组件与状态提升的理念与v-model不谋而合. 转载请注明地址: https://www.cnblo ...
- 因为之前完全没有接触过Spring,所以准备先把spring实战看完再落实项目
因为之前完全没有接触过Spring,所以准备先把spring实战看完再落实项目
- 利用JQUERY实现多个AJAX请求等待
利用JQUERY实现多个AJAX请求等待 li {list-style-type:decimal;}.wiz-editor-body ol.wiz-list-level2 > li {list- ...
- vue入门——基本概念
1. 挂载点,模板,实例的关系? 首先附上一个基本demo: <!DOCTYPE html> <html lang="en"> <head> & ...