Python画一个太极图代码1

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)          #加速绘制
turtle.bgcolor("white")

# 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()

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
要用Python一个太极图,你可以使用matplotlib库,这是一个非常流行的绘图库,它提供了一个类似于MATLAB的绘图环境。以下是一个简单的代码示例,展示如何使用matplotlib来绘制一个太极图: ```python import matplotlib.pyplot as plt import numpy as np def taiji(): fig = plt.figure(figsize=(6, 6)) ax = fig.add_axes([0,0,1,1]) ax.set_aspect('equal') ax.axis('off') # 关闭坐标轴 # 太极图的外圆 circle = plt.Circle((0.5, 0.5), 0.4, color='black') ax.add_artist(circle) # 太极图的两个半圆 left_circle = plt.Circle((0.5, 0.5), 0.4, color='white', clip_on=False) right_circle = plt.Circle((0.5, 0.5), 0.2, color='black', clip_on=False) ax.add_artist(left_circle) ax.add_artist(right_circle) # 太极图中的两个小圆 small_black = plt.Circle((0.5, 0.5), 0.1, color='black') small_white = plt.Circle((0.5, 0.5), 0.05, color='white') ax.add_artist(small_black) ax.add_artist(small_white) # 太极图中的鱼眼 left_eye = plt.Circle((0.35, 0.5), 0.03, color='black') right_eye = plt.Circle((0.65, 0.5), 0.03, color='white') ax.add_artist(left_eye) ax.add_artist(right_eye) # 绘制阴阳鱼的鱼身 theta = np.linspace(0, np.pi, 100) x_black = 0.5 + 0.1 * np.sin(theta) * np.cos(theta * 4) y_black = 0.5 + 0.1 * np.sin(theta) * np.sin(theta * 4) ax.fill_between(x_black, y_black, 0.5 - 0.2 * np.sin(theta), color='black') x_white = 0.5 + 0.1 * np.sin(theta) * np.cos(theta * 4) y_white = 0.5 + 0.1 * np.sin(theta) * np.sin(theta * 4) ax.fill_between(x_white, y_white, 0.5 + 0.2 * np.sin(theta), color='white') plt.show() if __name__ == '__main__': taiji() ``` 这段代码首先定义了一个绘制太极图的函数`taiji`,然后在主函数中调用这个函数来显示太极图代码中使用了`plt.Circle`来绘制不同颜色和大小的圆,以及`plt.fill_between`来填充阴阳鱼的形状。运行这段代码后,你会看到一个太极图
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

EYYLTV

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值