distorted_vase.scad
1 use <shape_circle.scad> 2 use <bezier_curve.scad> 3 use <sweep.scad> 4 use <path_scaling_sections.scad> 5 use <bijection_offset.scad> 6 use <util/rand.scad> 7 use <noise/nz_perlin2s.scad> 8 use <noise/nz_perlin3s.scad> 9 10 beginning_radius = 15; 11 thickness = 2; 12 fn = 180; 13 amplitude = 10; 14 curve_step = 0.01; 15 smoothness = 15; 16 // Perlin noise 2D or 3D 17 perlin = 2; // [2, 3] 18 bottom = "YES"; // ["YES", "NO"] 19 epsilon = 0.000001; 20 21 distorted_vase(beginning_radius, thickness, fn, amplitude, curve_step, smoothness, perlin, epsilon); 22 23 module distorted_vase(beginning_radius, thickness, fn, amplitude,curve_step, smoothness, perlin, epsilon) { 24 seed = rand() * 1000; 25 section = shape_circle(radius = beginning_radius, $fn = fn); 26 pt = [beginning_radius, 0, 0]; 27 28 edge_path = bezier_curve(curve_step, [ 29 pt, 30 pt + [15, 0, 20], 31 pt + [45, 0, 50], 32 pt + [20, 0, 70], 33 pt + [5, 0, 80], 34 pt + [-5, 0, 100], 35 pt + [10, 0, 140] 36 ]); 37 38 39 sections = path_scaling_sections(section, edge_path); 40 41 noise = perlin == 2 ? function(pts, seed) nz_perlin2s(pts, seed) : 42 function(pts, seed) nz_perlin3s(pts, seed); 43 44 noisy = [ 45 for(section = sections) 46 let(nz = noise(section / smoothness, seed)) 47 [ 48 for(i = [0:len(nz) - 1]) 49 let( 50 p = section[i], 51 p2d = [p[0], p[1]], 52 noisyP = p2d + p2d / norm(p2d) * nz[i] * amplitude 53 ) 54 [noisyP[0], noisyP[1], p[2]] 55 ] 56 ]; 57 58 offset_noisy = [ 59 for(section = noisy) 60 let( 61 offset_s = bijection_offset(section, thickness, epsilon) 62 ) 63 [ 64 for(i = [0:len(offset_s) - 1]) 65 [offset_s[i][0], offset_s[i][1], section[i][2]] 66 ] 67 ]; 68 69 all = [ 70 for(i = [0:len(offset_noisy) - 1]) 71 concat( 72 offset_noisy[i], 73 noisy[i] 74 ) 75 ]; 76 77 sweep(all, triangles = "HOLLOW"); 78 79 if(bottom == "YES") { 80 sweep([ 81 for(section = noisy) 82 if(section[0][2] < thickness) 83 section 84 ]); 85 } 86 }