python
真的好玩,功能强大,方便快捷,话不都说,自己感受。
import turtle #引入turtle外部库,turtle是python中一个绘制图像的外部库
def drawSnake(rad,angle,len,neckrad):#def定义函数,未经调用不能执行
for i in range (len):
turtle.circle(rad,angle)#轨迹为圆形,rad为半径(正代表圆心在左),angle为弧度值
turtle.circle(-rad,angle)
turtle.circle(rad,angle/2)
turtle.fd(rad)#直线爬行长度
turtle.circle(neckrad+1,180)
turtle.fd(rad*2/3)
def main():#def定义函数
turtle.setup(1300,800,0,0)#启动一个图形窗口(宽度,高度,窗口左上角在屏幕中的坐标位置)
pythonsize = 30
turtle.pensize(pythonsize)#表示小乌龟运动轨迹的宽度
turtle.pencolor("blue")#轨迹颜色
turtle.seth(-40)#轨迹的角度,上北90,下南270,左西180,右东0,负号方向相反
drawSnake(40,80,5,pythonsize/2)
main()#第一条执行语句
import turtle
def triangle(distance,len):
for i in range(len):
turtle.fd(distance)
turtle.seth(120)
turtle.fd(distance)
turtle.seth(240)
turtle.fd(distance)
def main():
turtle.setup(1300,800,0,0)
turtle.pencolor("blue")
triangle(250,1)
main()
加油!!!