欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

小白python学习笔记02:turtle绘图

程序员文章站 2022-05-28 19:37:47
...

小白python学习笔记02:turtle绘图
实例2:python蟒蛇绘制

#PythonDraw.py
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()

1.1库引用import保留字

方法一:import<库名>,
调用函数用<库名><函数名><函数参数>
方法二:from<库名>import*
调用函数:<函数名><函数参数>
小白python学习笔记02:turtle绘图

方法三:import<库名>as<函数名>
调用函数:<库别名><函数名><函数参数>
小白python学习笔记02:turtle绘图

1.2绘图坐标体系及建立

建立:setup(width,height,startx,starty)
小白python学习笔记02:turtle绘图

1.3画笔控制函数

1.3.1 penup():别名pu(),抬起画笔。
1.3.2 pendown():别名pd(),落笔
1.3.3 pensize(width):画笔宽度
1.3.4 pencolor(color):画笔颜色
1.3.5 RGB色彩体系:很多RGB颜色有固定英文名,例如white、red等,没名字的可用(r,g,b)来描述小白python学习笔记02:turtle绘图
小白python学习笔记02:turtle绘图

1.4海龟控制函数

1.4.1 forward(d):别名fd(d),前进d,d可负。
1.4.2 circle(r,extent):在海龟左侧r处画一个半径为r,弧度为extent的弧。extent默认为360°。
小白python学习笔记02:turtle绘图
1.4.3 setheading(to_angle):别名seth(),设置海龟当前行进方向为to_angle,to_angle为角度的整数值。小白python学习笔记02:turtle绘图
1.4.4 left(angle):海龟左转angle角度。
1.4.5 right(angle):海龟右转angle角度。

相关标签: python