当前位置: 首页 > news >正文

Python绘制三十六计

胜战计(处于优势时使用的策略)

瞒天过海

备周则意怠,常见则不疑。阴在阳之内,不在阳之对。太阳,太阴。

通过伪装隐藏真实意图,在对方松懈时行动。

import numpy as np
import matplotlib.pyplot as plt
from matplotlib.patches import Rectangle, Polygon, Circle# 设置中文字体
plt.rcParams['font.sans-serif'] = ['SimHei']  # 用黑体显示中文
plt.rcParams['axes.unicode_minus'] = False  # 正常显示负号# 创建画布
fig, ax = plt.subplots(figsize=(14, 8), facecolor='#0a0a2a')
ax.set_xlim(0, 14)
ax.set_ylim(0, 8)
ax.axis('off')
plt.title('瞒天过海策略示意图', fontsize=18, color='white', pad=20)# 绘制天空和海洋
sky = Rectangle((0, 4), 14, 4, facecolor='#0a0a2a', edgecolor='none')
sea = Rectangle((0, 0), 14, 4, facecolor='#1a1a5a', edgecolor='none')
ax.add_patch(sky)
ax.add_patch(sea)# 添加星光
stars_x = np.random.uniform(0, 14, 50)
stars_y = np.random.uniform(4.5, 7.5, 50)
ax.scatter(stars_x, stars_y, s=np.random.uniform(0.5, 3, 50),color='white', alpha=0.7)# 绘制月亮
moon = Circle((2, 6.5), 0.8, color='#f0f0c0', alpha=0.9)
ax.add_patch(moon)# 绘制真实舰队(隐蔽航行)
real_ships = []
for i in range(5):x = 1 + i * 0.8y = 1.5 + np.random.uniform(-0.1, 0.1)# 船体hull = Polygon(np.array([  # 添加np.array转换[x, y],[x + 0.6, y],[x + 0.5, y + 0.3],[x + 0.1, y + 0.3]]), closed=True, color='#303030')# 船帆sail = Polygon(np.array([  # 添加np.array转换[x + 0.3, y + 0.3],[x + 0.3, y + 0.9],[x + 0.4, y + 0.9]]), closed=True, color='#202020')ax.add_patch(hull)ax.add_patch(sail)real_ships.extend([hull, sail])# 绘制假目标(诱敌)
decoy_ships = []
for i in range(3):x = 10 + i * 1.5y = 2.5# 船体(更大更显眼)sail = Polygon(np.array([[x + 0.6, y + 0.6], [x + 0.6, y + 1.8], [x + 0.8, y + 1.8]]),closed=True, color='#aaaaaa', alpha=0.7)# 船帆(亮色吸引注意)hull = Polygon(np.array([[x, y], [x + 1.2, y], [x + 1.0, y + 0.6], [x + 0.2, y + 0.6]]),closed=True, color='#555555', alpha=0.7)# 灯光(模拟活动)light = Circle((x + 0.7, y + 0.3), 0.15, color='yellow', alpha=0.6)ax.add_patch(hull)ax.add_patch(sail)ax.add_patch(light)decoy_ships.extend([hull, sail, light])# 添加策略说明
texts = [("真实行动", (1, 0.8), '#a0d0ff'),("伪装隐蔽", (1, 0.5), '#a0d0ff'),("夜间潜行", (1, 0.2), '#a0d0ff'),("虚假目标", (9.7, 3.5), '#ffa0a0'),("吸引注意", (9.7, 3.2), '#ffa0a0'),("声东击西", (9.7, 2.9), '#ffa0a0'),("瞒天过海:通过伪装隐藏真实意图,制造假象迷惑敌人", (7, 7.5), 'white')
]for text, pos, color in texts:ax.text(pos[0], pos[1], text, color=color, fontsize=10,ha='center', va='center', alpha=0.9)# 添加海峡两岸
left_coast = Polygon(np.array([[0, 4], [0, 8], [3, 4]]), closed=True, color='#1a5a1a')
right_coast = Polygon(np.array([[14, 4], [14, 8], [11, 4]]), closed=True, color='#1a5a1a')
ax.add_patch(left_coast)
ax.add_patch(right_coast)# 添加箭头表示行动方向
ax.arrow(3.5, 1.8, 5.0, 0, head_width=0.2, head_length=0.3,fc='#70c0ff', ec='none', alpha=0.7)# 添加波浪效果
wave_x = np.linspace(0, 14, 100)
wave_y = 4 + 0.1 * np.sin(10 * wave_x) + 0.05 * np.cos(15 * wave_x)
ax.plot(wave_x, wave_y, color='#40a0ff', alpha=0.3, linewidth=1.5)# 添加图例
legend_elements = [plt.Line2D([0], [0], marker='o', color='w', markerfacecolor='#303030', markersize=10, label='真实舰队'),plt.Line2D([0], [0], marker='o', color='w', markerfacecolor='#aaaaaa', markersize=10, label='诱敌目标'),plt.Line2D([0], [0], marker='>', color='#70c0ff', markersize=10, label='行动方向', linestyle='None')
]ax.legend(handles=legend_elements, loc='upper center',bbox_to_anchor=(0.5, -0.05), ncol=3,facecolor='#000020', edgecolor='none',labelcolor='white', fontsize=10)plt.tight_layout()
plt.savefig('瞒天过海.png', dpi=300, bbox_inches='tight', facecolor='#0a0a2a')
plt.show()

围魏救赵

共敌不如分敌,敌阳不如敌阴。

攻击敌人薄弱处,迫使主力回援,以解己方之围。

