python里面有一个库是可以绘画的,我们成为小海龟,turtle库,通过这个库我们可以绘画出很多样式的图像。
例如
接下来教大家一点函数。
from turtle import * # 导入turtle库 import turtle也行hideturtle()# 隐藏箭头pencolor("pink")# 设置画笔颜色为粉色penup()# 提笔pensize(2) # 设置画笔大小为2pendown() # 放笔 showturtle()# 显示箭头left()# 向左旋转多少度right()# 向右旋转多少度circle(radius,extent,steps)# 画圆,randius=半径,正数往左边画,负数往右边画,extent=角度,steps=多边形
这个库是基于坐标的。通过这个函数可以使箭头去到各种位置。
goto(0,0)# 去到(0,0)这个坐标
以上是turtle库的基本函数用法,下面画完图形之后需要填充颜色,但需要完全闭合起来,不然会填充成各种各样的形状。
fillcolor("pink") # 填充颜色为粉色begin_fill() # 开始填充... # 图形内容end_fill()# 完成填充
还有绘画完图像,停止不动的函数。
done()
以下代码展示
from turtle import *hideturtle()penup()pensize(2)fillcolor("pink")begin_fill()goto(-150,100)pendown()showturtle()pencolor("pink")left(120)circle(100,180)left(12)fd(260)left(96)fd(260)left(13)circle(100,180)hideturtle()end_fill()fillcolor("pink")begin_fill()penup()goto(100, 200)pendown()showturtle()left(240)circle(121,180)left(15)fd(292)left(90)fd(292)left(15)circle(121,180)end_fill()hideturtle()penup()pencolor("yellow")goto(-400,-130)pendown()showturtle()right(215)fd(300)penup()goto(35,80)pendown()fd(110)penup()goto(305,205)pendown()fd(100)done()
写的不好,仅供参考!!!
如果觉得《python_turtle库丘比特之箭》对你有帮助,请点赞、收藏,并留下你的观点哦!