用python画一个围棋盘

2020-03-06 21:24:00
key10
原创
930
turtle.title('围棋棋盘')
g = 20
num_x = 18
num_y = 18
r = 4
j = 3
turtle.speed(10)
# 绘制横线
ruler_y = ['一', '二', '三', '四', '五', '六', '七', '八', '九', '十', '十一',  '十二', '十三', '十四', '十五', '十六', '十七', '十八', '十九']
for x in range(num_x + 1):
    if (x == 0) or (x == num_x):
        turtle.pensize(3)
    else:
        turtle.pensize(1)
    #  画线
    turtle.up()
    turtle.goto(-num_y / 2 * g, num_x / 2 * g - g * x)
    turtle.down()
    turtle.forward(num_y * g)
    # 写字
    turtle.up()
    turtle.goto(-num_y / 2 * g - g, num_x / 2 * g - g * x - g / 2)
    turtle.write(ruler_y[x], align="center", font=("Courier", 14, "bold"))
    turtle.down()
# 绘制竖线
turtle.right(90)
for x in range(num_y + 1):
    if (x == 0) or (x == num_y):
        turtle.pensize(3)
    else:
        turtle.pensize(1)
    # 画竖线
    turtle.up()
    turtle.goto(-num_y / 2 * g + g * x, num_x / 2 * g)
    turtle.down()
    turtle.forward(num_x * g)
    # 写字
    turtle.up()
    turtle.goto(-num_y / 2 * g + g * x, num_x / 2 * g + g / 2)
    turtle.write(x + 1, align="center", font=("Courier", 14, "bold"))
    turtle.down()
#  绘画棋盘圆点
turtle.pensize(1)
for x in range(3):
    for y in range(3):
        turtle.up()
        turtle.begin_fill()
        turtle.fillcolor('black')
        turtle.goto(-num_y / 2 * g + (j * g) * 2 * y + (j * g) - r, num_x / 2 * g - (j * g) - (j * g) * 2 * x)
        turtle.down()
        turtle.circle(r)
        turtle.end_fill()
turtle.hideturtle()

turtle.done()

文章分类
联系我们
联系人: 周老师
QQ: 3435593559
微信: thisfocus
微博: key10key10
百度统计