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(10) #加速绘制
# Draw the black half
draw_half_yin_yang("black", 255, -50, -300)
# 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()