|
1 | 1 | import bpy |
2 | | - |
3 | | -import numpy as np |
4 | | -import PIL.Image |
5 | 2 | from mathutils import Vector |
| 3 | +import numpy as np |
6 | 4 |
|
7 | 5 | bl_info = { |
8 | 6 | "name": "Shellz", |
@@ -208,16 +206,12 @@ def normalize_object_size(blender_object): |
208 | 206 | v.co -= vMin |
209 | 207 |
|
210 | 208 |
|
211 | | -class GeneratingCurve(object): |
212 | | - pass |
213 | | - |
214 | 209 |
|
215 | 210 | def cot(alpha): |
216 | 211 | return 1 / np.tan(alpha) |
217 | 212 |
|
218 | 213 |
|
219 | | -class Ellipse(GeneratingCurve): |
220 | | - |
| 214 | +class Ellipse: |
221 | 215 | def __init__(self, a=1, b=1, A=1, alpha=30, beta=30, omega=0, phi=0, mu=0, L=0, N=0, W_1=0, W_2=0, P=0): |
222 | 216 | """ |
223 | 217 | Initializes an elliptical generating curve with semi-axes a and b. |
@@ -291,7 +285,7 @@ def _nodules(self, s, theta): |
291 | 285 |
|
292 | 286 | class Shell(object): |
293 | 287 |
|
294 | | - def __init__(self, helico_spiral, generating_curve): |
| 288 | + def __init__(self, helico_spiral: "HelicoSpiral", generating_curve: Ellipse): |
295 | 289 | """ |
296 | 290 | Initialize a shell by specifying the generating curve and the helico spiral. |
297 | 291 |
|
@@ -340,47 +334,3 @@ def __call__(self, theta): |
340 | 334 | h[2] = -np.cos(beta) * np.exp(theta * cot) |
341 | 335 |
|
342 | 336 | return A * h |
343 | | - |
344 | | - |
345 | | -def generate_texture(rho, kappa, mu, rho_0, sigma, nu, D_a, D_s, N, M): |
346 | | - t_values, dt = np.linspace(0, 1, N, retstep=True) |
347 | | - x_values, dx = np.linspace(0, 1, M, retstep=True) |
348 | | - |
349 | | - s = np.zeros((N, M)) |
350 | | - a = np.zeros((N, M)) |
351 | | - |
352 | | - rho_array = np.random.normal(rho, scale=0.025, size=(N, M)) |
353 | | - s[0] = np.zeros(M) |
354 | | - a[0] = np.zeros(M) |
355 | | - |
356 | | - def rhs(a_prev, s_prev): |
357 | | - da_ddx = np.gradient(np.gradient(a_prev)) |
358 | | - ds_ddx = np.gradient(np.gradient(s_prev)) |
359 | | - |
360 | | - da_dt = rho * s_prev * (a_prev ** 2 / (1 + kappa * a_prev ** 2) + rho_0) - mu * a_prev + D_a * da_ddx |
361 | | - ds_dt = sigma - rho * s_prev * (a_prev ** 2 / (1 + kappa * a_prev ** 2) + rho_0) - nu * s_prev + D_s * ds_ddx |
362 | | - |
363 | | - return da_dt, ds_dt |
364 | | - |
365 | | - for i in range(0, N - 1): |
366 | | - rho = rho_array[i] |
367 | | - da_dt, ds_dt = rhs(a[i], s[i]) |
368 | | - |
369 | | - a[i + 1] = a[i] + dt * da_dt |
370 | | - s[i + 1] = s[i] + dt * ds_dt |
371 | | - |
372 | | - return a / np.max(a, axis=(0, 1)) |
373 | | - |
374 | | - |
375 | | -if __name__ == '__main__': |
376 | | - register() |
377 | | - |
378 | | - texture_map = generate_texture(rho=0.1, rho_0=0.005, mu=0.1, D_a=0.004, sigma=0.012, nu=0, D_s=0.0, kappa=1, |
379 | | - N=100, |
380 | | - M=100) |
381 | | - import matplotlib.pyplot as plt |
382 | | - |
383 | | - plt.imshow(texture_map) |
384 | | - map = np.uint8(texture_map * 255) |
385 | | - img = PIL.Image.fromarray(map) |
386 | | - img.save('test.png') |
0 commit comments