标签:src 国际 python学习 end img port 图片 练习 技术分享
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()
成果
标签:src 国际 python学习 end img port 图片 练习 技术分享
原文地址:http://blog.51cto.com/12068679/2069682