From 4b7133252f20d69966fb1e4be14abe72560fb7b7 Mon Sep 17 00:00:00 2001 From: Justin Lin Date: Thu, 14 Jul 2022 10:05:21 +0800 Subject: [PATCH] add tetrapod_doll --- examples/tetrapod_doll.scad | 100 ++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 examples/tetrapod_doll.scad diff --git a/examples/tetrapod_doll.scad b/examples/tetrapod_doll.scad new file mode 100644 index 00000000..60ab3906 --- /dev/null +++ b/examples/tetrapod_doll.scad @@ -0,0 +1,100 @@ +use +use +use +use + +radius = 20; +$fn = 6; // multiples of 6 + +if($preview) { + points = pp_poisson2([150, 150], radius * 2.25); + for(p = points) { + translate(p) + rotate(rand(-25, 25)) + tetrapod_doll(); + } +} +else { + tetrapod_doll(); +} + +module tetrapod_doll() { + function __angy_angz(p1, p2) = + let(v = p2 - p1) + [ + atan2(v.z, norm([v.x, v.y])), + atan2(v.y, v.x) + ]; + + module eye() { + color("white") + difference() { + translate([radius / 5.75 / 2, 0, 0]) + sphere(radius / 5.75, $fn = 48); + translate([-radius / 2, 0, 0]) + cube(radius, center = true); + } + } + + vertices = geom_tetrahedron(radius = radius)[0]; + + ayz = __angy_angz(vertices[0], [0, 0, 0]); + + color(rands(0, 1, 3)) + difference() { + rotate([0, 90 - ayz[0], 0]) + rotate(ayz[1]) + for(p = vertices) { + ayz = __angy_angz(p, [0, 0, 0]); + + rotate([0, 90 + ayz[0], ayz[1]]) + translate([0, 0, 2 / 4.158]) + rounded_cylinder( + radius = [radius * .4, radius * .275], + h = radius, + round_r = 2 + ); + } + + rotate(40) + translate([radius * .2, 0, radius * .6]) + scale(1.05) + eye(); + + rotate(-40) + translate([radius * .2, 0, radius * .6]) + scale(1.05) + eye(); + } + + if($preview) { + rotate(40) + translate([radius * .2, 0, radius * .6]) + eye(); + + rotate(-40) + translate([radius * .2, 0, radius * .6]) + eye(); + + color("black") + rotate([rand(-3, 3), rand(-3, 3), 30 + rand(-3, 3)]) + translate([radius * .2, 0, radius * .6]) + translate([radius / 5, 0, 0]) + sphere(radius / 5.75 / 2, $fn = 48); + + color("black") + rotate([rand(-3, 3), rand(-3, 3), -30 + rand(-3, 3)]) + translate([radius * .2, 0, radius * .6]) + translate([radius / 5, 0, 0]) + sphere(radius / 5.75 / 2, $fn = 48); + } + else { + translate([radius, 0, 0]) + rotate([0, -90, 0]) + eye(); + + translate([radius * 1.5, 0, 0]) + rotate([0, -90, 0]) + eye(); + } +}