Python太极图代码
时间: 2023-11-19 09:50:36 浏览: 159
好的,以下是Python实现太极图的代码:
```python
import turtle
# 设置画布大小和背景色
turtle.setup(600, 600)
turtle.bgcolor('black')
# 定义画圆弧的函数
def draw_arc(radius, angle, color):
turtle.fillcolor(color)
turtle.begin_fill()
turtle.circle(radius, angle)
turtle.right(180 - angle)
turtle.circle(-radius, angle)
turtle.right(180)
turtle.end_fill()
# 画白色半圆
turtle.penup()
turtle.goto(0, 200)
turtle.pendown()
draw_arc(200, 180, 'white')
# 画黑色半圆
turtle.penup()
turtle.goto(0, -200)
turtle.pendown()
draw_arc(200, 180, 'black')
# 画白色小圆
turtle.penup()
turtle.goto(0, 80)
turtle.pendown()
turtle.fillcolor('white')
turtle.begin_fill()
turtle.circle(80)
turtle.end_fill()
# 画黑色小圆
turtle.penup()
turtle.goto(0, -80)
turtle.pendown()
turtle.fillcolor('black')
turtle.begin_fill()
turtle.circle(80)
turtle.end_fill()
# 隐藏画笔
turtle.hideturtle()
# 等待用户关闭窗口
turtle.done()
```
阅读全文