码迷,mamicode.com
首页 > 编程语言 > 详细

python用turtle画国际象棋棋盘

时间:2018-02-07 10:20:12      阅读:1021      评论:0      收藏:0      [点我收藏+]

标签: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()

成果

技术分享图片

python用turtle画国际象棋棋盘

标签:src   国际   python学习   end   img   port   图片   练习   技术分享   

原文地址:http://blog.51cto.com/12068679/2069682

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!