import numpy as np
import matplotlib.pyplot as plt
from matplotlib.patches import Circle, Rectangle# 设置中文字体
plt.rcParams['font.sans-serif'] = ['SimHei']  # 用黑体显示中文
plt.rcParams['axes.unicode_minus'] = False  # 正常显示负号# 创建画布
fig, ax = plt.subplots(figsize=(14, 8))
ax.set_xlim(0, 14)
ax.set_ylim(0, 8)
ax.axis('off')
plt.title('围魏救赵策略示意图', fontsize=18, pad=20)# 绘制地形背景
terrain = Rectangle((0, 0), 14, 8, facecolor='#e0e0c0', edgecolor='none')
ax.add_patch(terrain)# 绘制河流
river_x = np.linspace(2, 12, 100)
river_y = 4 + 0.3 * np.sin(0.8 * river_x)
ax.plot(river_x, river_y, color='#40a0ff', linewidth=4, alpha=0.7)
ax.fill_between(river_x, river_y, 8, color='#a0d0ff', alpha=0.3)# 绘制三个关键位置
def draw_city(x, y, name, color, size=0.8):city = Circle((x, y), size, color=color, alpha=0.9)ax.add_patch(city)ax.text(x, y, name, ha='center', va='center', color='white',fontsize=12, weight='bold')return city# 三个关键城市
zhao = draw_city(3, 6, '赵', '#3030a0')  # 赵国 (蓝色)
wei = draw_city(11, 5.4, '魏', '#a03030')  # 魏国 (红色)
qi = draw_city(7, 2.2, '齐', '#30a030')    # 齐国 (绿色)# 绘制魏国主力围攻赵国
def draw_army(x, y, color, size=20, direction=None):ax.scatter([x], [y], s=size, color=color, alpha=0.8)if direction:dx, dy = directionax.arrow(x, y, dx*0.5, dy*0.5, head_width=0.2, head_length=0.3,fc=color, ec=color, alpha=0.7)# 魏国主力围攻赵国 (红色)
for i in range(12):angle = i * 2 * np.pi / 12radius = 1.5 + np.random.uniform(0, 0.2)x = 3 + radius * np.cos(angle)y = 6 + radius * np.sin(angle)draw_army(x, y, '#d05050', 80, (-np.cos(angle)*0.5, -np.sin(angle)*0.5))# 赵国守军 (蓝色)
for i in range(5):angle = i * 2 * np.pi / 5radius = 0.8 + np.random.uniform(0, 0.1)x = 3 + radius * np.cos(angle)y = 6 + radius * np.sin(angle)draw_army(x, y, '#3060d0', 60)# 齐国军队行动路线 (绿色)
# 1. 齐国主力佯攻赵国方向
ax.plot([7, 5.5], [2, 3.5], 'g--', alpha=0.5)
draw_army(5.5, 3.5, '#30d030', 70, (0.5, 0.5))# 2. 实际分兵奔袭魏国
ax.plot([5.5, 11], [3.5, 5], 'g-', linewidth=2, alpha=0.8)
draw_army(8.5, 4.5, '#30d030', 100, (0.7, 0.3))# 3. 齐国军队抵达魏国都城
draw_army(10.5, 5.5, '#30d030', 120)
ax.plot([10.5, 11], [5.5, 5.8], 'g-', linewidth=2)
ax.plot([10.5, 10.8], [5.5, 5.2], 'g-', linewidth=2)# 魏国守军 (少量)
for i in range(4):angle = i * 2 * np.pi / 4radius = 0.6 + np.random.uniform(0, 0.1)x = 11 + radius * np.cos(angle)y = 6 + radius * np.sin(angle)draw_army(x, y, '#d05050', 50)# 魏国主力回援路线 (红色)
ax.plot([3, 11], [6, 5.5], 'r-', linewidth=2, alpha=0.6)
draw_army(7, 5.8, '#d05050', 90, (1.0, -0.1))# 添加策略说明
texts = [("1. 魏国主力围攻赵国", (3, 7.2), '#a03030'),("2. 齐国佯装救援赵国", (5, 3.0), '#30a030'),("3. 实际分兵奔袭魏国都城", (8.5, 4.0), '#30a030'),("4. 魏国主力被迫回援", (7, 6.2), '#a03030'),("5. 赵国危机解除", (3, 4.8), '#3030a0'),("围魏救赵:攻击敌人要害,迫使敌方主力回援", (7, 1), 'black'),("魏国", (11, 7.0), '#a03030'),("赵国", (3, 7.8), '#3030a0'),("齐国", (7, 1.2), '#30a030')
]for text, pos, color in texts:ax.text(pos[0], pos[1], text, color=color, fontsize=10,ha='center', va='center', weight='bold')# 添加图例
legend_elements = [plt.Line2D([0], [0], marker='o', color='w', markerfacecolor='#d05050', markersize=10, label='魏国军队'),plt.Line2D([0], [0], marker='o', color='w', markerfacecolor='#3060d0', markersize=10, label='赵国军队'),plt.Line2D([0], [0], marker='o', color='w', markerfacecolor='#30d030', markersize=10, label='齐国军队'),plt.Line2D([0], [0], marker='>', color='#30a030', markersize=10, label='齐国行动', linestyle='None'),plt.Line2D([0], [0], marker='>', color='#a03030', markersize=10, label='魏国行动', linestyle='None')
]ax.legend(handles=legend_elements, loc='lower center',bbox_to_anchor=(0.5, -0.05), ncol=3,facecolor='#f0f0f0', edgecolor='gray',fontsize=10)# 添加策略原理图
ax.text(1, 1.5, "策略原理:", fontsize=11, weight='bold')
ax.text(1, 1.0, "1. 避实击虚:攻击敌人薄弱环节", fontsize=10)
ax.text(1, 0.6, "2. 攻其必救:威胁敌人要害", fontsize=10)
ax.text(1, 0.2, "3. 以逸待劳:在敌回援途中设伏", fontsize=10)# 绘制时间线
timeline_x = [3, 5, 8, 11]
timeline_y = [0.4, 0.4, 0.4, 0.4]
ax.plot(timeline_x, timeline_y, 'k-', linewidth=1)
for i, label in enumerate(["初始", "佯攻", "奔袭", "回援"]):ax.plot([timeline_x[i], timeline_x[i]], [0.3, 0.5], 'k-', linewidth=1)ax.text(timeline_x[i], 0.6, f"阶段 {i+1}\n{label}", ha='center', fontsize=9)plt.tight_layout()
plt.savefig('围魏救赵.png', dpi=300, bbox_inches='tight')
plt.show()

借刀杀人

敌已明,友未定,引友杀敌,不自出力。

利用第三方力量打击对手,避免直接消耗。

import numpy as np
import matplotlib.pyplot as plt
from matplotlib.patches import Rectangle, Circle# 设置中文字体
plt.rcParams['font.sans-serif'] = ['SimHei']  # 用黑体显示中文
plt.rcParams['axes.unicode_minus'] = False  # 正常显示负号# 创建画布
fig, ax = plt.subplots(figsize=(14, 10))
ax.set_xlim(0, 14)
ax.set_ylim(0, 10)
ax.axis('off')
plt.title('借刀杀人策略示意图', fontsize=20, pad=20, weight='bold')# 设置背景为古代地图样式
map_bg = Rectangle((0, 0), 14, 10, facecolor='#f0e6d2', edgecolor='#8b7d6b', linewidth=2)
ax.add_patch(map_bg)# 绘制三个势力区域
def draw_kingdom(x, y, width, height, color, name):# 绘制领地territory = Rectangle((x, y), width, height,facecolor=color, alpha=0.2,edgecolor=color, linewidth=2)ax.add_patch(territory)# 绘制王座throne = Rectangle((x + width / 2 - 0.5, y + height - 1.5), 1, 1.5,facecolor='#d4af37', edgecolor='#8b7500', linewidth=1.5)ax.add_patch(throne)# 添加势力名称ax.text(x + width / 2, y + height - 0.7, name,fontsize=14, ha='center', va='center',weight='bold', color=color)# 返回领地中心坐标return x + width / 2, y + height / 2# 绘制三个势力
my_center = draw_kingdom(1, 1, 4, 4, '#3060a0', '我方势力')  # 蓝色
enemy_center = draw_kingdom(9, 1, 4, 4, '#a03030', '敌方势力')  # 红色
third_center = draw_kingdom(4, 6, 6, 3, '#30a030', '第三方势力')  # 绿色# 绘制势力代表
def draw_leader(x, y, color, size=0.5):leader = Circle((x, y), size, facecolor=color, edgecolor='black')ax.add_patch(leader)return leader# 添加领导者
me = draw_leader(my_center[0], my_center[1] - 1, '#3060a0')
enemy = draw_leader(enemy_center[0], enemy_center[1] - 1, '#a03030')
third_party = draw_leader(third_center[0], third_center[1] - 0.5, '#30a030')# 绘制策略步骤
step_texts = [("1. 制造矛盾", (third_center[0], enemy_center[1] + 1.5), '#a03030'),("散布谣言:敌方计划入侵第三方", (third_center[0], enemy_center[1] + 1.0), 'black'),("伪造证据:敌方与第三方敌人结盟", (third_center[0], enemy_center[1] + 0.5), 'black'),("2. 提供诱因", (third_center[0], third_center[1] - 1.5), '#30a030'),("承诺支援:提供情报和物资", (third_center[0], third_center[1] - 2.0), 'black'),("夸大利益:战胜后的领土分配", (third_center[0], third_center[1] - 2.5), 'black'),("3. 第三方行动", (enemy_center[0], enemy_center[1] + 2.8), '#30a030'),("第三方出兵攻击敌人", (enemy_center[0], enemy_center[1] + 2.5), 'black'),("双方消耗实力", (enemy_center[0], enemy_center[1] + 2.2), 'black'),("4. 坐收渔利", (my_center[0], my_center[1] + 2.8), '#3060a0'),("保存自身实力", (my_center[0], my_center[1] + 2.5), 'black'),("待两败俱伤后出击", (my_center[0], my_center[1] + 2.2), 'black'),("借刀杀人:借助第三方力量打击敌人,避免直接消耗", (7, 9.5), '#000000')
]for text, pos, color in step_texts:ax.text(pos[0], pos[1], text, ha='center', va='center',color=color, fontsize=10 if 'black' in color else 12)# 绘制信息流(谣言和诱因)
ax.annotate('', xy=(my_center[0] + 1, my_center[1] + 1.8),xytext=(third_center[0] - 1, third_center[1] - 0.5),arrowprops=dict(arrowstyle='->', color='#3060a0',linestyle='dashed', alpha=0.7),annotation_clip=False)ax.annotate('', xy=(my_center[0] + 1, my_center[1] + 1.5),xytext=(third_center[0] - 0.5, third_center[1] - 1.0),arrowprops=dict(arrowstyle='->', color='#3060a0',linestyle='dashed', alpha=0.7),annotation_clip=False)# 绘制第三方攻击敌人的行动
ax.annotate('', xy=(third_center[0] - 1, third_center[1] - 1.5),xytext=(enemy_center[0] + 0.5, enemy_center[1] + 1.0),arrowprops=dict(arrowstyle='->', color='#30a030',linewidth=2, alpha=0.8),annotation_clip=False)# 绘制战斗场景
def draw_battle(x, y):# 绘制冲突符号conflict = plt.text(x, y, '⚔', fontsize=24,ha='center', va='center', alpha=0.7)# 绘制爆炸效果for i in range(8):angle = i * np.pi / 4length = 0.5 + np.random.random() * 0.3dx = length * np.cos(angle)dy = length * np.sin(angle)ax.plot([x, x + dx], [y, y + dy], color='#ff3030', alpha=0.6)draw_battle(enemy_center[0], enemy_center[1] + 1.5)# 绘制资源流动
def draw_resource_flow(start, end, color, label):ax.annotate('', xy=end, xytext=start,arrowprops=dict(arrowstyle='fancy',color=color,connectionstyle="arc3,rad=-0.3",alpha=0.7))mid_x = (start[0] + end[0]) / 2mid_y = (start[1] + end[1]) / 2 + 0.5ax.text(mid_x, mid_y, label, color=color,ha='center', fontsize=9, style='italic')# 我方提供给第三方的资源
draw_resource_flow((my_center[0] + 1, my_center[1] + 0.5),(third_center[0] - 1, third_center[1] - 0.5),'#3060a0', '情报/物资')# 第三方损失的资源
draw_resource_flow((third_center[0] - 1, third_center[1] - 1),(enemy_center[0] + 1, enemy_center[1] + 1.5),'#30a030', '兵力消耗')# 敌方损失的资源
draw_resource_flow((enemy_center[0] - 1, enemy_center[1] + 1),(third_center[0] + 1, third_center[1] - 1.5),'#a03030', '领土损失')# 绘制策略原理图
principles = ["核心原理: 避免直接冲突","关键要素:","1. 寻找有利的'刀'(第三方力量)","2. 制造合理的'借口'(矛盾或利益)","3. 隐藏自身真实意图","4. 控制资源投入程度","5. 把握介入时机"
]for i, text in enumerate(principles):ax.text(11, 9.9 - i * 0.6, text, ha='left', va='top',fontsize=10 if i > 1 else (11 if i == 1 else 12),bbox=dict(facecolor='#f9f9e0', alpha=0.7, edgecolor='#d0d0a0') if i > 0 else None)# 绘制时间线
ax.plot([2, 12], [0.5, 0.5], 'k-', linewidth=1)
timeline_points = [3, 5, 8, 10]
timeline_labels = ["制造矛盾", "提供诱因", "第三方行动", "坐收渔利"]
for i, (x, label) in enumerate(zip(timeline_points, timeline_labels)):ax.plot([x, x], [0.4, 0.6], 'k-', linewidth=1)ax.text(x, 0.7, f"阶段 {i + 1}\n{label}", ha='center', fontsize=9)ax.text(x, 0.3, f"时间 +{i}", ha='center', fontsize=8, style='italic')# 添加图例
legend_elements = [plt.Line2D([0], [0], marker='o', color='w', markerfacecolor='#3060a0', markersize=10, label='我方势力'),plt.Line2D([0], [0], marker='o', color='w', markerfacecolor='#a03030', markersize=10, label='敌方势力'),plt.Line2D([0], [0], marker='o', color='w', markerfacecolor='#30a030', markersize=10, label='第三方势力'),plt.Line2D([0], [0], color='#3060a0', linestyle='dashed', label='信息操控'),plt.Line2D([0], [0], color='#30a030', label='攻击行动'),plt.Line2D([0], [0], color='#30a030', linestyle='-', label='资源流动')
]ax.legend(handles=legend_elements, loc='lower center',bbox_to_anchor=(0.5, -0.05), ncol=3,facecolor='#f0f0d0', edgecolor='#c0c0a0',fontsize=10)plt.tight_layout()
plt.savefig('借刀杀人.png', dpi=300, bbox_inches='tight', facecolor='#f0e6d2')
plt.show()

