赞
踩
1.用填充的方法画一个小方块。画一下旋转90度,画四下围成一个小方块
import turtle turtle.showturtle() step=20 turtle.begin_fill() for k in range(4): turtle.forward(step) turtle.right(90) turtle.end_fill() turtle.done()
运行
2.国际象棋是8*8的,所以设置8次的双循环,循环化上面的小方格,颜色先不管,就黑的就可以
import turtle turtle.showturtle() step=20 for i in range(8): for j in range(8): turtle.penup() turtle.goto(i*step,j*step) turtle.pendown() turtle.begin_fill() for k in range(4): turtle.forward(step) turtle.right(90) turtle.end_fill() turtle.done()
运行
3.黑白间隔做一下,用间隔输出就可以
import turtle turtle.showturtle() step=20 for i in range(8): for j in range(8): turtle.penup() turtle.goto(i*step,j*step) turtle.pendown() turtle.begin_fill() if (i+j)%2==0: turtle.color("white") else: turtle.color("black") for k in range(4): turtle.forward(step) turtle.right(90) turtle.end_fill() turtle.done()
运行一下:
4.调整下画笔的粗细,显得画面更好看
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。