From 1f9ee747ae5df2d3bf2b3170361aaf89437f3750 Mon Sep 17 00:00:00 2001 From: Justin Lin Date: Sun, 22 Sep 2019 20:19:52 +0800 Subject: [PATCH] refactor --- examples/twist_bottle.scad | 63 ++++++++++++++++++++++++++++---------- 1 file changed, 46 insertions(+), 17 deletions(-) diff --git a/examples/twist_bottle.scad b/examples/twist_bottle.scad index c32e37ca..7f82c94a 100644 --- a/examples/twist_bottle.scad +++ b/examples/twist_bottle.scad @@ -1,7 +1,8 @@ include ; + /* [Basic] */ -shape = "Flower"; // [Flower, Circle] +shape = "Heart"; // [Flower, Circle, Heart] model = "Outer"; // [Outer, Inner] width = 30; radius = 20; @@ -12,15 +13,14 @@ twist = 180; /* [Advanced] */ -convexity = 10; slices = 200; module twist_bottle(model, height, thickness, twist, spacing, convexity, slices) { - $fn = 96; + $fn = 48; module outer_container() { translate([0, 0, thickness]) - linear_extrude(height = height, twist = twist, convexity = convexity, slices = slices) + linear_extrude(height = height, twist = twist, slices = slices) hollow_out(thickness) children(); linear_extrude(thickness) @@ -28,7 +28,7 @@ module twist_bottle(model, height, thickness, twist, spacing, convexity, slices) } module inner_container() { - linear_extrude(height = height, twist = twist, convexity = convexity, slices = slices) + linear_extrude(height = height, twist = twist, slices = slices) hollow_out(thickness) offset(r = -thickness - spacing) children(); @@ -42,8 +42,7 @@ module twist_bottle(model, height, thickness, twist, spacing, convexity, slices) if(model == "Outer") { outer_container() children(); - } - else { + } else if(model == "Inner") { translate([0, 0, height + thickness]) rotate([180, 0, 0]) inner_container() @@ -51,23 +50,53 @@ module twist_bottle(model, height, thickness, twist, spacing, convexity, slices) } } +module heart(radius, center = false) { + sin45 = sin(45); + cos45 = cos(45); + + module heart_sub_component(radius) { + diameter = radius * 2; + $fn = 48; + + translate([-radius * cos45, 0, 0]) + rotate(-45) union() { + circle(radius); + translate([0, -radius, 0]) + square(diameter); + } + } + + + offsetX = center ? 0 : radius + radius * cos(45); + offsetY = center ? 1.5 * radius * sin45 - 0.5 * radius : 3 * radius * sin45; + + translate([offsetX, offsetY, 0]) union() { + heart_sub_component(radius); + mirror([1, 0, 0]) heart_sub_component(radius); + } +} + if(shape == "Flower") { - twist_bottle(model, height, thickness, twist, spacing, convexity, slices) union() { + twist_bottle(model, height, thickness, twist, spacing, slices) union() { for(i = [0:3]) { rotate(90 * i) translate([radius * 0.5, 0, 0]) circle(radius * 0.5); } } -} - -if(shape == "Circle") { - twist_bottle(model, height, thickness, twist, spacing, convexity, slices) difference() { +} else if(shape == "Circle") { + twist_bottle(model, height, thickness, twist, spacing, slices) difference() { circle(radius); - for(a = [0:120:240]) { - rotate(a) - translate([radius, 0, 0]) - circle(radius / 4); + union() { + for(a = [0:120:240]) { + rotate(a) + translate([radius, 0, 0]) + circle(radius / 4); + } } } -} \ No newline at end of file +} else if(shape == "Heart") { + twist_bottle(model, height, thickness, twist, spacing, slices) + heart(radius * 1.9 / (3 * sin(45) + 1), center = true); +} +