import turtle
import math
def draw_circle(color, radius, x, y):
turtle.penup()
turtle.goto(x, y)
turtle.pendown()
turtle.color(color)
turtle.begin_fill()
turtle.circle(radius)
turtle.end_fill()
def draw_half_yin_yang(color, radius, x, y):
turtle.penup()
turtle.goto(x, y)
turtle.pendown()
turtle.color(color)
turtle.begin_fill()
turtle.circle(radius, 180)
turtle.circle(radius/2, -180)
turtle.circle(-radius/2, -180)
turtle.circle(-radius, 360)
turtle.end_fill()
def draw_yin_yang():
turtle.speed(0)
turtle.bgcolor(“white”)
# Draw the black half
draw_half_yin_yang("black", 255, -50, -300)
# Draw the white half
turtle.setheading(0)
draw_half_yin_yang("white", 0, 0, 0)
# Adjust the radius and positions of the small circles
draw_circle("white", 30, -50, 120)
draw_circle("black", 30, -50, -150)
turtle.hideturtle()
turtle.done()
运行绘制太极图的函数
draw_yin_yang()