1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-02-22 08:32:54 +01:00
dotSCAD/examples/twist_bottle.scad

104 lines
2.6 KiB
OpenSCAD
Raw Normal View History

2019-07-30 15:49:31 +08:00
include <hollow_out.scad>;
2019-09-22 20:19:52 +08:00
2019-07-30 15:49:31 +08:00
/* [Basic] */
2019-09-22 20:19:52 +08:00
shape = "Heart"; // [Flower, Circle, Heart]
2019-07-30 15:49:31 +08:00
model = "Outer"; // [Outer, Inner]
width = 30;
radius = 20;
height = 100;
thickness = 1;
spacing = 0.65;
twist = 180;
/* [Advanced] */
slices = 200;
module twist_bottle(model, height, thickness, twist, spacing, convexity, slices) {
2019-09-22 20:19:52 +08:00
$fn = 48;
2019-07-30 15:49:31 +08:00
module outer_container() {
translate([0, 0, thickness])
2019-09-26 08:53:47 +08:00
linear_extrude(height = height, twist = twist, slices = slices)
hollow_out(thickness) children();
2019-07-30 15:49:31 +08:00
linear_extrude(thickness)
children();
}
module inner_container() {
2019-09-22 20:19:52 +08:00
linear_extrude(height = height, twist = twist, slices = slices)
2019-07-30 15:49:31 +08:00
hollow_out(thickness)
offset(r = -thickness - spacing)
children();
translate([0, 0, height])
2019-09-26 08:53:47 +08:00
rotate(twist)
linear_extrude(thickness)
children();
2019-07-30 15:49:31 +08:00
}
if(model == "Outer") {
outer_container()
children();
2019-09-22 20:19:52 +08:00
} else if(model == "Inner") {
2019-07-30 15:49:31 +08:00
translate([0, 0, height + thickness])
2019-09-26 08:53:47 +08:00
rotate([180, 0, 0])
inner_container()
children();
2019-07-30 15:49:31 +08:00
}
}
2019-09-22 20:19:52 +08:00
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])
2019-09-26 08:53:47 +08:00
rotate(-45) {
circle(radius);
translate([0, -radius, 0])
square(diameter);
}
2019-09-22 20:19:52 +08:00
}
offsetX = center ? 0 : radius + radius * cos(45);
offsetY = center ? 1.5 * radius * sin45 - 0.5 * radius : 3 * radius * sin45;
2019-09-26 08:53:47 +08:00
translate([offsetX, offsetY, 0]) {
2019-09-22 20:19:52 +08:00
heart_sub_component(radius);
mirror([1, 0, 0]) heart_sub_component(radius);
}
}
2019-07-30 15:49:31 +08:00
if(shape == "Flower") {
2019-09-22 20:19:52 +08:00
twist_bottle(model, height, thickness, twist, spacing, slices) union() {
2019-07-30 15:49:31 +08:00
for(i = [0:3]) {
rotate(90 * i)
2019-09-26 08:53:47 +08:00
translate([radius * 0.5, 0, 0])
circle(radius * 0.5);
2019-07-30 15:49:31 +08:00
}
}
2019-09-22 20:19:52 +08:00
} else if(shape == "Circle") {
2019-09-26 08:53:47 +08:00
twist_bottle(model, height, thickness, twist, spacing, slices)
difference() {
2019-07-30 15:49:31 +08:00
circle(radius);
2019-09-22 20:19:52 +08:00
union() {
for(a = [0:120:240]) {
rotate(a)
2019-09-26 08:53:47 +08:00
translate([radius, 0, 0])
circle(radius / 4);
2019-09-22 20:19:52 +08:00
}
2019-07-30 15:49:31 +08:00
}
}
2019-09-22 20:19:52 +08:00
} else if(shape == "Heart") {
twist_bottle(model, height, thickness, twist, spacing, slices)
heart(radius * 1.9 / (3 * sin(45) + 1), center = true);
}