feat: script levelset explication
This commit is contained in:
parent
0d52c9e351
commit
44d807bec3
39
src/levelset.py
Normal file
39
src/levelset.py
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
import mcubes
|
||||||
|
import numpy as np
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
import imageio.v2 as imageio
|
||||||
|
import perlin_noise
|
||||||
|
|
||||||
|
|
||||||
|
# X, Y, Z = np.mgrid[:100, :100, :100]
|
||||||
|
# V = np.sqrt((X - 50)**2 + (Y - 50)**2 + (Z - 50)**2)
|
||||||
|
|
||||||
|
# for i in range(5, 45):
|
||||||
|
# vertices, triangles = mcubes.marching_cubes(V, i)
|
||||||
|
# mcubes.export_obj(vertices, triangles, f"cube_{i}.obj")
|
||||||
|
|
||||||
|
noise = perlin_noise.PerlinNoise(octaves=6, seed=1)
|
||||||
|
|
||||||
|
X, Y = np.mgrid[:100, :100]
|
||||||
|
V = [[10 * noise([x/100, y/100]) + np.sqrt((x-50)**2 + (y-50)**2) for y in range(100)] for x in range(100)]
|
||||||
|
V = np.array(V)
|
||||||
|
V = (V - V.min()) / (V.max() - V.min())
|
||||||
|
|
||||||
|
frame_list = []
|
||||||
|
for i in np.linspace(0.05, 0.55, 100):
|
||||||
|
plt.clf()
|
||||||
|
plt.subplot(1, 2, 1)
|
||||||
|
plt.imshow(V, cmap="gray")
|
||||||
|
plt.contour(V, [i], colors="r")
|
||||||
|
plt.plot([0, 0, 100, 100, 0], [0, 100, 100, 0, 0], "k-")
|
||||||
|
plt.axis('off')
|
||||||
|
|
||||||
|
plt.subplot(1, 2, 2)
|
||||||
|
plt.imshow(V > i, cmap="gray")
|
||||||
|
plt.plot([0, 0, 100, 100, 0], [0, 100, 100, 0, 0], "k-")
|
||||||
|
plt.axis('off')
|
||||||
|
|
||||||
|
plt.savefig(f"/tmp/frame.png")
|
||||||
|
frame_list.append(imageio.imread(f"/tmp/frame.png"))
|
||||||
|
|
||||||
|
imageio.mimsave('picture.gif', frame_list + frame_list[::-1], fps=60)
|
Loading…
Reference in a new issue