python太极图代码
时间: 2023-05-14 18:06:55 浏览: 181
以下是一个简单的 Python 太极图代码:
```
import turtle
def draw_yin(radius):
turtle.circle(radius/2, 180)
turtle.circle(radius, 180)
turtle.circle(-radius/2, 180)
def draw_yang(radius):
turtle.circle(-radius/2, 180)
turtle.circle(radius, -180)
def draw_taiji(radius):
turtle.pensize(3)
turtle.penup()
turtle.goto(0, -radius)
turtle.pendown()
turtle.circle(radius)
turtle.penup()
turtle.goto(0, 0)
turtle.pendown()
turtle.fillcolor("black")
turtle.begin_fill()
draw_yin(radius)
turtle.end_fill()
turtle.fillcolor("white")
turtle.begin_fill()
draw_yang(radius)
turtle.end_fill()
turtle.speed(0)
draw_taiji(200)
turtle.done()
```
这个代码使用了 Python 的 turtle 库来绘制太极图。它定义了三个函数来绘制阴、阳两个半圆和太极图的外圆。最后,它使用 turtle 库的 fillcolor 和 begin_fill/end_fill 函数来填充黑白两个半圆。
阅读全文