From ea401ce009f34085979b1eb9a256b0e0448fffce Mon Sep 17 00:00:00 2001 From: Justin Lin Date: Sat, 28 Sep 2019 09:58:30 +0800 Subject: [PATCH] refactor --- examples/sierpinski_pyramid.scad | 41 ++++++++++++++++---------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/examples/sierpinski_pyramid.scad b/examples/sierpinski_pyramid.scad index 0a2bd129..5b5316b8 100644 --- a/examples/sierpinski_pyramid.scad +++ b/examples/sierpinski_pyramid.scad @@ -1,40 +1,39 @@ include ; -width = 100; -min_width = 5; +side_leng = 100; +min_len = 5; thickness = 2.5; -$fn = 4; -sierpinski_pyramid(width, min_width, thickness); +sierpinski_pyramid(side_leng, min_len, thickness, $fn = 4); -module sierpinski_pyramid(width, min_width, thickness) { - pyramid_frame(width, thickness); - if(width > min_width){ - half_w = width / 2; - h = half_w * 0.707107; - pt = [width / 4, width / 4, 0]; +module sierpinski_pyramid(side_leng, min_len, thickness) { + pyramid_frame(side_leng, thickness); + if(side_leng > min_len){ + half_len = side_leng / 2; + h = half_len * 0.707107; + pt = [side_leng / 4, side_leng / 4, 0]; for(i=[0:3]) { rotate([0, 0, i * 90]) translate(pt) - sierpinski_pyramid(half_w, min_width, thickness); + sierpinski_pyramid(half_len, min_len, thickness); } translate([0, 0, h]) - sierpinski_pyramid(half_w, min_width, thickness); + sierpinski_pyramid(half_len, min_len, thickness); } } -module pyramid_frame(width, thickness) { - half_w = width / 2; - h = half_w * 1.414214; +module pyramid_frame(side_leng, thickness) { + half_len = side_leng / 2; + h = half_len * 1.414214; - tri_pts = [[0, 0, h], [half_w, half_w, 0], [half_w, -half_w, 0], [0, 0, h]]; - line_pts = [[half_w, half_w, 0], [-half_w, half_w, 0]]; + tri_pts = [[0, 0, h], [half_len, half_len, 0], [half_len, -half_len, 0], [0, 0, h]]; + line_pts = [[half_len, half_len, 0], [-half_len, half_len, 0]]; - hull_polyline3d(tri_pts, thickness = thickness); + hull_polyline3d(tri_pts, thickness); mirror([1, 0, 0]) - hull_polyline3d(tri_pts, thickness = thickness); + hull_polyline3d(tri_pts, thickness); - hull_polyline3d(line_pts, thickness = thickness); + hull_polyline3d(line_pts, thickness); mirror([0, 1, 0]) - hull_polyline3d(line_pts, thickness = thickness); + hull_polyline3d(line_pts, thickness); } \ No newline at end of file