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

python3 turtle 画国际象棋棋盘

时间:2018-06-26 23:52:25      阅读:930      评论:0      收藏:0      [点我收藏+]

标签:象棋   src   python3   国际   got   技术   IV   --   hid   

python3 turtle 画国际象棋棋盘

 

#!/usr/bin/env python
# -*- coding:utf-8 -*-
# Author:Hiuhung Wan

import turtle

n = 60  # 每行间隔
x = -300   #  x初始值
y = -300   #  x初始值

turtle.speed(11)
turtle.pensize(2)
# 先画8*8的正方形,并按要求涂黑
for i in range(8):
    for j in range(1, 9):
        turtle.penup()
        turtle.goto(x + i * n, y + j * n )
        turtle.pendown()
        if (i + j) % 2 == 1:   #不涂黑
            for index in range(4):
                turtle.forward(n)
                turtle.left(90)
        elif (i + j) % 2 == 0:  #涂黑
            turtle.begin_fill()
            turtle.fillcolor(‘black‘)
            for index in range(4):
                turtle.forward(n)
                turtle.left(90)
            turtle.end_fill()
        turtle.penup()

# 再画外面两个正方形
x1 = x - n * 0.12
y1 = y - n * 0.12 + n
turtle.goto(x1, y1)
turtle.pendown()
turtle.pensize(4)
for index in range(4):
    turtle.forward(n * 8 + 2 * n * 0.12)
    turtle.left(90)
turtle.penup()
# -----------------------------------------------

x2 = x - n * 0.3
y2 = y - n * 0.3 + n
turtle.goto(x2, y2)
turtle.pendown()
turtle.pensize(10)
for index in range(4):
    turtle.forward(n * 8 + 2 * n * 0.3)
    turtle.left(90)

turtle.hideturtle()
turtle.done()

  效果图如下:

技术分享图片

python3 turtle 画国际象棋棋盘

标签:象棋   src   python3   国际   got   技术   IV   --   hid   

原文地址:https://www.cnblogs.com/hiuhungwan/p/9231685.html

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