Python小海龟画图

import turtle


'''
运动命令
forward(d) 向前移动d长度
backward(d) 向后移动d长度
right(d) 向右移动d长度
left(d) 向左一定d长度
goto(x,y) 移动到坐标为(x,y)的位置
speed(speed) 笔划绘制的速度1-10

笔画控制命令
up() 笔画抬起,在移动的时候不会绘图
down() 笔画落下,下次绘图时则有效
setheading(d) 改变海龟的朝向
pensize(d) 笔画的宽度
pencolor("red") 笔画的颜色
reset() 清空窗口,重置turtle状态
clear() 清空窗口,补充子turtle状态
circle(r,e) 绘制一个圆形,r为半径,e为次数(几次画出这个圆)

begin_fill() 开始填充
fillcolor(colorstr) 填充
end_fill() 结束填充

其他命令:
done() 程序继续执行
undo() 撤销上一次执行
hideturtle() 隐藏海龟
show() 显示海龟
screensize(x,y)  
'''

#乘法表
num = -400
num1 = 300
turtle.speed(10)
for x in range(0,9):
    turtle.up()
    turtle.goto(num, num1)
    turtle.down()
    num1 -= 30
    for i in range(0,x):
        turtle.forward(80)
        turtle.left(90)
        turtle.forward(30)
        turtle.left(90)
        turtle.forward(80)
        turtle.left(90)
        turtle.forward(30)
        turtle.left(90)
        turtle.forward(80)




#正方形
turtle.forward(100)
turtle.left(90)
turtle.forward(100)
turtle.left(90)
turtle.forward(100)
turtle.left(90)
turtle.forward(100)


#正方体

turtle.forward(100)
turtle.left(45)
turtle.forward(40)
turtle.left(45)
turtle.forward(100)
turtle.left(90)
turtle.forward(100)
turtle.left(90)
turtle.forward(100)
turtle.right(45)
turtle.forward(40)
turtle.right(135)
turtle.forward(100)
turtle.right(45)
turtle.forward(40)
turtle.goto(0,100)
turtle.right(45)
turtle.forward(100)
turtle.left(45)
turtle.forward(40)
turtle.goto(100,100)
turtle.right(135)
turtle.forward(100)
turtle.right(90)
turtle.up()
turtle.goto(0,0)
turtle.right(135)
turtle.forward(40)
turtle.right(45)
turtle.down()
turtle.forward(100)


#五角星

turtle.pencolor("red")
turtle.forward(130)
turtle.right(135)
turtle.forward(130)
turtle.right(150)
turtle.forward(140)
turtle.right(150)
turtle.forward(140)
turtle.right(150)
turtle.forward(140)




#五环
turtle.pencolor("blue")
turtle.circle(50)
turtle.up()
turtle.forward(70)
turtle.down()
turtle.pencolor("black")
turtle.circle(50)
turtle.up()
turtle.forward(70)
turtle.down()
turtle.pencolor("red")
turtle.circle(50)
turtle.up()
turtle.forward(70)
turtle.up()
turtle.goto(30,-50)
turtle.down()
turtle.pencolor("orange")
turtle.circle(50)
turtle.up()
turtle.forward(70)
turtle.down()
turtle.pencolor("green")
turtle.circle(50)



turtle.done()

 

你可能感兴趣的:(零散代码,其他文章,Python)