python绘制一个简易八卦图
时间: 2023-07-04 07:19:39 浏览: 202
气象领域python色斑图绘制程序
5星 · 资源好评率100%
好的,以下是Python绘制简易八卦图的代码:
```python
import turtle
# 创建画布和画笔
canvas = turtle.Screen()
pen = turtle.Turtle()
# 绘制圆形
def draw_circle(color, radius, x, y):
pen.penup()
pen.fillcolor(color)
pen.goto(x, y)
pen.pendown()
pen.begin_fill()
pen.circle(radius)
pen.end_fill()
# 绘制半圆形
def draw_half_circle(color, radius, x, y):
pen.penup()
pen.goto(x, y)
pen.pendown()
pen.color(color)
pen.circle(radius, 180)
# 绘制八卦图
def draw_yin_yang():
draw_circle("black", 100, 0, 0)
draw_half_circle("white", 50, 0, 100)
draw_half_circle("black", 50, 0, -100)
draw_circle("white", 10, 0, 50)
draw_circle("black", 10, 0, -50)
# 调用绘制函数
draw_yin_yang()
# 隐藏画笔
pen.hideturtle()
# 显示画布
canvas.mainloop()
```
运行后可以看到绘制出来的简易八卦图。
阅读全文