我们一生之中,要牢记和要忘记的东西一样多。其实人生最好的贵人,就是不断努力的自己!靠自己,最踏实!假期很短暂,快乐却无边,工作很苦闷,赚钱最重要,陶醉在假期的快乐中,奋斗在工作的战线中,苦中寻乐一点甜,快乐与你长相伴。
本文实例为大家分享了python图形工具turtle绘制国际象棋棋盘的具体代码,供大家参考,具体内容如下
#编写程序绘制一个国际象棋的棋盘 import turtle turtle.speed(30) turtle.penup() off = True for y in range(-40, 30 + 1, 10): for x in range(-40, 30 + 1, 10): if off: turtle.goto(x, y) turtle.pendown() turtle.begin_fill() turtle.color("black") turtle.forward(10) turtle.left(90) turtle.forward(10) turtle.left(90) turtle.forward(10) turtle.left(90) turtle.forward(10) turtle.left(90) turtle.end_fill() turtle.penup() else: turtle.goto(x, y) turtle.pendown() turtle.forward(10) turtle.left(90) turtle.forward(10) turtle.left(90) turtle.forward(10) turtle.left(90) turtle.forward(10) turtle.left(90) turtle.penup() off = bool(int(off) - 1) off = bool(int(off) - 1) turtle.hideturtle() turtle.done()
通过函数的重用优化代码:
先建立一个UsefulTurtleFunctions.py 的文件夹
import turtle #Draw a square def drawSquare(): turtle.pendown() turtle.forward(10) turtle.left(90) turtle.forward(10) turtle.left(90) turtle.forward(10) turtle.left(90) turtle.forward(10) turtle.left(90) turtle.penup()
再在test中调用它
#编写程序绘制一个国际象棋的棋盘 import turtle from UsefulTurtleFunctions import * turtle.speed(30) turtle.penup() off = True for y in range(-40, 30 + 1, 10): for x in range(-40, 30 + 1, 10): if off: turtle.goto(x, y) turtle.begin_fill() turtle.color("black") drawSquare() turtle.end_fill() turtle.penup() else: turtle.goto(x, y) drawSquare() off = bool(int(off) - 1) off = bool(int(off) - 1) turtle.hideturtle() turtle.done()
最后结果:
以上就是python图形工具turtle绘制国际象棋棋盘。市场比作一块蛋糕。我们不过分地在现有市场抢占份额,而是去另创造一个市场,即另做一个蛋糕——另做一个蛋糕独享。更多关于python图形工具turtle绘制国际象棋棋盘请关注haodaima.com其它相关文章!