以逸待劳

困敌之势,不以战;损刚益柔。

养精蓄锐,待敌疲惫时出击。

import numpy as np
import matplotlib.pyplot as plt
from matplotlib.patches import Rectangle, Polygon, Circle, Ellipse, Arrow# 设置中文字体
plt.rcParams['font.sans-serif'] = ['SimHei']  # 用黑体显示中文
plt.rcParams['axes.unicode_minus'] = False  # 正常显示负号# 创建画布
fig, ax = plt.subplots(figsize=(14, 10))
ax.set_xlim(0, 14)
ax.set_ylim(0, 10)
ax.axis('off')
plt.title('以逸待劳策略示意图', fontsize=20, pad=20, weight='bold', color='#2c3e50')# 设置背景为战场地形
# 高地 - 我方阵地
hill = Polygon(np.array([(0, 0), (0, 6), (3, 7), (6, 8), (9, 7), (12, 6), (14, 5), (14, 0)]),closed=True, facecolor='#8e9e7e', edgecolor='#5a6b4c', alpha=0.9)
ax.add_patch(hill)# 平原 - 敌军行进区域
plain = Rectangle((0, 0), 14, 5, facecolor='#b8a07c', alpha=0.7, edgecolor='none')
ax.add_patch(plain)# 河流
river_x = np.linspace(1, 13, 100)
river_y = 1.5 + 0.3 * np.sin(0.7 * river_x)
ax.plot(river_x, river_y, color='#3498db', linewidth=3, alpha=0.8)
ax.fill_between(river_x, river_y, 0, color='#2980b9', alpha=0.3)# 添加树木
def draw_tree(x, y, size=1.0):trunk = Rectangle((x - 0.1 * size, y), 0.2 * size, 0.8 * size, facecolor='#8b4513')leaves = Ellipse((x, y + 1.2 * size), 1.2 * size, 1.5 * size, facecolor='#27ae60')ax.add_patch(trunk)ax.add_patch(leaves)for i in range(15):x = np.random.uniform(1, 13)y = np.random.uniform(0.5, 4.5)if 5 < x < 9:  # 避免在关键区域添加树木continuedraw_tree(x, y, size=np.random.uniform(0.7, 1.2))# 绘制我方军队 - 在高地上休整
def draw_soldier(x, y, color, resting=False, size=1.0):# 身体body = Ellipse((x, y), 0.5 * size, 0.8 * size, facecolor=color)# 头部head = Circle((x, y + 0.5 * size), 0.2 * size, facecolor='#f1c27d')if resting:# 休息姿势arm1 = Rectangle((x - 0.3 * size, y - 0.2 * size), 0.3 * size, 0.1 * size,facecolor=color, angle=30)arm2 = Rectangle((x + 0.1 * size, y - 0.1 * size), 0.3 * size, 0.1 * size,facecolor=color, angle=-20)# 闭眼eye = Polygon(np.array([[x - 0.1 * size, y + 0.55 * size],[x + 0.1 * size, y + 0.55 * size],[x + 0.05 * size, y + 0.52 * size]]),closed=True, facecolor='black')ax.add_patch(eye)else:# 站立姿势arm1 = Rectangle((x - 0.3 * size, y), 0.3 * size, 0.1 * size, facecolor=color, angle=45)arm2 = Rectangle((x + 0.1 * size, y), 0.3 * size, 0.1 * size, facecolor=color, angle=-45)# 眼睛eye1 = Circle((x - 0.08 * size, y + 0.55 * size), 0.03 * size, facecolor='black')eye2 = Circle((x + 0.08 * size, y + 0.55 * size), 0.03 * size, facecolor='black')ax.add_patch(eye1)ax.add_patch(eye2)# 腿leg1 = Rectangle((x - 0.15 * size, y - 0.5 * size), 0.15 * size, 0.6 * size, facecolor=color)leg2 = Rectangle((x, y - 0.5 * size), 0.15 * size, 0.6 * size, facecolor=color)ax.add_patch(body)ax.add_patch(head)ax.add_patch(arm1)ax.add_patch(arm2)ax.add_patch(leg1)ax.add_patch(leg2)return [body, head, arm1, arm2, leg1, leg2]# 我方军队在高地上休整(蓝色)
my_soldiers = []
for i in range(20):x = np.random.uniform(2, 12)y = np.random.uniform(6, 7.5)soldier = draw_soldier(x, y, '#3498db', resting=True, size=0.8)my_soldiers.extend(soldier)# 绘制帐篷
def draw_tent(x, y, size=1.0):# 帐篷主体tent = Polygon(np.array([[x, y + size],[x - 0.8 * size, y],[x + 0.8 * size, y]]),closed=True, facecolor='#e74c3c', edgecolor='#c0392b')# 门door = Rectangle((x - 0.2 * size, y), 0.4 * size, 0.3 * size, facecolor='#f39c12')ax.add_patch(tent)ax.add_patch(door)# 营地设施
draw_tent(4, 6.5, size=1.5)
draw_tent(8, 6.8, size=1.2)
draw_tent(10, 6.3, size=1.3)# 篝火
fire = plt.Circle((6, 6.5), 0.4, color='#e67e22', alpha=0.7)
ax.add_patch(fire)
for i in range(8):angle = np.random.uniform(0, 2 * np.pi)length = np.random.uniform(0.2, 0.6)dx = length * np.cos(angle)dy = length * np.sin(angle)ax.plot([6, 6 + dx], [6.5, 6.5 + dy], color='#f1c40f', linewidth=2, alpha=0.7)# 绘制敌军 - 在平原上行军疲惫
def draw_tired_soldier(x, y, color, size=1.0):# 身体(弯腰)body = Ellipse((x, y - 0.1 * size), 0.5 * size, 0.7 * size, facecolor=color)# 头部head = Circle((x, y + 0.2 * size), 0.2 * size, facecolor='#f1c27d')# 手臂(下垂)arm1 = Rectangle((x - 0.3 * size, y - 0.3 * size), 0.3 * size, 0.1 * size, facecolor=color, angle=-30)arm2 = Rectangle((x + 0.1 * size, y - 0.4 * size), 0.3 * size, 0.1 * size, facecolor=color, angle=20)# 腿(沉重)leg1 = Rectangle((x - 0.15 * size, y - 0.7 * size), 0.15 * size, 0.6 * size, facecolor=color, angle=10)leg2 = Rectangle((x, y - 0.8 * size), 0.15 * size, 0.6 * size, facecolor=color, angle=-5)# 汗水for i in range(3):sweat = plt.Circle((x - 0.1 + i * 0.1, y + 0.3 * size), 0.03, color='#3498db', alpha=0.7)ax.add_patch(sweat)ax.add_patch(body)ax.add_patch(head)ax.add_patch(arm1)ax.add_patch(arm2)ax.add_patch(leg1)ax.add_patch(leg2)return [body, head, arm1, arm2, leg1, leg1]# 敌军在平原上行军(红色)
enemy_soldiers = []
for i in range(15):x = 1 + i * 0.8y = 3.0 + np.random.uniform(-0.1, 0.1)soldier = draw_tired_soldier(x, y, '#e74c3c', size=0.9)enemy_soldiers.extend(soldier)# 绘制行军路线
ax.plot([0.5, 13.5], [3.0, 3.0], 'r--', linewidth=1, alpha=0.7)# 添加策略说明
texts = [("我军阵地(高地)", (7, 8.0), '#2c3e50'),("养精蓄锐", (7, 7.7), '#3498db'),("构筑工事", (4, 6.0), '#3498db'),("充分补给", (8, 6.0), '#3498db'),("观察敌情", (10, 6.0), '#3498db'),("敌军行军(平原)", (7, 4.5), '#2c3e50'),("长途跋涉", (7, 4.2), '#e74c3c'),("补给困难", (7, 3.9), '#e74c3c'),("士气低落", (7, 3.6), '#e74c3c'),("以逸待劳:养精蓄锐,待敌疲惫时出击", (7, 9.5), '#2c3e50'),("时机成熟!", (12, 7.0), '#f39c12', 14)
]for text in texts:if len(text) == 3:text, pos, color = textsize = 11else:text, pos, color, size = textax.text(pos[0], pos[1], text, ha='center', va='center',color=color, fontsize=size, weight='bold')# 绘制策略阶段
phases = [("1. 占据有利地形", (2, 2.5), '#3498db'),("2. 休整准备", (2, 2.0), '#3498db'),("3. 观察敌军动向", (2, 1.5), '#3498db'),("4. 敌军疲惫到达", (12, 2.5), '#e74c3c'),("5. 发起攻击", (12, 2.0), '#f39c12'),("6. 取得胜利", (12, 1.5), '#27ae60')
]for text, pos, color in phases:ax.text(pos[0], pos[1], text, ha='center', va='center',color=color, fontsize=10, weight='bold',bbox=dict(facecolor='#ecf0f1', alpha=0.8, edgecolor=color))# 绘制时间线
ax.plot([3, 11], [1.0, 1.0], 'k-', linewidth=1.5)
time_points = [4, 6, 8, 10]
time_labels = ["敌军出发", "行军途中", "到达战场", "我军出击"]
for i, (x, label) in enumerate(zip(time_points, time_labels)):ax.plot([x, x], [0.9, 1.1], 'k-', linewidth=1.5)ax.text(x, 1.2, f"阶段 {i + 1}\n{label}", ha='center', fontsize=9, weight='bold')# 添加时间标签ax.text(x, 0.7, f"时间: {i * 4}小时", ha='center', fontsize=8, style='italic')# 绘制攻击箭头
attack_arrow = Arrow(8, 7.0, 4.0, -3.0, width=0.8, color='#f39c12', alpha=0.9)
ax.add_patch(attack_arrow)# 添加能量对比图
ax.text(1, 9.0, "军队状态对比", fontsize=12, weight='bold', color='#2c3e50')# 我军能量
ax.plot([2, 2], [8.5, 9.5], 'b-', linewidth=8, solid_capstyle='round')
ax.text(2, 9.7, "我军", ha='center', fontsize=10, color='#3498db')
ax.text(2, 8.3, "高", ha='center', fontsize=9, color='#3498db')# 敌军能量
ax.plot([3.5, 3.5], [8.5, 7.0], 'r-', linewidth=8, solid_capstyle='round')
ax.text(3.5, 9.7, "敌军", ha='center', fontsize=10, color='#e74c3c')
ax.text(3.5, 6.8, "低", ha='center', fontsize=9, color='#e74c3c')# 能量变化箭头
ax.annotate('', xy=(2.2, 8.5), xytext=(2.2, 9.5),arrowprops=dict(arrowstyle='->', color='#3498db', linewidth=2))
ax.text(2.4, 9.0, "保持充沛", rotation=90, ha='left', va='center',color='#3498db', fontsize=9)ax.annotate('', xy=(3.3, 8.5), xytext=(3.3, 7.0),arrowprops=dict(arrowstyle='->', color='#e74c3c', linewidth=2))
ax.text(3.1, 7.8, "逐渐消耗", rotation=90, ha='right', va='center',color='#e74c3c', fontsize=9)# 添加策略原理
principles = ["策略原理:","1. 选择有利地形 - 高地提供防御优势","2. 充分休息补给 - 保持最佳状态","3. 迫使敌人移动 - 消耗敌军体力","4. 耐心等待时机 - 待敌疲惫不堪","5. 集中力量出击 - 一举击溃敌军"
]for i, text in enumerate(principles):ax.text(12.5, 9.0 - i * 0.5, text, ha='left', va='top',fontsize=10 if i > 0 else 11,color='#2c3e50',bbox=dict(facecolor='#ecf0f1', alpha=0.7, edgecolor='#bdc3c7') if i > 0 else None)# 添加图例
legend_elements = [plt.Line2D([0], [0], marker='o', color='w', markerfacecolor='#3498db', markersize=10, label='我军士兵'),plt.Line2D([0], [0], marker='o', color='w', markerfacecolor='#e74c3c', markersize=10, label='敌军士兵'),plt.Line2D([0], [0], color='#3498db', linewidth=3, label='我军阵地'),plt.Line2D([0], [0], color='#b8a07c', linewidth=3, label='平原地形'),plt.Line2D([0], [0], color='#f39c12', linewidth=3, label='出击时机')
]ax.legend(handles=legend_elements, loc='lower center',bbox_to_anchor=(0.5, -0.05), ncol=3,facecolor='#ecf0f1', edgecolor='#bdc3c7',fontsize=10)plt.tight_layout()
plt.savefig('以逸待劳.png', dpi=300, bbox_inches='tight', facecolor='#ecf0f1')
plt.show()

