如果你会画一条线,那么你将能勾勒出整个世界。
- 先来点历史
1946-1981
|
计算机系统结构时代(35年)
|
解决计算机的问题
|
1981-2008
|
网络和视窗时代(27年)
|
解决交互问题
|
2008-2016
|
复杂信息系统时代(8年)
|
解决数据处理问题
|
2016-xxxx
|
人工智能时代
|
解决人类的问题
|
- 信息化的发展非常迅速,变化周期在大幅度的减短。
- 由原来解决构造问题转向解决服务大众的问题。
- Python进步之路不可阻挡。
- 语言的江湖
机器语言
|
代码直接执行,执行与CPU型号有关
|
汇编语言
|
包含助记符和汇编器,执行与CPU型号有关
|
高级语言
|
包含编译器或解释器,接近自然语言,可移植
|
超级语言
|
粘性整合已有程序,具有庞大计算生态
|
- Turtle绘图体系
1969年诞生,主要用于程序入门设计和LOGO开发
Turtle Screen(界面设置)
|
setup(width,height,*startx,*starty)
|
设置窗体大小,单位为像素(px)
|
title(titlestring)
|
设置窗图形标题
|
mode(mode)
|
mode='standard' or 'logo'
|
standard:起始指向正东,以逆时针为正
|
logo:起始指向正北,以顺时针为正
|
colormode(mode)
|
mode=1 or 255 表示RGB表示形式
|
speed(sp)
|
sp=1~10 控制绘图速度
|
Turtle PenMove(画笔动作)
|
forward | fd(dis)
|
dis=前进距离,单位px
|
backward | back | bk(dis)
|
dis=后退距离,单位px
|
circle(r,ang)
|
以r(左正右负)为半径,根据mode正方向 旋转ang度
|
left | lt (ang)
|
Turtle坐标下**左**转ang,单位 角度
|
right | rt (ang)
|
Turtle坐标下**右**转ang,单位 角度
|
setx(x)
|
设置起始坐标在(x,0)坐标上
|
sety(y)
|
设置起始坐标在(0,y)坐标上
|
setheading | seth(ang)
|
绝对坐标下Turtle头方向根据 mode正方向 旋转ang度
|
goto(x,y)
|
立即让Turtle到达(x,y)坐标处
|
penup | pu | up()
|
画笔抬起
|
pendown | pd | down()
|
画笔落下
|
pensize | width()
|
画笔线条宽度,单位px
|
Turtle Color&filling(颜色与填充)
|
color(*pencolor,*fillingcolor)
|
colorstring / (R,G,B)均可,RGB参照colormode,可缺省
|
pencolor(colorstring / (R,G,B))
|
设置画笔颜色
|
fillcolor(colorstring / (R,G,B))
|
设置填充颜色
|
begin_fill()
|
开始填充标志
|
end_fill()
|
停止填充标志
|
Turtle Others(其他)
|
clear()
|
清除图像,不改变Turtle位置
|
degrees()
|
设置为角度制
|
radians()
|
设置为弧度制
|
showturtle | st()
|
显示Turtle
|
hideturtle | ht()
|
显示Turtle
|
![绘图窗体](https://i-blog.csdnimg.cn/blog_migrate/1575ae429280584af8b3b1c94aa185c0.png)
来个自画像
import turtle
turtle.setup(650, 350, 200, 200)
turtle.penup()
turtle.fd(-250)
turtle.pendown()
turtle.pensize(25)
turtle.pencolor("purple")
turtle.seth(-40)
for i in range(4):
turtle.circle(40, 80)
turtle.circle(-40, 80)
turtle.circle(40, 80/2)
turtle.fd(40)
turtle.circle(16, 180)
turtle.fd(40 * 2/3)
turtle.done()
![效果图](https://i-blog.csdnimg.cn/blog_migrate/fb3c94e26c115b8a8df0af5300feee29.png)
- 如何引入库—import
import 库名
|
引用: 库名 .函数名
|
from 库名 import 函数名
|
引用: 函数名
|
from 库名 import *
|
import 库名 as __
|
引用: __ .函数名
|
- For循环与range()函数
- range(M,N):产生从M到N-1以1为步长的整数序列,M可缺省,缺省值为0
- 有点福利
import turtle
turtle.speed(10)
turtle.setup(650,650)
turtle.pensize(5)
turtle.penup()
turtle.goto(0,-100)
turtle.pendown()
turtle.fillcolor(0,0,0)
turtle.begin_fill()
turtle.circle(50,180)
turtle.circle(-50,180)
turtle.circle(-100,180)
turtle.end_fill()
turtle.circle(-100,180)
turtle.pensize(35)
turtle.pencolor(1,1,1)
turtle.penup()
turtle.goto(0,50)
turtle.pendown()
turtle.circle(0)
turtle.pencolor(0,0,0)
turtle.penup()
turtle.goto(0,-50)
turtle.pendown()
turtle.circle(0)
turtle.pensize(10)
turtle.penup()
turtle.goto(30,150)
turtle.pendown()
turtle.bk(60)
turtle.penup()
turtle.circle(10,180)
turtle.pendown()
turtle.bk(60)
turtle.penup()
turtle.circle(-10,180)
turtle.pendown()
turtle.bk(60)
turtle.penup()
turtle.goto(0,150)
turtle.pendown()
turtle.penup()
turtle.goto(-30,-150)
turtle.pendown()
turtle.fd(20)
turtle.penup()
turtle.fd(20)
turtle.pendown()
turtle.fd(20)
turtle.penup()
turtle.circle(-10,180)
turtle.pendown()
turtle.fd(20)
turtle.penup()
turtle.fd(20)
turtle.pendown()
turtle.fd(20)
turtle.penup()
turtle.circle(10,180)
turtle.pendown()
turtle.fd(20)
turtle.penup()
turtle.fd(20)
turtle.pendown()
turtle.fd(20)
turtle.penup()
turtle.left(90)
turtle.goto(-150,-30)
turtle.pendown()
turtle.fd(60)
turtle.penup()
turtle.circle(10,180)
turtle.pendown()
turtle.fd(20)
turtle.penup()
turtle.fd(20)
turtle.pendown()
turtle.fd(20)
turtle.penup()
turtle.circle(-10,180)
turtle.pendown()
turtle.fd(60)
turtle.penup()
turtle.goto(150,30)
turtle.pendown()
turtle.bk(20)
turtle.penup()
turtle.bk(20)
turtle.pendown()
turtle.bk(20)
turtle.penup()
turtle.circle(-10,180)
turtle.pendown()
turtle.bk(60)
turtle.penup()
turtle.circle(10,180)
turtle.pendown()
turtle.bk(20)
turtle.penup()
turtle.bk(20)
turtle.pendown()
turtle.bk(20)
turtle.penup()
turtle.goto(190,0)
turtle.circle(190,45)
turtle.pendown()
turtle.bk(30)
turtle.fd(60)
turtle.penup()
turtle.circle(10,180)
turtle.pendown()
turtle.fd(60)
turtle.penup()
turtle.circle(-10,180)
turtle.pendown()
turtle.fd(20)
turtle.penup()
turtle.fd(20)
turtle.pendown()
turtle.fd(20)
turtle.penup()
turtle.bk(30)
turtle.circle(150,180)
turtle.pendown()
turtle.bk(30)
turtle.fd(60)
turtle.penup()
turtle.circle(-10,180)
turtle.pendown()
turtle.fd(20)
turtle.penup()
turtle.fd(20)
turtle.pendown()
turtle.fd(20)
turtle.penup()
turtle.circle(10,180)
turtle.pendown()
turtle.fd(20)
turtle.penup()
turtle.fd(20)
turtle.pendown()
turtle.fd(20)
turtle.penup()
turtle.bk(30)
turtle.circle(190,90)
turtle.pendown()
turtle.bk(30)
turtle.fd(60)
turtle.penup()
turtle.circle(10,180)
turtle.pendown()
turtle.fd(20)
turtle.penup()
turtle.fd(20)
turtle.pendown()
turtle.fd(20)
turtle.penup()
turtle.circle(-10,180)
turtle.pendown()
turtle.fd(20)
turtle.penup()
turtle.fd(20)
turtle.pendown()
turtle.fd(20)
turtle.penup()
turtle.bk(30)
turtle.circle(150,180)
turtle.pendown()
turtle.bk(30)
turtle.fd(60)
turtle.penup()
turtle.circle(-10,180)
turtle.pendown()
turtle.fd(60)
turtle.penup()
turtle.circle(10,180)
turtle.pendown()
turtle.fd(20)
turtle.penup()
turtle.fd(20)
turtle.pendown()
turtle.fd(20)
turtle.pensize(1)
turtle.done()
![太极八卦](https://i-blog.csdnimg.cn/blog_migrate/9b0042bbe91cd2c891a897aa10fc1437.jpeg)