使用ellipse绘制太极图
时间: 2024-03-01 08:37:50 浏览: 68
taijitu.rar_太极图
好的,下面是使用Python的turtle库绘制太极图的代码:
```python
import turtle
# 设置画布和画笔
canvas = turtle.Screen()
canvas.bgcolor("white")
pen = turtle.Turtle()
# 绘制黑白两个半圆
pen.penup()
pen.goto(0, 100)
pen.pendown()
pen.begin_fill()
pen.fillcolor("black")
pen.circle(100, 180)
pen.end_fill()
pen.penup()
pen.goto(0, -100)
pen.pendown()
pen.begin_fill()
pen.fillcolor("white")
pen.circle(100, 180)
pen.end_fill()
# 绘制小圆和阴阳两个小圆
pen.penup()
pen.goto(0, 50)
pen.pendown()
pen.begin_fill()
pen.fillcolor("white")
pen.circle(50)
pen.end_fill()
pen.penup()
pen.goto(0, -50)
pen.pendown()
pen.begin_fill()
pen.fillcolor("black")
pen.circle(50)
pen.end_fill()
pen.penup()
pen.goto(0, 90)
pen.pendown()
pen.circle(10)
pen.penup()
pen.goto(0, -90)
pen.pendown()
pen.circle(10)
# 隐藏画笔
pen.hideturtle()
# 关闭画布
canvas.exitonclick()
```
运行代码后,会弹出一个窗口显示绘制的太极图。图形如下:
![太极图](https://img-blog.csdnimg.cn/20210930201553265.png)
阅读全文