From c3425143c396a2ab761315cfee94b24c571179b0 Mon Sep 17 00:00:00 2001 From: Justin Lin Date: Mon, 4 Apr 2022 18:58:32 +0800 Subject: [PATCH] refactor/format --- examples/spiral/L_puzzle.scad | 6 +- examples/spiral/bauer_text_sphere.scad | 9 ++- examples/spiral/heart_chain.scad | 2 +- examples/spiral/moving_fish.scad | 4 +- examples/spiral/nautilus_shell.scad | 24 ++++--- examples/spiral/seashell.scad | 23 ++----- examples/spiral/spiral_city.scad | 75 +++++++++++----------- examples/spiral/spiral_math_constants.scad | 6 +- examples/spiral/spring_dog.scad | 3 +- examples/spiral/string_tetrahedron.scad | 8 +-- examples/spiral/string_tetrahedrons.scad | 10 +-- examples/spiral/vx_spiral_text.scad | 2 +- 12 files changed, 73 insertions(+), 99 deletions(-) diff --git a/examples/spiral/L_puzzle.scad b/examples/spiral/L_puzzle.scad index e3640018..e6bb35b3 100644 --- a/examples/spiral/L_puzzle.scad +++ b/examples/spiral/L_puzzle.scad @@ -48,7 +48,7 @@ module L_puzzle(level, thickness, thickness_step = true, p = 1.272) { mirror([1, 0, 0]) rotate(-90) color(rands(0, 1, 3)) - L_piece(1, thickness_step ? thickness * 2 : thickness); + L_piece(1, thickness_step ? thickness * 2 : thickness); } } @@ -77,13 +77,13 @@ module L_puzzle(level, thickness, thickness_step = true, p = 1.272) { translate([0, offset1]) rotate(-90) { scale([1, 1, thickness_step ? 1 + level * 0.05 : 1]) - _L_puzzle(level - 1); + _L_puzzle(level - 1); translate([offset1, offset2]) mirror([1, 0, 0]) rotate(-90) scale([1, 1, thickness_step ? 1 + (level - 1) * 0.05 : 1]) - _L_puzzle(level - 2); + _L_puzzle(level - 2); } } } diff --git a/examples/spiral/bauer_text_sphere.scad b/examples/spiral/bauer_text_sphere.scad index 23e18a42..149537fb 100644 --- a/examples/spiral/bauer_text_sphere.scad +++ b/examples/spiral/bauer_text_sphere.scad @@ -17,7 +17,6 @@ module bauer_text_sphere(radius, font_name, font_size, txt_extrude, txt_scale, b pts = bauer_spiral(n, radius); if(ball) { - render() sphere(radius * 0.9); } /* @@ -25,10 +24,10 @@ module bauer_text_sphere(radius, font_name, font_size, txt_extrude, txt_scale, b Bauer R. Distribution of points on a sphere with application to star catalogs. Journal of Guidance, Control, and Dynamics. 2000;23(1):130–137 */ for(i = [0:n - 1]) { - x = pts[i][0]; - y = pts[i][1]; - z = pts[i][2]; - ya = atan2(z, sqrt(x * x + y * y)); + x = pts[i].x; + y = pts[i].y; + z = pts[i].z; + ya = atan2(z, norm([x, y])); za = atan2(y, x); render() diff --git a/examples/spiral/heart_chain.scad b/examples/spiral/heart_chain.scad index 55747890..17868b2d 100644 --- a/examples/spiral/heart_chain.scad +++ b/examples/spiral/heart_chain.scad @@ -10,7 +10,7 @@ module heart(radius, center = false) { module heart_sub_component() { translate([-radius * cos(rotated_angle), 0, 0]) - rotate(-rotated_angle) union() { + rotate(-rotated_angle) { circle(radius); translate([0, -radius, 0]) square(diameter); diff --git a/examples/spiral/moving_fish.scad b/examples/spiral/moving_fish.scad index 984793b3..6b60e8ec 100644 --- a/examples/spiral/moving_fish.scad +++ b/examples/spiral/moving_fish.scad @@ -17,8 +17,8 @@ module joint_Y(leng, width, height, ring_offset, thickness) { linear_extrude(height, center = true) difference() { hollow_out(thickness) - offset(delta = thickness, chamfer = true) - square([inner_leng, inner_width], center = true); + offset(delta = thickness, chamfer = true) + square([inner_leng, inner_width], center = true); translate([-half_thickness - inner_leng / 2, 0, 0]) square([thickness, inner_width], center = true); diff --git a/examples/spiral/nautilus_shell.scad b/examples/spiral/nautilus_shell.scad index b51f831d..60796485 100644 --- a/examples/spiral/nautilus_shell.scad +++ b/examples/spiral/nautilus_shell.scad @@ -20,21 +20,19 @@ module nautilus_shell(chambered_section_max_angle, steps, thickness) { ]; half_thickness = thickness / 2; - render() { - polyline_join(spiral) - circle(half_thickness); - for(a = [a_step:a_step * 2:chambered_section_max_angle]) { - a2 = a + 360; - a3 = a + 420; - p1 = ptf_rotate([r(a), 0], a); - p2 = ptf_rotate((p1 + ptf_rotate([r(a2), 0], a2)) * .6, -5); - p3 = ptf_rotate([r(a3), 0], a3); - - polyline_join(bezier_curve(0.1, [p1, p2, p3])) - circle(half_thickness); - } + polyline_join(spiral) + circle(half_thickness); + for(a = [a_step:a_step * 2:chambered_section_max_angle]) { + a2 = a + 360; + a3 = a + 420; + p1 = ptf_rotate([r(a), 0], a); + p2 = ptf_rotate((p1 + ptf_rotate([r(a2), 0], a2)) * .6, -5); + p3 = ptf_rotate([r(a3), 0], a3); + + polyline_join(bezier_curve(0.1, [p1, p2, p3])) + circle(half_thickness); } } diff --git a/examples/spiral/seashell.scad b/examples/spiral/seashell.scad index b60c6c9e..11a94f3c 100644 --- a/examples/spiral/seashell.scad +++ b/examples/spiral/seashell.scad @@ -58,14 +58,8 @@ module seashell() { ); points = [ - for(s = [s_s:s_step:s_e]) - for(theta = [theta_s:theta_step:theta_e]) - let( - x = x(theta, s), - y = y(theta, s), - z = z(theta, s) - ) - [x, y, z] + for(s = [s_s:s_step:s_e], theta = [theta_s:theta_step:theta_e]) + [x(theta, s), y(theta, s), z(theta, s)] ]; slen = floor((s_e - s_s) / s_step); @@ -73,15 +67,12 @@ module seashell() { c = thetalen + 1; triangles = [ - for(s = [0:slen - 1]) - for(theta = [0:thetalen - 1]) - each [ - [theta + s * c, theta + 1 + s * c, theta + (s + 1) * c], - [theta + 1 + s * c, theta + 1 + (s + 1) * c, theta + (s + 1) * c] - ] + for(s = [0:slen - 1], theta = [0:thetalen - 1]) + each [ + [theta + s * c, theta + 1 + s * c, theta + (s + 1) * c], + [theta + 1 + s * c, theta + 1 + (s + 1) * c, theta + (s + 1) * c] + ] ]; - - sf_thickenT(points, thickness, triangles); } diff --git a/examples/spiral/spiral_city.scad b/examples/spiral/spiral_city.scad index 9fb28396..671febab 100644 --- a/examples/spiral/spiral_city.scad +++ b/examples/spiral/spiral_city.scad @@ -39,8 +39,7 @@ module spiral_city(num_of_buildings, seed_value) { ra_arc = atan2(mid_pt[1], mid_pt[0]) - (i > leng_pts - 4 ? arc_a / 4.5 : arc_a / 5); translate(mid_pt) - rotate(ra_arc) - union() { + rotate(ra_arc) { difference() { union() { linear_extrude(building_h) @@ -55,7 +54,6 @@ module spiral_city(num_of_buildings, seed_value) { cubes(i, arm_distance, building_h, w_size, arc_a, arc_r, seed_value); } - roof(i, arm_distance, building_h, roof_h, arc_a, arc_r); } } @@ -66,42 +64,41 @@ module spiral_city(num_of_buildings, seed_value) { half_a = arc_a / 2; is_even = i % 2 == 0; arc_w = arm_distance / (is_even ? 2.5 : 1.7); - union() { - rs = is_undef(seed_value) ? - rands(-1, 1, 4) : - rands(-1, 1, 4, seed_value = seed_value + i); - - outer_cube_size = [w_size / 2, w_size + rs[0] , w_size + rs[1]]; - inter_cube_size = [w_size / 2, (w_size + rs[0]) * 0.85, w_size + rs[1]]; - - h_step = w_size * 1.5; - h_to = building_h - w_size * 1.5; - - a_from = -half_a + (rs[3] > 0 ? arc_a / 8 : arc_a / 6); - a_step = rs[3] > 0 ? arc_a / 4 : arc_a / 3; - - outer_cube_p = [arc_r + arc_w / 2, 0, w_size * 0.75]; - inner_cube_p = [arc_r - arc_w / 2, 0, w_size * 0.75]; - - for(h = [0:h_step: h_to]) { - translate([-arc_r, 0, h + rs[2] + 1]) - for(a = [a_from:a_step:half_a]) { - r = is_undef(seed_value) ? - rands(0, 1, 1)[0] : - rands(0, 1, 1, seed_value = seed_value)[0]; - s = [r > 0.5 ? 2.75 : 1, 1, 1]; - rotate(a) { - translate(outer_cube_p) - scale(s) - rounded_cube(outer_cube_size, 1, center = true, $fn = 7); - - translate(inner_cube_p) - scale(s) - rounded_cube(inter_cube_size, 1, center = true, $fn = 7); - } - } - } - } + + rs = is_undef(seed_value) ? + rands(-1, 1, 4) : + rands(-1, 1, 4, seed_value = seed_value + i); + + outer_cube_size = [w_size / 2, w_size + rs[0] , w_size + rs[1]]; + inter_cube_size = [w_size / 2, (w_size + rs[0]) * 0.85, w_size + rs[1]]; + + h_step = w_size * 1.5; + h_to = building_h - w_size * 1.5; + + a_from = -half_a + (rs[3] > 0 ? arc_a / 8 : arc_a / 6); + a_step = rs[3] > 0 ? arc_a / 4 : arc_a / 3; + + outer_cube_p = [arc_r + arc_w / 2, 0, w_size * 0.75]; + inner_cube_p = [arc_r - arc_w / 2, 0, w_size * 0.75]; + + for(h = [0:h_step: h_to]) { + translate([-arc_r, 0, h + rs[2] + 1]) + for(a = [a_from:a_step:half_a]) { + r = is_undef(seed_value) ? + rands(0, 1, 1)[0] : + rands(0, 1, 1, seed_value = seed_value)[0]; + s = [r > 0.5 ? 2.75 : 1, 1, 1]; + rotate(a) { + translate(outer_cube_p) + scale(s) + rounded_cube(outer_cube_size, 1, center = true, $fn = 7); + + translate(inner_cube_p) + scale(s) + rounded_cube(inter_cube_size, 1, center = true, $fn = 7); + } + } + } } module roof(i, arm_distance, building_h, roof_h, arc_a, arc_r) { diff --git a/examples/spiral/spiral_math_constants.scad b/examples/spiral/spiral_math_constants.scad index 5bffde2c..4e94785b 100644 --- a/examples/spiral/spiral_math_constants.scad +++ b/examples/spiral/spiral_math_constants.scad @@ -30,9 +30,9 @@ module spiral_math_constants(n, radius, constants, font_name, font_size, txt_ext module constant_on_spiral(constant, spiral) { for(i = [0:len(spiral) - 1]) { - x = spiral[i][0]; - y = spiral[i][1]; - z = spiral[i][2]; + x = spiral[i].x; + y = spiral[i].y; + z = spiral[i].z; ya = atan2(z, sqrt(x * x + y * y)); za = atan2(y, x); diff --git a/examples/spiral/spring_dog.scad b/examples/spiral/spring_dog.scad index e6c8e499..74b0b924 100644 --- a/examples/spiral/spring_dog.scad +++ b/examples/spiral/spring_dog.scad @@ -48,8 +48,7 @@ module dog_back(head_r, peg_radius) { $fn = 36; module foot() { - translate([head_r, 0, 0]) - union() { + translate([head_r, 0, 0]) { color("PapayaWhip") ellipse_extrude(head_r / 3) polygon(shape_ellipse([head_r / 3, head_r / 2])); diff --git a/examples/spiral/string_tetrahedron.scad b/examples/spiral/string_tetrahedron.scad index ed09d5a7..103a37a4 100644 --- a/examples/spiral/string_tetrahedron.scad +++ b/examples/spiral/string_tetrahedron.scad @@ -10,12 +10,8 @@ model = "Tetrahedron"; // [Tetrahedron, Base, Both] module string_tetrahedron(leng, diameter, segs_per_side, line_fn) { module lines_between(side1, side2, diameter, segs) { function pts(p1, p2, segs) = - let( - p = p2 - p1, - dx = p[0] / segs, - dy = p[1] / segs, - dz = p[2] / segs - ) [for(i = [0:segs]) p1 + [dx, dy, dz] * i]; + let(p = p2 - p1) + [for(i = [0:segs]) p1 + p / segs * i]; pts1 = pts(side1[0], side1[1], segs); pts2 = pts(side2[0], side2[1], segs); diff --git a/examples/spiral/string_tetrahedrons.scad b/examples/spiral/string_tetrahedrons.scad index 89a24d5d..a243e737 100644 --- a/examples/spiral/string_tetrahedrons.scad +++ b/examples/spiral/string_tetrahedrons.scad @@ -9,12 +9,7 @@ center = false; module string_tetrahedron(leng, diameter, segs_per_side, line_fn) { module lines_between(side1, side2, diameter, segs) { function pts(p1, p2, segs) = - let( - p = p2 - p1, - dx = p[0] / segs, - dy = p[1] / segs, - dz = p[2] / segs - ) [for(i = [0:segs]) p1 + [dx, dy, dz] * i]; + let(p = p2 - p1) [for(i = [0:segs]) p1 + p / segs * i]; pts1 = pts(side1[0], side1[1], segs); pts2 = pts(side2[0], side2[1], segs); @@ -95,12 +90,11 @@ module string_tetrahedrons(level, leng, diameter, segs_per_side, center) { for(i = [0:120:240]) { rotate(i) - translate([0, -center_y * 2]) rotate([a, 0, 0]) translate([0, center_y * 2]) rotate([180, 0, 0]) - scale(0.9427) + scale(0.9427) string_tetrahedrons(level - 1, half_leng, diameter, segs_per_side, center); } } diff --git a/examples/spiral/vx_spiral_text.scad b/examples/spiral/vx_spiral_text.scad index 88272aff..b9870ddc 100644 --- a/examples/spiral/vx_spiral_text.scad +++ b/examples/spiral/vx_spiral_text.scad @@ -9,7 +9,7 @@ linear_extrude(2) translate(pts[i]) difference() { square(7, center = true); - render() for(p = vx_ascii(tx[i], center = true)) { + for(p = vx_ascii(tx[i], center = true)) { translate(p) square(.8); } }