目录
python入门高阶练习之turtle库与random函数
Turtle库是Python语言中一个很流行的绘制图像的函数库。
1) turtle.pensize():设置画笔的宽度;
2) turtle.pencolor():没有参数传入,返回当前画笔颜色,传入参数设置画笔颜色,可以是字符串如"green", "red",也可以是RGB 3元组。
3) turtle.speed(speed):设置画笔移动速度,画笔绘制的速度范围[0,10]整数,数字越大越快。
import turtle as t
t.pensize(5) #设置画笔的宽度
t.hideturtle() #隐藏画笔
t.colormode(255)
t.color((255,155,192),"pink")
t.setup(840,500) #起始位置
t.speed(8) #设置画笔移动速度
t.pu() #画笔抬起 penup
t.goto(-100,100)
t.pd() #画笔按下 pendown
t.seth(30) #设置朝向 30度
t.begin_fill()
t.circle(20)
t.color(160,11,11)
t.end_fill()
t.pu()#画笔抬起 penup
t.goto(-100,100)
t.pd()#画笔按下 pendown
t.begin_fill()
t.seth(-10)#设置方向
t.fillcolor('yellow')
t.circle(20)
t.end_fill()
t.begin_fill()
t.seth(10)
t.fillcolor('black')
t.circle(10)
t.end_fill()
t.pu()#画笔抬起 penup
t.goto(-200,100)
t.pd()#画笔按下 pendown
t.begin_fill()
t.seth(-10)#设置方向
t.fillcolor('yellow')
t.circle(20)
t.end_fill()
t.begin_fill()
t.seth(10)
t.fillcolor('black')
t.circle(10)
t.end_fill()
t.pu()#画笔抬起 penup
t.goto(-180,50)
t.pd()#画笔按下 pendown
t.circle(-60, 60) # 半圆