给我提供一个画图的代码,我要画八卦图
时间: 2024-04-17 11:26:49 浏览: 196
当然可以!下面是一个使用Python绘制八卦图的代码示例:
```python
import turtle
# 初始化画布
window = turtle.Screen()
window.bgcolor("white")
# 创建黑色半圆
black_pen = turtle.Turtle()
black_pen.shape("turtle")
black_pen.color("black")
black_pen.speed(0)
black_pen.begin_fill()
black_pen.circle(100, 180)
black_pen.circle(50, 180)
black_pen.left(180)
black_pen.circle(-50, 180)
black_pen.end_fill()
# 创建白色半圆
white_pen = turtle.Turtle()
white_pen.shape("turtle")
white_pen.color("white")
white_pen.speed(0)
white_pen.penup()
white_pen.goto(0, -100)
white_pen.pendown()
white_pen.begin_fill()
white_pen.circle(100, -180)
white_pen.circle(50, -180)
white_pen.left(180)
white_pen.circle(-50, -180)
white_pen.end_fill()
# 隐藏画笔
black_pen.hideturtle()
white_pen.hideturtle()
# 结束绘画
turtle.done()
```
运行这段代码,你将得到一个绘制八卦图的窗口。希望你喜欢!
阅读全文