趁火打劫

敌之害大,就势取利,刚决柔也。

趁敌方陷入危机时发动攻击。

import matplotlib.pyplot as plt
import numpy as np
from matplotlib.patches import Rectangle, Circle, Polygon, Arrow
import matplotlib.patheffects as path_effects# 设置中文字体支持
plt.rcParams['font.sans-serif'] = ['SimHei', 'Microsoft YaHei', 'WenQuanYi Micro Hei']
plt.rcParams['axes.unicode_minus'] = False# 创建画布
fig, ax = plt.subplots(figsize=(14, 8))
ax.set_xlim(0, 10)
ax.set_ylim(0, 6)
ax.set_aspect('equal')
ax.axis('off')# 设置背景颜色
fig.patch.set_facecolor('#f0f8ff')
ax.set_facecolor('#f0f8ff')# 绘制标题
title = ax.text(5, 5.5, '趁火打劫策略示意图',fontsize=24, ha='center', va='center', fontweight='bold',color='#8B0000')
title.set_path_effects([path_effects.withStroke(linewidth=3, foreground='gold')])# 添加副标题
subtitle = ax.text(5, 5.1, '敌之害大,就势取利,刚决柔也',fontsize=16, ha='center', va='center',fontstyle='italic', color='#333333')# 绘制城堡(敌人基地)
castle = Rectangle((1, 1), 2, 2, color='#8B4513', alpha=0.8)
castle_roof = Polygon(np.array([[0.8, 3.0], [1.5, 3.8], [2.5, 3.8], [3.2, 3.0]], dtype=np.float64),color='#A52A2A')
castle_window = Rectangle((1.4, 1.8), 0.4, 0.4, color='yellow')
castle_door = Rectangle((1.8, 1), 0.4, 0.6, color='#654321')
ax.add_patch(castle)
ax.add_patch(castle_roof)
ax.add_patch(castle_window)
ax.add_patch(castle_door)# 添加城堡标签
ax.text(2, 0.8, '敌人基地', fontsize=12, ha='center', color='#8B4513')# 绘制火焰(表示敌人危机)
flames = []
for i in range(5):x = np.random.uniform(1.2, 2.8)y = np.random.uniform(3.1, 3.8)size = np.random.uniform(0.3, 0.6)flame = Polygon([[float(x), float(y)],  # 显式转换坐标值为float[float(x - size/2), float(y - size)],[float(x), float(y - size/3)],[float(x + size/2), float(y - size)]], color='#FF4500')flames.append(flame)ax.add_patch(flame)# 添加烟雾
for i in range(8):x = np.random.uniform(0.5, 3.5)y = np.random.uniform(3.5, 4.5)size = np.random.uniform(0.2, 0.5)smoke = Circle((x, y), size, color='#A9A9A9', alpha=0.4)ax.add_patch(smoke)# 绘制我方部队
for i in range(3):x = 4.5 + i * 1.5y = 1.5soldier = Circle((x, y), 0.3, color='#006400')ax.add_patch(soldier)ax.plot([x, x], [y - 0.3, y - 0.8], color='#006400', linewidth=2)ax.plot([x - 0.2, x + 0.2], [y - 0.5, y - 0.5], color='#006400', linewidth=2)ax.plot([x, x - 0.3], [y - 0.8, y - 1.2], color='#006400', linewidth=2)ax.plot([x, x + 0.3], [y - 0.8, y - 1.2], color='#006400', linewidth=2)# 绘制武器ax.plot([x - 0.3, x + 0.3], [y + 0.15, y + 0.15], color='#2F4F4F', linewidth=3)# 添加我方部队标签
ax.text(6, 1.9, '我方部队', fontsize=12, ha='center', color='#006400')# 绘制箭头表示进攻方向
arrow = Arrow(4.5, 1.5, -1.8, 0, width=0.3, color='#8B0000', alpha=0.8)
ax.add_patch(arrow)# 绘制策略说明框
strategy_box = Rectangle((5.5, 2.3), 4, 2.5, color='#FFFACD', alpha=0.9, ec='#DAA520', lw=2)
ax.add_patch(strategy_box)# 添加策略说明文本
strategy_text = ['趁火打劫策略解析:','','• 核心思想: 当敌人遭遇危机(如内乱、灾害、外敌)时','• 行动原则: 抓住时机,果断出击,获取最大利益','• 实施要点:','  1. 密切关注敌方动态,及时发现"火情"','  2. 快速评估形势,制定攻击方案','  3. 迅速行动,不给敌人喘息机会','  4. 夺取关键资源,扩大战果','','《三十六计》:"敌之害大,就势取利,刚决柔也"'
]for i, text in enumerate(strategy_text):y_pos = 4.7 - i * 0.22ax.text(5.7, y_pos, text, fontsize=10, ha='left', va='top', color='#333333')# 绘制装饰性边框
border = Rectangle((0.1, 0.1), 9.8, 5.8, fill=None, ec='#DAA520', lw=3, linestyle='--', alpha=0.7)
ax.add_patch(border)# 添加火焰图标装饰
for i in range(10):x = np.random.uniform(0.5, 9.5)y = np.random.uniform(0.5, 5.5)size = np.random.uniform(0.05, 0.15)flame_icon = Polygon([[x, y + size],[x - size / 2, y],[x, y + size / 3],[x + size / 2, y]], color='#FF4500', alpha=0.3)ax.add_patch(flame_icon)
plt.savefig('趁火打劫.png', dpi=300, bbox_inches='tight', facecolor='#ecf0f1')
plt.tight_layout()
plt.show()

声东击西

敌志乱萃,不虞,坤下兑上之象。利其不自主而取之。

佯攻一处,实则突袭另一目标。

import numpy as np
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
from matplotlib.patches import Circle, Rectangle, Polygon, Arrow
import matplotlib.patheffects as path_effects# 设置中文字体
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False# 创建画布
fig, ax = plt.subplots(figsize=(12, 8))
ax.set_xlim(0, 10)
ax.set_ylim(0, 8)
ax.set_aspect('equal')
ax.axis('off')
ax.set_title('声东击西策略示意图', fontsize=18, pad=20)# 绘制地形元素
river = Polygon([[1.0, 1.0], [3.0, 3.0], [5.0, 2.5], [7.0, 4.0], [9.0, 1.0]], closed=False,fill=False, color='blue', lw=2, alpha=0.7)
mountain = Polygon([[2.0, 5.0], [4.0, 7.0], [6.0, 6.0], [8.0, 7.5], [7.0, 5.0]],closed=True, fill=True, color='#8B4513', alpha=0.4)
city = Rectangle((8, 1.5), 1.5, 1.5, color='#A9A9A9', alpha=0.8)
forest = Polygon([[1.0, 6.0], [2.0, 7.0], [3.0, 6.5], [4.0, 7.2], [3.0, 5.5]],closed=True, fill=True, color='#2E8B57', alpha=0.5)# 添加地形到画布
ax.add_patch(river)
ax.add_patch(mountain)
ax.add_patch(city)
ax.add_patch(forest)# 添加地形标注
ax.text(5, 0.5, '河流', color='blue', fontsize=10, ha='center')
ax.text(5.5, 6.5, '山脉', color='#8B4513', fontsize=10, ha='center')
ax.text(8.75, 1.0, '目标城市', color='black', fontsize=10, ha='center')
ax.text(2.5, 6.2, '森林', color='#2E8B57', fontsize=10, ha='center')# 初始部队位置
red_team = {'main': {'pos': np.array([1.0, 3.5]), 'size': 8},'diversion': {'pos': np.array([2.0, 6.0]), 'size': 4}
}blue_team = {'defense_east': {'pos': np.array([6.0, 6.5]), 'size': 10},'defense_west': {'pos': np.array([7.0, 3.0]), 'size': 6}
}# 创建部队标记
red_main = Circle(red_team['main']['pos'], radius=0.15, color='red', ec='black')
red_diversion = Circle(red_team['diversion']['pos'], radius=0.12, color='red', ec='black')
blue_east = Circle(blue_team['defense_east']['pos'], radius=0.15, color='blue', ec='black')
blue_west = Circle(blue_team['defense_west']['pos'], radius=0.12, color='blue', ec='black')# 添加部队标记
ax.add_patch(red_main)
ax.add_patch(red_diversion)
ax.add_patch(blue_east)
ax.add_patch(blue_west)# 添加部队标注
ax.text(1.0, 3.0, '红军主力', color='red', fontsize=10, ha='center')
ax.text(2.0, 5.7, '佯攻部队', color='red', fontsize=9, ha='center')
ax.text(6.0, 6.0, '蓝军东侧防线', color='blue', fontsize=10, ha='center')
ax.text(7.0, 2.5, '蓝军西侧防线', color='blue', fontsize=9, ha='center')# 添加策略说明
strategy_text = ax.text(2.0, 7.5, "策略: 佯攻东侧(山脉),实攻西侧(城市)",fontsize=14, color='darkred', ha='left')
strategy_text.set_path_effects([path_effects.withStroke(linewidth=3, foreground='w')])# 创建动态元素
diversion_arrow = Arrow(2.0, 6.0, 1.5, 1.0, width=0.1, color='red', alpha=0.7)
main_arrow = Arrow(1.0, 3.5, 0.5, 0.0, width=0.1, color='red', alpha=0.7)
diversion_path, = ax.plot([], [], 'r--', lw=1, alpha=0.5)
main_path, = ax.plot([], [], 'r-', lw=2)ax.add_patch(diversion_arrow)
ax.add_patch(main_arrow)# 动画更新函数
def update(frame):# 更新佯攻部队位置和箭头if frame < 20:dx = 0.15dy = 0.08red_diversion.center = red_team['diversion']['pos'] + np.array([dx * frame, dy * frame])diversion_arrow.set_data(x=red_diversion.center[0],y=red_diversion.center[1],dx=1.5,dy=1.0)# 更新佯攻路径x_data = np.linspace(red_team['diversion']['pos'][0], red_diversion.center[0], 10)y_data = np.linspace(red_team['diversion']['pos'][1], red_diversion.center[1], 10)diversion_path.set_data(x_data, y_data)# 更新主力部队位置if frame > 5:red_main.center = red_team['main']['pos'] + np.array([0.2 * (frame - 5), 0])main_arrow.set_data(x=red_main.center[0],y=red_main.center[1],dx=0.5,dy=0)# 更新主力路径x_data = np.linspace(red_team['main']['pos'][0], red_main.center[0], 10)y_data = np.linspace(red_team['main']['pos'][1], red_main.center[1], 10)main_path.set_data(x_data, y_data)# 第二阶段:主力加速进攻elif frame < 40:# 佯攻部队继续前进dx = 0.15dy = 0.08red_diversion.center = red_diversion.center + np.array([dx, dy])diversion_arrow.set_data(x=red_diversion.center[0],y=red_diversion.center[1],dx=1.5,dy=1.0)# 主力部队加速前进red_main.center = red_main.center + np.array([0.4, 0])main_arrow.set_data(x=red_main.center[0],y=red_main.center[1],dx=0.5,dy=0)# 更新路径x_data = np.append(diversion_path.get_xdata(), red_diversion.center[0])y_data = np.append(diversion_path.get_ydata(), red_diversion.center[1])diversion_path.set_data(x_data, y_data)x_data = np.append(main_path.get_xdata(), red_main.center[0])y_data = np.append(main_path.get_ydata(), red_main.center[1])main_path.set_data(x_data, y_data)# 蓝军东侧部队被吸引if frame > 25:blue_east.center = blue_east.center + np.array([0.1, 0.05])# 第三阶段:主力到达目标else:if frame < 60:# 主力部队到达城市if np.linalg.norm(red_main.center - np.array([8.75, 2.25])) > 0.5:direction = (np.array([8.75, 2.25]) - red_main.center) * 0.1red_main.center = red_main.center + directionmain_arrow.set_data(x=red_main.center[0],y=red_main.center[1],dx=direction[0] * 2,dy=direction[1] * 2)else:# 占领城市city.set_color('red')city.set_alpha(0.6)strategy_text.set_text("策略成功: 佯攻部队吸引敌军主力,红军主力攻占城市!")# 更新路径x_data = np.append(main_path.get_xdata(), red_main.center[0])y_data = np.append(main_path.get_ydata(), red_main.center[1])main_path.set_data(x_data, y_data)return red_diversion, diversion_arrow, diversion_path, red_main, main_arrow, main_path, blue_east, city# 创建动画
ani = FuncAnimation(fig, update, frames=60, interval=100, blit=False)# 添加图例和说明
ax.text(0.5, 0.2, '三十六计·声东击西:\n"敌志乱萃,不虞,坤下兑上之象。利其不自主而取之。"',fontsize=12, color='#8B0000', ha='left', va='bottom', wrap=True,bbox=dict(boxstyle='round', alpha=0.2, color='#FFE4E1'))# 保存动画
ani.save('声东击西.gif', writer='pillow', fps=10)plt.tight_layout()
plt.show()

敌战计(势均力敌时的对抗策略)

无中生有

诳也,非诳也,实其所诳也。少阴、太阴、太阳。

制造假象迷惑敌人,后化虚为实。

import numpy as np
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
from matplotlib.patches import Circle, Rectangle, Polygon, Arrow, Ellipse
import matplotlib.patheffects as path_effects
import random# 设置中文字体
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False# 创建画布
fig, ax = plt.subplots(figsize=(14, 8))
ax.set_xlim(0, 12)
ax.set_ylim(0, 8)
ax.set_aspect('equal')
ax.axis('off')
ax.set_title('无中生有策略示意图', fontsize=20, pad=20, color='darkred')# 绘制地形元素
# 城池
city_wall = Rectangle((2, 2), 5, 4, fill=False, color='#8B4513', lw=3)
city_gate = Rectangle((4.5, 2), 1, 0.5, color='#A52A2A', alpha=0.8)
city_inner = Rectangle((2.5, 2.5), 4, 3, fill=False, color='gray', lw=1, ls='--')# 河流
river = Polygon([[0, 0], [1, 1.5], [3, 0.5], [5, 2], [7, 1], [9, 3], [12, 2]],closed=False, fill=False, color='blue', lw=2, alpha=0.7)# 山脉
mountains = [Polygon([[9, 5], [10, 7], [11, 6], [12, 7]], closed=True, fill=True, color='#8B4513', alpha=0.6),Polygon([[0, 7], [1, 6], [2, 7], [3, 6.5]], closed=True, fill=True, color='#8B4513', alpha=0.6)
]# 森林
forest = Polygon([[10, 1], [11, 2], [11.5, 1.5], [12, 2], [11.5, 0.5]],closed=True, fill=True, color='#2E8B57', alpha=0.6)# 添加地形到画布
ax.add_patch(city_wall)
ax.add_patch(city_gate)
ax.add_patch(city_inner)
ax.add_patch(river)
ax.add_patch(forest)
for mountain in mountains:ax.add_patch(mountain)# 添加地形标注
ax.text(4.5, 1.8, '城门', color='#8B4513', fontsize=10, ha='center')
ax.text(7, 0.5, '河流', color='blue', fontsize=10, ha='center')
ax.text(10.5, 6.5, '山脉', color='#8B4513', fontsize=10, ha='center')
ax.text(11, 1.2, '森林', color='#2E8B57', fontsize=10, ha='center')
ax.text(4.5, 4.5, '城池', color='black', fontsize=12, ha='center', weight='bold')# 初始部队位置
red_team_real = {'pos': np.array([10.5, 3.5]), 'size': 8}  # 真实主力
red_team_fake = {'pos': np.array([1.5, 3.0]), 'size': 5}  # 假部队
blue_team = {'pos': np.array([4.5, 4.0]), 'size': 10}  # 守城部队# 创建部队标记
red_real = Circle(red_team_real['pos'], radius=0.2, color='red', ec='black', alpha=0.8)
red_fake = Circle(red_team_fake['pos'], radius=0.2, color='red', ec='black', alpha=0.3)  # 半透明表示虚假
blue_army = Circle(blue_team['pos'], radius=0.25, color='blue', ec='black', alpha=0.8)# 添加部队标记
ax.add_patch(red_real)
ax.add_patch(red_fake)
ax.add_patch(blue_army)# 添加部队标注
ax.text(10.5, 3.2, '红军主力(隐藏)', color='red', fontsize=10, ha='center')
ax.text(1.5, 2.7, '红军佯动部队(虚假)', color='red', fontsize=10, ha='center', alpha=0.7)
ax.text(4.5, 3.7, '守城部队', color='blue', fontsize=10, ha='center')# 创建虚假部队元素(用于动画)
fake_troops = []
for i in range(15):# 创建半透明的假士兵troop = Circle((0, 0), radius=0.1, color='red', ec='black', alpha=0)ax.add_patch(troop)fake_troops.append(troop)# 添加策略说明
strategy_text = ax.text(1.0, 7.5, "策略: 制造假象,迷惑敌人",fontsize=16, color='darkred', ha='left')
strategy_text.set_path_effects([path_effects.withStroke(linewidth=3, foreground='w')])# 创建动态元素
fake_arrow = Arrow(red_team_fake['pos'][0], red_team_fake['pos'][1], 1, 0,width=0.2, color='red', alpha=0.3)
real_arrow = Arrow(red_team_real['pos'][0], red_team_real['pos'][1], -1, 0,width=0.2, color='red', alpha=0)
ax.add_patch(fake_arrow)
ax.add_patch(real_arrow)# 添加烟雾效果
smoke_particles = []
for _ in range(30):smoke = Ellipse((0, 0), width=0.2, height=0.3, angle=0,color='#AAAAAA', alpha=0)ax.add_patch(smoke)smoke_particles.append(smoke)# 添加计策解释
quote_text = ax.text(0.5, 0.8,'三十六计·无中生有:\n"诳也,非诳也,实其所诳也。少阴、太阴、太阳。"\n——用假象欺骗敌人,但并非一假到底,而是假中有真。\n由虚假逐渐转化为真实,以造成敌人的错觉。',fontsize=14, color='#8B0000', ha='left', va='bottom', wrap=True,bbox=dict(boxstyle='round', alpha=0.2, color='#FFE4E1'))# 动画更新函数
def update(frame):# 第一阶段:制造假象(1-20帧)if frame < 20:# 显示虚假部队if frame < 15:# 逐渐显示虚假部队for i in range(min(frame, len(fake_troops))):fake_troops[i].set_alpha(0.3)fake_troops[i].center = (red_team_fake['pos'][0] + random.uniform(-1.0, 1.0),red_team_fake['pos'][1] + random.uniform(-0.8, 0.8))# 制造烟雾效果for i, smoke in enumerate(smoke_particles):if frame > 5 and i < frame - 5:smoke.set_alpha(0.5)smoke.set_center((1.0 + random.uniform(0, 3),2.5 + random.uniform(0, 2)))smoke.set_width(random.uniform(0.1, 0.3))smoke.set_height(random.uniform(0.2, 0.5))# 虚假部队向前移动if frame > 8:dx = 0.1red_fake.center = red_team_fake['pos'] + np.array([dx * (frame - 8), 0])fake_arrow.set_data(x=red_fake.center[0],y=red_fake.center[1],dx=1,dy=0)# 更新策略文本strategy_text.set_text(f"策略: 制造假象,迷惑敌人 (显示虚假部队)")# 第二阶段:吸引敌军注意(20-40帧)elif frame < 40:# 虚假部队继续前进dx = 0.1red_fake.center = red_fake.center + np.array([dx, 0])fake_arrow.set_data(x=red_fake.center[0],y=red_fake.center[1],dx=1,dy=0)# 守城部队被吸引if frame > 25:dy = 0.08blue_army.center = blue_team['pos'] + np.array([0, dy * (frame - 25)])# 更新策略文本strategy_text.set_text(f"策略: 成功吸引守军注意!")# 第三阶段:真实部队出击(40-60帧)elif frame < 60:# 虚假部队逐渐消失(透明度降低)for troop in fake_troops:alpha = troop.get_alpha()if alpha > 0:troop.set_alpha(max(0, alpha - 0.02))# 真实部队出击if frame < 50:dx = -0.25red_real.center = red_team_real['pos'] + np.array([dx * (frame - 40), 0])real_arrow.set_alpha(0.8)real_arrow.set_data(x=red_real.center[0],y=red_real.center[1],dx=-1,dy=0)else:# 真实部队到达城门red_real.center = (5.0, 2.5)real_arrow.set_data(x=5.0,y=2.5,dx=0,dy=0.5)strategy_text.set_text("策略成功: 真实部队趁虚而入!")# 第四阶段:揭示真相(60-75帧)else:if frame == 61:# 添加揭示文本reveal_text = ax.text(3.0, 7.0, "真相揭示:",fontsize=18, color='darkgreen', ha='left')reveal_text.set_path_effects([path_effects.withStroke(linewidth=2, foreground='w')])# 添加解释文本ax.text(3.0, 6.2, "• 东部部队只是假象\n• 真实主力从西部森林出击\n• 守军被假象迷惑,未及时防御西部",fontsize=14, color='darkgreen', ha='left')# 添加成功标志success_text = ax.text(8.0, 6.0, "无中生有成功!",fontsize=24, color='red', ha='center', weight='bold')success_text.set_path_effects([path_effects.withStroke(linewidth=4, foreground='yellow')])# 添加箭头指示ax.annotate('假象', xy=(2.0, 3.0), xytext=(0.5, 4.0),arrowprops=dict(arrowstyle='->', color='red', alpha=0.5),fontsize=12, color='red')ax.annotate('真实', xy=(5.0, 2.5), xytext=(8.0, 1.0),arrowprops=dict(arrowstyle='->', color='red'),fontsize=12, color='red')# 添加策略总结ax.text(8.0, 0.8, "无中生有精髓:\n以虚掩实,假中藏真\n虚张声势,实攻其虚",fontsize=14, color='darkred', ha='center',bbox=dict(boxstyle='round', alpha=0.2, color='#FFE4E1'))return fake_troops + [red_fake, red_real, blue_army, fake_arrow, real_arrow] + smoke_particles# 创建动画
ani = FuncAnimation(fig, update, frames=75, interval=150, blit=False)# 添加来源注释
plt.figtext(0.5, 0.01, "三十六计 - 无中生有: 制造假象,迷惑敌人 | 可视化: Python Matplotlib",ha="center", fontsize=10, color='gray')plt.tight_layout()
plt.show()# 保存动画
ani.save('无中生有.gif', writer='pillow', fps=8, dpi=120)

暗渡陈仓

示之以动,利其静而有主,“益动而巽”。

明面佯动吸引注意,暗地实施真实计划。

隔岸观火

阳乖序乱,阴以待逆。暴戾恣睢,其势自毙。

静待敌人内部分裂,再伺机行动。

笑里藏刀

信而安之,阴以图之;备而后动,勿使有变。刚中柔外也。

表面友好,暗中准备攻击。

李代桃僵

势必有损,损阴以益阳。

牺牲局部保全整体。

顺手牵羊

微隙在所必乘,微利在所必得。少阴,少阳。

抓住敌方疏漏,获取小利。

攻战计(主动进攻的策略)

打草惊蛇

疑以叩实,察而后动。复者,阴之媒也。

故意暴露行动,试探敌方反应。

借尸还魂

有用者,不可借;不能用者,求借。借不能用者而用之。

利用废弃资源或名义,实现新目标。

调虎离山

待天以困之,用人以诱之。往蹇来返。

诱使强敌离开有利环境。

欲擒故纵

逼则反兵,走则减势。紧随勿迫,累其气力,消其斗志,散而后擒。

暂时放松逼迫,待敌松懈时再擒获。

抛砖引玉

类以诱之,击蒙也。

以小利引诱敌人,换取更大利益。

擒贼擒王

摧其坚,夺其魁,以解其体。龙战于野,其道穷也。

打击核心人物或关键环节,瓦解整体。

混战计(局势混乱时的策略)

釜底抽薪

不敌其力,而消其势。

从根本上削弱敌方力量。

浑水摸鱼

乘其阴乱,利其弱而无主。随,以向晦入宴息。

趁混乱谋取利益。

金蝉脱壳

存其形,完其势;友不疑,敌不动。巽而止,蛊。

伪装撤退或转移,暗中脱离险境。

关门捉贼

小敌困之。剥,不利有攸往。

包围敌人,断其退路后歼灭。

远交近攻

频更其阵,抽其劲旅,待其自败,而后乘之。

结交远方势力,打击邻近对手。

假道伐虢

两大之间,敌胁以从,我假以势。困,有言不信。

借路通行,顺势占领地盘。

并战计(应对盟友或潜在对手的策略)

偷梁换柱

频更其阵,抽其劲旅,待其自败,而后乘之。

暗中替换关键要素,改变局势。

指桑骂槐

大凌小者,警以诱之。刚中而应,行险而顺。

借批评他人警示目标对象。

假痴不癫

宁伪作不知不为,不伪作假知妄为。静不露机,云雷屯也。

假装糊涂,麻痹对手。

上屋抽梯

假之以便,唆之使前,断其援应,陷之死地。

诱敌深入后断其退路。

树上开花

借局布势,力小势大。鸿渐于陆,其羽可用为仪也。

借势造势,虚张声势。

反客为主

乘隙插足,扼其主机,渐之进也。

被动变主动,逐步掌控局面。

败战计(劣势下的生存策略)

美人计

兵强者,攻其将;将智者,伐其情。将弱兵颓,其势自萎。

利用美色或诱惑瓦解敌方意志。

空城计

虚者虚之,疑中生疑;刚柔之际,奇而复奇。

虚张声势,示弱以迷惑敌人。

反间计

疑中之疑。比之自内,不自失也。

离间敌人内部,使其自损。

苦肉计

人不自害,受害必真;假真真假,间以得行。

自我伤害骗取敌人信任。

连环计

将多兵众,不可以敌,使其自累,以杀其势。

多计并用,环环相扣。

走为上计

全师避敌。左次无咎,未失常也。

形势不利时主动撤退,保存实力。

词云图

import jieba
from wordcloud import WordCloud
import matplotlib.pyplot as plt
from collections import Counter# 设置中文字体
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False# 三十六计数据
strategies = ["瞒天过海", "围魏救赵", "借刀杀人", "以逸待劳", "趁火打劫", "声东击西","无中生有", "暗渡陈仓", "隔岸观火", "笑里藏刀", "李代桃僵", "顺手牵羊","打草惊蛇", "借尸还魂", "调虎离山", "欲擒故纵", "抛砖引玉", "擒贼擒王","釜底抽薪", "混水摸鱼", "金蝉脱壳", "关门捉贼", "远交近攻", "假道伐虢","偷梁换柱", "指桑骂槐", "假痴不癫", "上屋抽梯", "树上开花", "反客为主","美人计", "空城计", "反间计", "苦肉计", "连环计", "走为上计"
]# 处理文本
text = " ".join(strategies)
words = jieba.lcut(text)
word_list = " ".join(words)
word_counts = Counter(words)
font_path = "C:/Windows/Fonts/simhei.ttf"
# 生成词云
wc = WordCloud(font_path=font_path,background_color="white",max_words=200,width=800,height=600,collocations=False
)
wc.generate_from_frequencies(word_counts)# 显示结果
plt.figure(figsize=(10, 8))
plt.imshow(wc, interpolation="bilinear")
plt.axis("off")
plt.show()# 保存图片
wc.to_file("三十六计词云.png")

网络关系图

交互式图表

思维导图

import matplotlib.pyplot as plt
import networkx as nx# 设置中文字体
plt.rcParams['font.sans-serif'] = ['SimHei']  # 用来正常显示中文标签
plt.rcParams['axes.unicode_minus'] = False  # 用来正常显示负号# 创建图形
plt.figure(figsize=(16, 12))
G = nx.Graph()# 三十六计结构
categories = {"胜战计": ["瞒天过海", "围魏救赵", "借刀杀人", "以逸待劳", "趁火打劫", "声东击西"],"敌战计": ["无中生有", "暗渡陈仓", "隔岸观火", "笑里藏刀", "李代桃僵", "顺手牵羊"],"攻战计": ["打草惊蛇", "借尸还魂", "调虎离山", "欲擒故纵", "抛砖引玉", "擒贼擒王"],"混战计": ["釜底抽薪", "混水摸鱼", "金蝉脱壳", "关门捉贼", "远交近攻", "假道伐虢"],"并战计": ["偷梁换柱", "指桑骂槐", "假痴不癫", "上屋抽梯", "树上开花", "反客为主"],"败战计": ["美人计", "空城计", "反间计", "苦肉计", "连环计", "走为上计"]
}# 添加节点和边
# 中心节点
G.add_node("三十六计", size=3000, color='gold')# 添加分类节点
for i, (category, strategies) in enumerate(categories.items()):# 添加分类节点G.add_node(category, size=1500, color=f'C{i}')G.add_edge("三十六计", category)# 添加具体计策节点for strategy in strategies:G.add_node(strategy, size=800, color=f'C{i}')G.add_edge(category, strategy)# 设置布局
pos = nx.spring_layout(G, k=0.3, seed=42)  # k参数控制节点间距# 绘制节点
node_sizes = [G.nodes[node]['size'] for node in G.nodes()]
node_colors = [G.nodes[node]['color'] for node in G.nodes()]nx.draw_networkx_nodes(G, pos,node_size=node_sizes,node_color=node_colors,alpha=0.8
)# 绘制标签
nx.draw_networkx_labels(G, pos,font_size=12,font_weight='bold',font_family='SimHei'
)# 绘制边
nx.draw_networkx_edges(G, pos,width=1.5,edge_color='gray',alpha=0.6
)# 添加标题和注释
plt.figtext(0.5, 0.01,"《三十六计》是中国古代兵法策略的集大成者,分胜战、敌战、攻战、混战、并战、败战六套计策,每套六计",ha="center", fontsize=14, style='italic')# 添加图例
from matplotlib.patches import Patchlegend_elements = [Patch(facecolor='gold', label='核心概念'),Patch(facecolor='C0', label='胜战计'),Patch(facecolor='C1', label='敌战计'),Patch(facecolor='C2', label='攻战计'),Patch(facecolor='C3', label='混战计'),Patch(facecolor='C4', label='并战计'),Patch(facecolor='C5', label='败战计'),
]
plt.legend(handles=legend_elements, loc='upper right', fontsize=12)# 保存和显示
plt.tight_layout()
plt.savefig("三十六计思维导图.png", dpi=300, bbox_inches='tight')
plt.show()

相关文章:

  • Python Robot Framework【自动化测试框架】简介
  • # STM32F103 SD卡读写程序
  • Egg.js框架的基本介绍与用法,以及如何连接数据库并对数据库进行增删改查
  • 使用Caddy在Ubuntu 22.04上配置HTTPS反向代理
  • Python爬虫实战:研究Hyper 相关技术
  • 华为云Astro中服务编排、自定义模型,页面表格之间有什么关系?如何连接起来?如何操作?
  • 【CSS-4】掌握CSS文字样式:从基础到高级技巧
  • 容器安全最佳实践:云原生环境下的零信任架构实施
  • 微服务架构-分布式任务调度
  • 《探秘跨网段局域网IP广播:解锁网络通信的新姿势》
  • 开疆智能Ethernet/IP转Modbus网关连接鸣志步进电机驱动器配置案例
  • 【软件工具】批量OCR指定区域图片自动识别内容重命名软件使用教程及注意事项
  • Vue3+Element Plus表单验证实战:从零实现用户管理
  • 数据导入技术(文档加载)
  • LabVIEW音频测试分析
  • can转Profinet网关转换:S7-1200PLC与施耐德变频器间的通信实现
  • 引起MySQL CPU 使用率过高常见因素和解决方案
  • ngx_stream_geo_module在传输层实现高性能 IP Region 路由
  • sqlsugar WhereIF条件的大于等于和等于查出来的坑
  • Mysql批处理写入数据库
  • 遵义公司做网站找哪个公司好/谷歌推广效果怎么样
  • 宁波做网站建设推广/最快的新闻发布平台
  • 哪个网站建设公司/网络推广营销方案100例
  • 手机适配网站/企业seo优化服务
  • 网站建设网上售票系统/福建seo顾问
  • 陕西建设集团招聘信息网站/对seo的认识和理解