1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-01-17 14:18:13 +01:00
dotSCAD/examples/mandelbrot_set.scad

49 lines
990 B
OpenSCAD
Raw Normal View History

2022-06-06 13:11:46 +08:00
use <surface/sf_solidify.scad>
use <util/sum.scad>
2022-05-30 12:57:42 +08:00
Z0 = [0, 0];
NL = 50;
DIV = 4.0;
PW = 100;
step = .5;
cw = 1.5;
cc = [-0.75, 0];
2022-05-30 17:39:42 +08:00
thickness = 4;
2022-05-30 12:57:42 +08:00
function pow2(z) = [z.x ^ 2 - z.y ^ 2, 2 * z.x * z.y];
function znxt(c) =
let(
slt = [
for(n = 0, z = pow2(Z0) + c, s = z * z;
n < NL && s <= DIV; n = n + 1, z = pow2(z) + c, s = z * z)
s
],
leng = len(slt)
)
2022-05-30 17:39:42 +08:00
leng == NL ? sum(slt) / (thickness * 2) :
leng == 0 ? c * c : sum(slt) / leng * thickness;
2022-05-30 12:57:42 +08:00
2022-05-30 17:39:42 +08:00
left = -PW * 0.84;
right = PW * 1.18;
top = PW * 0.9;
2022-05-30 12:57:42 +08:00
pts = [
2022-05-30 17:39:42 +08:00
for(py = -top; py <= top; py = py + step)
2022-05-30 12:57:42 +08:00
let(y = cw / PW * py + cc.y)
[
for(px = left; px <= right; px = px + step)
2022-05-30 17:39:42 +08:00
let(x = cw / PW * px + cc.x)
[px, py, znxt([x, y])]
2022-05-30 12:57:42 +08:00
]
];
2022-05-30 17:39:42 +08:00
b_pts = [
for(py = -top; py <= top; py = py + step)
[
for(px = left; px <= right; px = px + step)
[px, py, -thickness]
]
];
2022-05-30 12:57:42 +08:00
2022-05-30 17:39:42 +08:00
sf_solidify(pts, b_pts);