python用turtle画国际象棋棋盘
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python用turtle画国际象棋棋盘相关的知识,希望对你有一定的参考价值。
python学习的练习
用turtle画的国际象棋棋盘
import turtle
turtle.speed(10)
a = 30
#画背景
turtle.up()
turtle.goto( -10, -10)
turtle.down()
turtle.fillcolor("Khaki")
turtle.begin_fill()
turtle.fd( a * 8 + 20)
turtle.left(90)
turtle.fd( a * 8 + 20)
turtle.left(90)
turtle.fd( a * 8 + 20)
turtle.left(90)
turtle.fd( a * 8 + 20)
turtle.left(90)
turtle.end_fill()
#画黑格
for i in range(8):
if i % 2 == 0:#偶数行
turtle.up()
turtle.goto(0, i * a)
turtle.down()
for j in range(4):
turtle.fillcolor("black")
turtle.begin_fill()
turtle.fd( a )
turtle.left(90)
turtle.fd( a )
turtle.left(90)
turtle.fd( a )
turtle.left(90)
turtle.fd( a )
turtle.left(90)
turtle.end_fill()
turtle.up()
turtle.fd(a * 2)
turtle.down()
else:#奇数行
turtle.up()
turtle.goto(a , a * i)
turtle.down()
for n in range( 4 ):
turtle.fillcolor("black")
turtle.begin_fill()
turtle.fd( a )
turtle.left(90)
turtle.fd( a )
turtle.left(90)
turtle.fd( a )
turtle.left(90)
turtle.fd( a )
turtle.left( 90 )
turtle.end_fill()
turtle.up()
turtle.fd( a * 2 )
turtle.down()
#画白格
turtle.up()
turtle.goto(0, 0)
turtle.down()
turtle.fd( a * 8 )
turtle.left(90)
turtle.fd( a * 8 )
turtle.left(90)
turtle.fd( a * 8 )
turtle.left(90)
turtle.fd( a * 8 )
turtle.left(90)
turtle.done()
成果
以上是关于python用turtle画国际象棋棋盘的主要内容,如果未能解决你的问题,请参考以下文章