mandelbrot_set.scad
1 use <surface/sf_solidify.scad> 2 use <util/sum.scad> 3 4 Z0 = [0, 0]; 5 NL = 50; 6 DIV = 4.0; 7 PW = 100; 8 step = .5; 9 cw = 1.5; 10 cc = [-0.75, 0]; 11 12 thickness = 4; 13 14 function pow2(z) = [z.x ^ 2 - z.y ^ 2, 2 * z.x * z.y]; 15 16 function znxt(c) = 17 let( 18 slt = [ 19 for(n = 0, z = pow2(Z0) + c, s = z * z; 20 n < NL && s <= DIV; n = n + 1, z = pow2(z) + c, s = z * z) 21 s 22 ], 23 leng = len(slt) 24 ) 25 leng == NL ? sum(slt) / (thickness * 2) : 26 leng == 0 ? c * c : sum(slt) / leng * thickness; 27 28 left = -PW * 0.84; 29 right = PW * 1.18; 30 top = PW * 0.9; 31 pts = [ 32 for(py = -top; py <= top; py = py + step) 33 let(y = cw / PW * py + cc.y) 34 [ 35 for(px = left; px <= right; px = px + step) 36 let(x = cw / PW * px + cc.x) 37 [px, py, znxt([x, y])] 38 ] 39 ]; 40 41 b_pts = [ 42 for(py = -top; py <= top; py = py + step) 43 [ 44 for(px = left; px <= right; px = px + step) 45 [px, py, -thickness] 46 ] 47 ]; 48 49 sf_solidify(pts, b_pts);