1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-02-20 07:34:36 +01:00
dotSCAD/examples/maze/heart_maze.scad

129 lines
3.2 KiB
OpenSCAD
Raw Normal View History

2020-01-28 10:08:01 +08:00
use <line2d.scad>;
use <hollow_out.scad>;
use <ellipse_extrude.scad>;
use <arc.scad>;
2020-12-20 10:49:16 +08:00
use <maze/mz_square_cells.scad>;
2020-12-08 18:04:34 +08:00
use <maze/mz_square_get.scad>;
2019-10-05 16:18:32 +08:00
2019-10-06 09:53:18 +08:00
radius_of_heart = 12;
2019-10-05 17:27:53 +08:00
height_of_heart = 25;
tip_r_of_heart = 5;
2019-10-05 16:18:32 +08:00
wall_thickness = 2;
2020-12-20 10:49:16 +08:00
ccells = 6;
2019-10-05 16:18:32 +08:00
levels = 3;
2019-10-05 17:27:53 +08:00
$fn = 36;
2019-10-05 16:18:32 +08:00
module heart(radius, tip_r) {
offset_h = 0.410927 * radius;
translate([radius * 0.707107, offset_h, 0])
rotate([0, 0, -45])
hull() {
circle(radius);
translate([radius - tip_r, -radius * 2 + tip_r, 0])
circle(tip_r);
}
translate([-radius * 0.707107, offset_h, 0])
rotate([0, 0, 45])
hull() {
circle(radius);
translate([-radius + tip_r, -radius * 2 + tip_r, 0])
circle(tip_r);
}
}
module ring_heart(radius, thickness) {
hollow_out(thickness)
2019-10-06 09:28:06 +08:00
heart(radius + thickness / 2, 5);
2019-10-05 16:18:32 +08:00
}
module ring_heart_sector(radius, angle, thickness, width) {
intersection() {
2019-10-06 10:06:06 +08:00
ring_heart(radius, thickness + 0.2);
2019-10-05 16:18:32 +08:00
rotate([0, 0, angle])
2019-10-06 10:06:06 +08:00
line2d([0, 0], [0, radius * 3 + width + thickness], width);
2019-10-05 16:18:32 +08:00
}
}
module heart_to_heart_wall(radius, length, angle, thickness) {
intersection() {
difference() {
2019-10-05 17:27:53 +08:00
heart(radius + thickness / 2 + length , 5);
heart(radius + thickness / 2, 5);
2019-10-05 16:18:32 +08:00
}
rotate([0, 0, angle])
line2d([0, 0], [0, (radius + length) * 2 + thickness], thickness);
}
}
2020-12-20 17:57:30 +08:00
module heart_maze(cells, radius, ccells, levels, thickness = 1) {
2020-12-20 18:15:11 +08:00
function no_wall(cell) = get_type(cell) == "NO_WALL";
function top_wall(cell) = get_type(cell) == "TOP_WALL";
function right_wall(cell) = get_type(cell) == "RIGHT_WALL";
function top_right_wall(cell) = get_type(cell) == "TOP_RIGHT_WALL";
2020-02-16 16:28:31 +08:00
2020-12-20 10:49:16 +08:00
function get_x(cell) = mz_square_get(cell, "x");
function get_y(cell) = mz_square_get(cell, "y");
2020-12-20 18:15:11 +08:00
function get_type(cell) = mz_square_get(cell, "t");
2020-02-16 16:28:31 +08:00
2020-12-20 10:49:16 +08:00
arc_angle = 360 / ccells;
2019-10-05 16:18:32 +08:00
r = radius / (levels + 1);
difference() {
render() union() {
for(i = [1 : levels + 1]) {
ring_heart(r * i, thickness);
}
2020-12-20 17:57:30 +08:00
for(i = [0:len(cells) - 1]) {
cell = cells[i];
2020-12-20 10:49:16 +08:00
cr = get_x(cell) + 1;
cc = get_y(cell);
2019-10-05 16:18:32 +08:00
angle = cc * arc_angle;
2020-12-20 10:49:16 +08:00
if(top_wall(cell) || top_right_wall(cell)) {
2019-10-05 16:18:32 +08:00
heart_to_heart_wall(r * cr, r, cc * arc_angle , thickness);
}
}
}
render() union() {
// road to the next level
2020-12-20 17:57:30 +08:00
for(i = [0:len(cells) - 1]) {
cell = cells[i];
2020-12-20 10:49:16 +08:00
cr = get_x(cell) + 1;
cc = get_y(cell);
2019-10-05 16:18:32 +08:00
2020-12-20 10:49:16 +08:00
if(no_wall(cell) || top_wall(cell)) {
2019-10-06 09:53:18 +08:00
ring_heart_sector(r * (cr + 1), (cc + 0.5) * arc_angle , thickness, thickness * 0.75);
2019-10-05 16:18:32 +08:00
}
}
}
}
}
2020-12-20 17:57:30 +08:00
cells = mz_square_cells(
2020-12-20 10:49:16 +08:00
ccells, levels, y_wrapping = true
2019-10-06 09:29:22 +08:00
);
2019-10-05 17:27:53 +08:00
intersection() {
2019-10-06 09:55:52 +08:00
union() {
2019-10-05 17:27:53 +08:00
ellipse_extrude(height_of_heart / 2)
heart(radius_of_heart + wall_thickness , tip_r_of_heart);
2019-10-05 17:08:14 +08:00
2019-10-05 17:27:53 +08:00
mirror([0, 0, 1])
ellipse_extrude(height_of_heart / 2)
heart(radius_of_heart + wall_thickness, tip_r_of_heart);
}
linear_extrude(height_of_heart, center = true)
2020-12-20 17:57:30 +08:00
heart_maze(cells, radius_of_heart, ccells, levels, wall_thickness);
2019-10-05 17:27:53 +08:00
}
2019-10-05 17:08:14 +08:00
2019-10-05 17:27:53 +08:00
linear_extrude(wall_thickness * 2, center = true)
translate([0, radius_of_heart * 1.25])
2019-10-06 09:28:06 +08:00
arc(radius = radius_of_heart / 3, angle = [25, 155], width = wall_thickness);