进一步地,我尝试学习了Python 的其中一个很是重要的函数库——turtle库python
这是一个用于python绘图的函数库,方便又好用!框架
对于它的安装,如今咱们所用的python 3的系统运用到的指令是:ide
pip3 install turtle函数
安装完以后就可使用它啦~这样就能够开始画画啦~(激动)学习
1、turtle库基本介绍:spa
python的turtle库是一个直观有趣的图形绘制的函数库;blog
turtle库有一个绘制框架:“”小乌龟”有转向,行进的动做,方向有“前进方向”,“后退方向”,“左侧方向”,“右侧方向"等,行进动做有“前进”,“后退”,“旋转”等;ip
2、开始绘图:ci
1.创建画布it
咱们能够用过代码setup()或screensize()创建一个窗口画布,咱们就能够在上面做画了!
我如今主要用setup(),其中setup(width,height,startx,starty)
前两个参数是设置屏幕的宽高比例;
后两个是设置窗口在屏幕的的位置;
2.设置画笔
对于画笔,我了解到有几个设置的函数(在引用了from turtle import*的状况下):
pensize()是画笔的大小,pensize(2)即说明画笔大小为2个像素点;
penup()是抬起画笔动做;
pendown()是放下画笔动做;
pencolor()是设置画笔的颜色……
恩,了解了这些,我已经能够开始好好利用个人画笔绘画了!
固然还少不了其余一些指令函数:
forward()/fd() #向前走
backward() #向后走
right(degree) #向右转
left(degree) #向左转
speed(speed) #绘画速度
begin_fill() #开始填充
end_fill() #结束填充……
了解到这些之后,就能够开始实战了!
3、个人做品:
1.画叠加的等边三角形
代码:
from turtle import*
pensize(3)
color('black','white')
penup()
begin_fill()
seth(90)
fd(50)
pendown()
seth(-120)
fd(200)
seth(0)
fd(200)
seth(120)
fd(100)
seth(180)
fd(100)
seth(-60)
fd(100)
seth(60)
fd(100)
seth(120)
fd(100)
end_fill()
done()
效果:
2.太极!!
代码:
from turtle import*
pensize(2)
color('black','black')
begin_fill()
circle(80)
end_fill()
begin_fill()
seth(180)
color('black','white')
seth(180)
circle(-80,180)
circle(-40,180)
end_fill()
begin_fill()
color('black','black')
circle(40,180)
end_fill()
penup()
seth(90)
fd(30)
seth(0)
pendown()
begin_fill()
color('black','white')
circle(10)
end_fill()
penup()
seth(90)
fd(80)
seth(0)
pendown()
begin_fill()
color('black','black')
circle(10)
end_fill()
done()
效果:
3.国际象棋盘
代码:
from turtle import*
import math
pensize(2)
speed(50)
temp=0
num=0
penup()
seth(120)
fd(150)
pendown()
seth(0)
for i in range(10):
for i in range(10):
if(temp%2==0):
begin_fill()
color('black','white')
for i in range(4):
fd(40)
right(90)
fd(40)
temp+=1
end_fill()
else:
begin_fill()
color('black','black')
for i in range(4):
fd(40)
right(90)
fd(40)
temp+=1
end_fill()
if(num%2==0):
right(90)
fd(80)
right(90)
num+=1
if(num==10):
break
else:
left(90)
left(90)
num+=1
penup()
seth(120)
fd(300)
pendown()
seth(-30) #写字开始
fd(45)
penup()
seth(194)
fd(70)
pendown()
seth(10)
fd(60)
right(100)
fd(90)
seth(30)
fd(20) #偏旁部首写完
penup()
seth(85)
fd(122)
pendown()
seth(0) #一横
fd(50)
penup()
seth(195)
fd(50)
pendown()
seth(0) #二横
fd(45)
penup()
seth(195)
fd(70)
pendown()
seth(0) #三横
fd(80)
penup()
seth(118)
fd(62)
pendown()
seth(-90)
fd(59) #右上结束
penup()
seth(-148)
fd(20)
pendown()
seth(-90)
fd(90)
seth(90)
fd(90)
seth(0)
fd(39)
right(90)
fd(92)
seth(120)
fd(15) #月外框结束
penup()
fd(55)
pendown()
seth(0)
fd(35)
penup()
seth(220)
fd(45)
pendown()
seth(0)
fd(35) #写字结束
hideturtle()
end_fill()
done()
(我还特意写了个字~~够酷吧!)
学到这,我深入认识到原来会用turtle库是多么有用!我甚至以为能够任意画图了!
Python太棒了!