【Turtle画图】实现围棋棋盘,棋盘由纵横各19条线组成,每一个小格子为40X40的正方形,画布设置为800X800,背景色为"#E6B380",要求在棋盘上标注出来9个星位,星位上为半径为3的实心黑色圆。
时间: 2024-03-11 21:50:34 浏览: 95
Python turtle绘画象棋棋盘
好的,我可以为你提供一个实现围棋棋盘的Turtle画图代码。下面是代码:
```python
import turtle
# 设置画布大小为800x800
turtle.setup(800, 800)
# 设置背景色
turtle.bgcolor("#E6B380")
# 创建画笔
pen = turtle.Turtle()
# 设置画笔颜色和粗细
pen.color("#000000")
pen.pensize(2)
# 画横线
for i in range(19):
pen.penup()
pen.goto(-360, 180 - i * 40)
pen.pendown()
pen.forward(720)
# 画竖线
pen.left(90)
for i in range(19):
pen.penup()
pen.goto(-360 + i * 40, 180)
pen.pendown()
pen.forward(720)
# 画星位
pen.penup()
pen.goto(-120, 120)
pen.dot(6, "#000000")
pen.goto(0, 120)
pen.dot(6, "#000000")
pen.goto(120, 120)
pen.dot(6, "#000000")
pen.goto(-120, 0)
pen.dot(6, "#000000")
pen.goto(0, 0)
pen.dot(6, "#000000")
pen.goto(120, 0)
pen.dot(6, "#000000")
pen.goto(-120, -120)
pen.dot(6, "#000000")
pen.goto(0, -120)
pen.dot(6, "#000000")
pen.goto(120, -120)
pen.dot(6, "#000000")
# 隐藏画笔
pen.hideturtle()
# 显示画布
turtle.done()
```
运行代码后,会在窗口中显示一个围棋棋盘,其中包含19x19的网格和9个星位。棋盘上的每个小格子大小为40x40,背景色为"#E6B380",星位为半径为3的实心黑色圆。希望这个代码对你有帮助。
阅读全文