用python画太极图的代码
时间: 2023-04-09 10:02:56 浏览: 114
以下是用Python画太极图的代码:
```python
import turtle
# 设置画布大小和背景颜色
turtle.setup(600, 600)
turtle.bgcolor("black")
# 定义画圆函数
def draw_circle(color, radius, position):
turtle.penup()
turtle.goto(position)
turtle.pendown()
turtle.fillcolor(color)
turtle.begin_fill()
turtle.circle(radius)
turtle.end_fill()
# 画黑色半圆
draw_circle("black", 200, (0, 0))
turtle.setheading(180)
turtle.circle(200, 180)
# 画白色半圆
draw_circle("white", 200, (0, 0))
turtle.setheading(0)
turtle.circle(-200, 180)
# 画黑色小圆
draw_circle("black", 50, (0, 100))
# 画白色小圆
draw_circle("white", 50, (0, -100))
# 隐藏画笔
turtle.hideturtle()
# 等待用户关闭窗口
turtle.done()
```
希望能帮到你!
相关问题
用python画出太极图代码
以下是用 Python 画出太极图的代码:
```python
import turtle
# 设置画布大小和背景颜色
turtle.setup(500, 500)
turtle.bgcolor("black")
# 定义画圆函数
def draw_circle(color, radius, position):
turtle.penup()
turtle.goto(position)
turtle.pendown()
turtle.fillcolor(color)
turtle.begin_fill()
turtle.circle(radius)
turtle.end_fill()
# 画黑色半圆
draw_circle("black", 200, (0, 100))
turtle.right(180)
turtle.circle(200, 180)
# 画白色半圆
draw_circle("white", 200, (0, -100))
turtle.right(180)
turtle.circle(-200, 180)
# 画黑色小圆
draw_circle("black", 50, (0, 50))
# 画白色小圆
draw_circle("white", 50, (0, -50))
# 隐藏画笔
turtle.hideturtle()
# 显示画布
turtle.done()
```
希望能对你有所帮助!
python画太极八卦图代码
以下是Python画太极八卦图的代码:
```python
import turtle as t
# 设置背景和笔的移动速度及大小
t.bgcolor('yellow')
t.speed(10)
t.pensize(6)
# 画黑色的半圆
t.fillcolor("black")
t.begin_fill()
t.circle(100,180)
t.left(0)
t.circle(50,180)
t.circle(-50,180)
t.end_fill()
# 画白色的半圆
t.fillcolor("white")
t.begin_fill()
t.circle(-100,180)
t.left(180)
t.circle(50,180)
t.circle(-50,180)
t.end_fill()
# 在黑圆画白色的点
t.left(180)
t.up()
t.goto(10,150)
t.down()
t.pencolor("white")
t.fillcolor("white")
t.begin_fill()
t.circle(13)
t.end_fill()
# 在白圆画黑色的点
t.up()
t.goto(-10,30)
t.fillcolor("black")
.begin_fill()
t.circle(15)
t.end_fill()
t.pencolor('blue')
t.goto(1000,1000)
t.done()
```