# miura_pattern.py
import numpy as np
import matplotlib.pyplot as plt
import random
def miura_ori(rows=12, cols=10, a=1.0, b=0.6, theta=np.deg2rad(72)):
c = a * np.cos(theta)
d = a * np.sin(theta)
points = []
lines_mountain = []
lines_valley = []
# 点生成
for i in range(rows+1):
row = []
for j in range(cols+1):
x = j * 2 * c + (i % 2) * c
y = i * (d + b)
row.append((x, y))
points.append(row)
# 折り線生成(境界線を除外)
for i in range(rows):
for j in range(cols):
p = points[i][j]
pr = points[i][j+1]
pd = points[i+1][j]
pdr= points[i+1][j+1]
# 横線(谷折り): 最終列は描かない
if j < cols - 1:
lines_valley.append([p, pr])
# 縦線: 最終行は描かない
if i < rows - 1:
lines_valley.append([p, pd])
# 対角線(山折り): 最終行・最終列は描かない
if i < rows - 1 and j < cols - 1:
if (i + j) % 2 == 0:
lines_mountain.append([p, pdr])
else:
lines_mountain.append([pr, pd])
return lines_mountain, lines_valley
# 和色パレット(オリジナル)
wacolors = [
"#6B7A8F", # 藍鼠
"#5BA199", # 青竹色
"#C4976A", # 黄唐茶
"#8B8C89", # 錫色
"#2C2C2C" # 墨色
]
fig = plt.figure(figsize=(8,10), facecolor="#f8f5ee")
ax = plt.gca()
mountain, valley = miura_ori()
# 谷折り(薄墨)
for line in valley:
xs = [line[0][0], line[1][0]]
ys = [line[0][1], line[1][1]]
ax.plot(xs, ys, color="#A3A3A1", linewidth=0.7)
# 山折り(ランダム和色)
for line in mountain:
xs = [line[0][0], line[1][0]]
ys = [line[0][1], line[1][1]]
ax.plot(xs, ys, color=random.choice(wacolors), linewidth=1.2)
ax.set_aspect("equal")
plt.axis("off")
plt.tight_layout()
plt.savefig("miura_pattern.png", dpi=350, facecolor="#f8f5ee")