matlab
function weave_patterns()
clf;
figure('Name', 'Weave Patterns', 'Position', [100, 100, 800, 600]);
% 参数设置
width = 50; % 图案宽度
height = 50; % 图案高度
colors = {'r', 'b', 'g', 'm', 'c', 'y'}; % 经纬线颜色
% 平纹
subplot(2, 3, 1);
[X, Y] = meshgrid(1:width, 1:height);
Z = mod(X + Y, 2);
contourf(X, Y, Z, 'LineWidth', 1.5);
title('Plain Weave');
axis equal;
hold on;
for i = 1:width
plot([i, i], [1, height], 'Color', colors{1}, 'LineWidth', 1.5);
end
for j = 1:height
plot([1, width], [j, j], 'Color', colors{2}, 'LineWidth', 1.5);
end
hold off;
% 斜纹
subplot(2, 3, 2);
Z = mod(X - Y, 2);
contourf(X, Y, Z, 'LineWidth', 1.5);
title('Twill Weave');
axis equal;
hold on;
for i = 1:width
plot([i, i], [1, height], 'Color', colors{3}, 'LineWidth', 1.5);
end
for j = 1:height
plot([1, width], [j, j], 'Color', colors{4}, 'LineWidth', 1.5);
end
hold off;
% 缎纹
subplot(2, 3, 3);
Z = mod(X * 3 - Y, 5) < 2;
contourf(X, Y, Z, 'LineWidth', 1.5);
title('Satin Weave');
axis equal;
hold on;
for i = 1:width
plot([i, i], [1, height], 'Color', colors{5}, 'LineWidth', 1.5);
end
for j = 1:height
plot([1, width], [j, j], 'Color', colors{6}, 'LineWidth', 1.5);
end
hold off;
% 中国结编织
subplot(2, 3, 4);
Z = mod(X * 2 + Y * 2, 4);
contourf(X, Y, Z, 'LineWidth', 1.5);
title('Chinese Knot Weave');
axis equal;
hold on;
for i = 1:width
plot([i, i], [1, height], 'Color', colors{1}, 'LineWidth', 1.5);
end
for j = 1:height
plot([1, width], [j, j], 'Color', colors{2}, 'LineWidth', 1.5);
end
hold off;
% 竹编
subplot(2, 3, 5);
Z = mod(X + Y * 2, 3);
contourf(X, Y, Z, 'LineWidth', 1.5);
title('Bamboo Weave');
axis equal;
hold on;
for i = 1:width
plot([i, i], [1, height], 'Color', colors{3}, 'LineWidth', 1.5);
end
for j = 1:height
plot([1, width], [j, j], 'Color', colors{4}, 'LineWidth', 1.5);
end
hold off;
% 绕编
subplot(2, 3, 6);
Z = mod(X * 2 - Y * 2, 5);
contourf(X, Y, Z, 'LineWidth', 1.5);
title('Coil Weave');
axis equal;
hold on;
for i = 1:width
plot([i, i], [1, height], 'Color', colors{5}, 'LineWidth', 1.5);
end
for j = 1:height
plot([1, width], [j, j], 'Color', colors{6}, 'LineWidth', 1.5);
end
hold off;
end
python
import numpy as np
import matplotlib.pyplot as plt
def weave_patterns():
fig, axes = plt.subplots(2, 3, figsize=(15, 10))
fig.suptitle('Weave Patterns', fontsize=16)
# 参数设置
width, height = 50, 50
colors = ['r', 'b', 'g', 'm', 'c', 'y']
# 平纹
ax = axes[0, 0]
X, Y = np.meshgrid(range(width), range(height))
Z = (X + Y) % 2
ax.contourf(X, Y, Z, colors=['white', colors[0]], linewidths=1.5)
ax.set_title('Plain Weave')
ax.set_aspect('equal')
for i in range(width):
ax.plot([i, i], [0, height], color=colors[1], linewidth=1.5)
for j in range(height):
ax.plot([0, width], [j, j], color=colors[2], linewidth=1.5)
# 斜纹
ax = axes[0, 1]
Z = (X - Y) % 2
ax.contourf(X, Y, Z, colors=['white', colors[3]], linewidths=1.5)
ax.set_title('Twill Weave')
ax.set_aspect('equal')
for i in range(width):
ax.plot([i, i], [0, height], color=colors[4], linewidth=1.5)
for j in range(height):
ax.plot([0, width], [j, j], color=colors[5], linewidth=1.5)
# 缎纹
ax = axes[0, 2]
Z = ((X * 3 - Y) % 5) < 2
ax.contourf(X, Y, Z, colors=['white', colors[0]], linewidths=1.5)
ax.set_title('Satin Weave')
ax.set_aspect('equal')
for i in range(width):
ax.plot([i, i], [0, height], color=colors[1], linewidth=1.5)
for j in range(height):
ax.plot([0, width], [j, j], color=colors[2], linewidth=1.5)
# 中国结编织
ax = axes[1, 0]
Z = (X * 2 + Y * 2) % 4
ax.contourf(X, Y, Z, colors=['white', colors[3]], linewidths=1.5)
ax.set_title('Chinese Knot Weave')
ax.set_aspect('equal')
for i in range(width):
ax.plot([i, i], [0, height], color=colors[4], linewidth=1.5)
for j in range(height):
ax.plot([0, width], [j, j], color=colors[5], linewidth=1.5)
# 竹编
ax = axes[1, 1]
Z = (X + Y * 2) % 3
ax.contourf(X, Y, Z, colors=['white', colors[0]], linewidths=1.5)
ax.set_title('Bamboo Weave')
ax.set_aspect('equal')
for i in range(width):
ax.plot([i, i], [0, height], color=colors[1], linewidth=1.5)
for j in range(height):
ax.plot([0, width], [j, j], color=colors[2], linewidth=1.5)
# 绕编
ax = axes[1, 2]
Z = (X * 2 - Y * 2) % 5
ax.contourf(X, Y, Z, colors=['white', colors[3]], linewidths=1.5)
ax.set_title('Coil Weave')
ax.set_aspect('equal')
for i in range(width):
ax.plot([i, i], [0, height], color=colors[4], linewidth=1.5)
for j in range(height):
ax.plot([0, width], [j, j], color=colors[5], linewidth=1.5)
plt.tight_layout()
plt.show()
weave_patterns()