python语言程序设计——基本图形绘制(mooc)
2019-04-20 20:35
417 查看
第2周:python基本图形绘制
- 深入理解python语言
- 计算机技术的演进
![]()
- 编程语言的多样初心
![]()
-
python语言的特点
-
“超级语言的诞生”
-
实例2:python蟒蛇绘制
import turtle as tt tt.setup(650,350,200,200) tt.penup() tt.fd(-250) tt.pendown() tt.pensize(25) tt.pencolor("red") tt.seth(-40) for i in range(4): tt.circle(40,80) tt.circle(-40,80) tt.circle(40,80/2) tt.fd(40) tt.circle(16,180) tt.fd(40*2/3) tt.done
- 模块1:turtle库的使用
- turtle库的基本介绍
标准库
- turtle绘图窗体布局
turtle.setup(width,height,startx,stary)
turtle.setup(800,400,0,0) #大小单位为像素,后两个参数设置位置,可选
-
turtle空间坐标体系
-
turtle角度坐标体系
-
RGB色彩体系
-
turtle程序语法元素分析
-
库引用与import
-
turtle画笔控制函数
-
turtle运动控制函数
-
turtle方向控制函数
-
循环语句与range()函数
-
绘制小猪佩奇:
# coding:utf-8 import turtle as t # 绘制小猪佩奇 # ======================================= t.pensize(4) t.hideturtle() t.colormode(255) t.color((255, 155, 192), "pink") t.setup(840, 500) t.speed(10) # 鼻子 t.pu() t.goto(-100,100) t.pd() t.seth(-30) t.begin_fill() a = 0.4 for i in range(120): if 0 <= i < 30 or 60 <= i < 90: a = a+0.08 t.lt(3) # 向左转3度 t.fd(a) # 向前走a的步长 else: a = a-0.08 t.lt(3) t.fd(a) t.end_fill() t.pu() t.seth(90) t.fd(25) t.seth(0) t.fd(10) t.pd() t.pencolor(255, 155, 192) t.seth(10) t.begin_fill() t.circle(5) t.color(160, 82, 45) t.end_fill() t.pu() t.seth(0) t.fd(20) t.pd() t.pencolor(255, 155, 192) t.seth(10) t.begin_fill() t.circle(5) t.color(160, 82, 45) t.end_fill() # 头 t.color((255, 155, 192), "pink") t.pu() t.seth(90) t.fd(41) t.seth(0) t.fd(0) t.pd() t.begin_fill() t.seth(180) t.circle(300, -30) t.circle(100, -60) t.circle(80, -100) t.circle(150, -20) t.circle(60, -95) t.seth(161) t.circle(-300, 15) t.pu() t.goto(-100, 100) t.pd() t.seth(-30) a = 0.4 for i in range(60): if 0 <= i < 30 or 60 <= i <90: a = a+0.08 t.lt(3) # 向左转3度 t.fd(a) # 向前走a的步长 else: a = a-0.08 t.lt(3) t.fd(a) t.end_fill() # 耳朵 t.color((255, 155, 192), "pink") t.pu() t.seth(90) t.fd(-7) t.seth(0) t.fd(70) t.pd() t.begin_fill() t.seth(100) t.circle(-50, 50) t.circle(-10, 120) t.circle(-50, 54) t.end_fill() t.pu() t.seth(90) t.fd(-12) t.seth(0) t.fd(30) t.pd() t.begin_fill() t.seth(100) t.circle(-50, 50) t.circle(-10, 120) t.circle(-50, 56) t.end_fill() #眼睛 t.color((255, 155, 192), "white") t.pu() t.seth(90) t.fd(-20) t.seth(0) t.fd(-95) t.pd() t.begin_fill() t.circle(15) t.end_fill() t.color("black") t.pu() t.seth(90) t.fd(12) t.seth(0) t.fd(-3) t.pd() t.begin_fill() t.circle(3) t.end_fill() t.color((255, 155, 192), "white") t.pu() t.seth(90) t.fd(-25) t.seth(0) t.fd(40) t.pd() t.begin_fill() t.circle(15) t.end_fill() t.color("black") t.pu() t.seth(90) t.fd(12) t.seth(0) t.fd(-3) t.pd() t.begin_fill() t.circle(3) t.end_fill() # 腮 t.color((255, 155, 192)) t.pu() t.seth(90) t.fd(-95) t.seth(0) t.fd(65) t.pd() t.begin_fill() t.circle(30) t.end_fill() # 嘴 t.color(239, 69, 19) t.pu() t.seth(90) t.fd(15) t.seth(0) t.fd(-100) t.pd() t.seth(-80) t.circle(30, 40) t.circle(40, 80) # 身体 t.color("red", (255, 99, 71)) t.pu() t.seth(90) t.fd(-20) t.seth(0) t.fd(-78) t.pd() t.begin_fill() t.seth(-130) t.circle(100,10) t.circle(300,30) t.seth(0) t.fd(230) t.seth(90) t.circle(300,30) t.circle(100,3) t.color((255,155,192),(255,100,100)) t.seth(-135) t.circle(-80,63) t.circle(-150,24) t.end_fill() # 手 t.color((255,155,192)) t.pu() t.seth(90) t.fd(-40) t.seth(0) t.fd(-27) t.pd() t.seth(-160) t.circle(300,15) t.pu() t.seth(90) t.fd(15) t.seth(0) t.fd(0) t.pd() t.seth(-10) t.circle(-20,90) t.pu() t.seth(90) t.fd(30) t.seth(0) t.fd(237) t.pd() t.seth(-20) t.circle(-300,15) t.pu() t.seth(90) t.fd(20) t.seth(0) t.fd(0) t.pd() t.seth(-170) t.circle(20,90) # 脚 t.pensize(10) t.color((240,128,128)) t.pu() t.seth(90) t.fd(-75) t.seth(0) t.fd(-180) t.pd() t.seth(-90) t.fd(40) t.seth(-180) t.color("black") t.pensize(15) t.fd(20) t.pensize(10) t.color((240, 128, 128)) t.pu() t.seth(90) t.fd(40) t.seth(0) t.fd(90) t.pd() t.seth(-90) t.fd(40) t.seth(-180) t.color("black") t.pensize(15) t.fd(20) # 尾巴 t.pensize(4) t.color((255, 155, 192)) t.pu() t.seth(90) t.fd(70) t.seth(0) t.fd(95) t.pd() t.seth(0) t.circle(70, 20) t.circle(10, 330) t.circle(70, 30) t.done()
- 绘制玫瑰花:
import turtle # 设置初始位置 turtle.penup() turtle.left(90) turtle.fd(200) turtle.pendown() turtle.right(90) # 花蕊 turtle.fillcolor("red") turtle.begin_fill() turtle.circle(10,180) turtle.circle(25,110) turtle.left(50) turtle.circle(60,45) turtle.circle(20,170) turtle.right(24) turtle.fd(30) turtle.left(10) turtle.circle(30,110) turtle.fd(20) turtle.left(40) turtle.circle(90,70) turtle.circle(30,150) turtle.right(30) turtle.fd(15) turtle.circle(80,90) turtle.left(15) turtle.fd(45) turtle.right(165) turtle.fd(20) turtle.left(155) turtle.circle(150,80) turtle.left(50) turtle.circle(150,90) turtle.end_fill() # 花瓣1 turtle.left(150) turtle.circle(-90,70) turtle.left(20) turtle.circle(75,105) turtle.setheading(60) turtle.circle(80,98) turtle.circle(-90,40) # 花瓣2 turtle.left(180) turtle.circle(90,40) turtle.circle(-80,98) turtle.setheading(-83) # 叶子1 turtle.fd(30) turtle.left(90) turtle.fd(25) turtle.left(45) turtle.fillcolor("green") turtle.begin_fill() turtle.circle(-80,90) turtle.right(90) turtle.circle(-80,90) turtle.end_fill() turtle.right(135) turtle.fd(60) turtle.left(180) turtle.fd(85) turtle.left(90) turtle.fd(80) # 叶子2 turtle.right(90) turtle.right(45) turtle.fillcolor("green") turtle.begin_fill() turtle.circle(80,90) turtle.left(90) turtle.circle(80,90) turtle.end_fill() turtle.left(135) turtle.fd(60) turtle.left(180) turtle.fd(60) turtle.right(90) turtle.circle(200,60)
相关文章推荐
- 中国大学 MOOC 课程 《Python 语言程序设计》第五周绘制树
- 中国大学 MOOC 课程 《Python 语言程序设计》第六周课后习题
- Python123 测验2: Python基本图形绘制 (第2周)
- python数字图像处理(12):基本图形的绘制
- python语言程序设计MOOC
- Python_note2 基本图形绘制+turtle库使用
- MOOC —— Python语言基础与应用 by 北京大学 第七章 基本扩展模块
- MOOC —— Python语言程序设计 by 北京交通大学 第六章 面向对象的编程方法
- 中国大学 MOOC 课程 《Python 语言程序设计》第六周
- 【JAVA语言程序设计基础篇】--图形--练习绘制多边形
- MOOC【Python语言程序设计】- 第1周-选择题
- 2018.4.2(Python)基本图形绘制
- 【JAVA语言程序设计基础篇】--图形--练习绘制时钟
- 【JAVA语言程序设计基础篇】--图形-- 使用抽象方法绘制函数图形
- P2 Python基本图形绘制
- Life is short,Use Python!-----Python双杀!-----Python基本图形绘制
- 第二章 Python基本图形绘制
- python学习-第二课时-Python基本图形绘制
- python数字图像处理(12):基本图形的绘制
- Python学习12_基本图形的绘制