首页 > 其他 > 详细

国际象棋棋盘

时间:2020-10-06 21:59:08      阅读:88      评论:0      收藏:0      [点我收藏+]
import turtle

n = 60
x = -300
y = -300


def main():
    turtle.speed(11)
    turtle.pensize(2)
    turtle.penup()
    for i in range(8):
        for j in range(8):
            turtle.goto(x + i * n, y + j * n)
            if (i + j) % 2 == 0:
                draw_square(n, "white")
            elif (i + j) % 2 == 1:
                draw_square(n, "black")
    x1 = x - n * 0.12
    y1 = y - n * 0.12
    n1 = n * 8 + 2 * n * 0.12
    turtle.goto(x1, y1)
    turtle.pensize(4)
    draw_square_2(n1)
    x2 = x - n * 0.3
    y2 = y - n * 0.3
    n2 = n * 8 + 2 * n * 0.3
    turtle.goto(x2, y2)
    turtle.pensize(10)
    draw_square_2(n2)
    turtle.hideturtle()
    turtle.done()


def draw_square(length: float, fill_color: str):
    turtle.pendown()
    turtle.begin_fill()
    turtle.fillcolor(fill_color)
    for index in range(4):
        turtle.forward(length)
        turtle.left(90)
    turtle.end_fill()
    turtle.penup()


def draw_square_2(length: float):
    turtle.pendown()
    for index in range(4):
        turtle.forward(length)
        turtle.left(90)
    turtle.penup()


if __name__ == __main__:
    main()

技术分享图片

 

国际象棋棋盘

原文:https://www.cnblogs.com/hjli/p/13773710.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!