initial commit

This commit is contained in:
Alexander Gehrke 2025-04-13 14:04:24 +02:00
commit 76550363b3

121
divider.scad Normal file
View file

@ -0,0 +1,121 @@
$fa = 1;
$fs = 0.4;
index = 0;
icon = "icons/classes/Mystic.svg";
tab_offset = 14;
target_icon_height = 9;
target_icon_width = 9;
module outer_tab(tab_height = 10, tab_width = 16, tab_angle = 45, flip = false)
{
slope_width = tab_height * tan(tab_angle);
tab = ([
[ 0, 0 ],
[ 0, tab_height ],
[ tab_width, tab_height ],
[ tab_width + slope_width, 0 ],
]);
if (flip)
{
translate([ tab_width + slope_width, 0, 0 ]) mirror([ 1, 0, 0 ]) polygon(tab);
}
else
{
polygon(tab);
}
}
module inner_tab(tab_height = 10, tab_width = 16, tab_angle = 45)
{
slope_width = tab_height * tan(tab_angle);
tab = ([
[ 0, 0 ],
[ slope_width, tab_height ],
[ tab_width + slope_width, tab_height ],
[ tab_width + 2 * slope_width, 0 ],
]);
polygon(tab);
}
module card(index = 0, thickness = 0.6, icon = "", icon_thickness = 0.4, horizontal = 87, vertical = 61,
tab_height = 10, tab_width = 16, tab_angle = 45)
{
slope_width = tab_height * tan(tab_angle);
is_inner = index > 0 && index < 3;
inner_tab_width = tab_width + 2 * slope_width;
outer_tab_width = tab_width + slope_width;
positions = [
0,
tab_offset,
horizontal - tab_offset - inner_tab_width,
horizontal - outer_tab_width,
];
linear_extrude(thickness)
{
square([ horizontal, vertical ]);
translate([ positions[index], vertical, 0 ])
{
if (is_inner)
inner_tab(tab_height, tab_width, tab_angle);
else
outer_tab(tab_height, tab_width, tab_angle, index == 3);
}
}
if (icon != "")
{
// If no icon width is given, we assume the icon is square.
icon_width = (target_icon_width == 0 ? target_icon_height : target_icon_width);
icon_offset = (index > 0 ? slope_width : 0) + tab_width / 2 - icon_width / 2;
translate([ positions[index] + icon_offset, vertical + 0.5, thickness - 0.001 ]) color("blue")
linear_extrude(icon_thickness + 0.001) resize([ target_icon_width, target_icon_height, 0 ], auto = true)
offset(delta = 0.001) import(icon);
}
}
module card2(index = 0, thickness = 0.6, icon = "", icon_thickness = 0.4, horizontal = 87, vertical = 61, tabs = 4,
tab_height = 10, tab_width = 16, tab_angle = 45)
{
assert(0 <= index && index < tabs, str("Tab index out of range. Index: ", index, " Tabs: ", tabs));
is_inner = index > 0 && index < tabs - 1;
tab_spacing = (horizontal - tabs * tab_width) / (tabs - 1);
assert(tab_spacing >= 0, "Card width is too small for the number and width of tabs.");
position = index * (tab_width + tab_spacing);
slope_width = tab_height * tan(tab_angle);
indent = index == 0 ? 0 : (tab_width + tab_spacing) * index - slope_width;
color("black") linear_extrude(thickness)
{
square([ horizontal, vertical ]);
translate([ indent, vertical, 0 ])
{
if (is_inner)
inner_tab(tab_height, tab_width, tab_angle);
else
outer_tab(tab_height, tab_width, tab_angle, index == tabs - 1);
}
}
if (icon != "")
{
// If no icon width is given, we assume the icon is square.
icon_width = (target_icon_width == 0 ? target_icon_height : target_icon_width);
icon_x_offset = (index > 0 ? slope_width : 0) + tab_width / 2 - icon_width / 2;
icon_y_offset = tab_height / 2 - target_icon_height / 2;
translate([ indent + icon_x_offset, vertical + icon_y_offset, thickness - 0.001 ]) color("lime")
linear_extrude(icon_thickness + 0.001) resize([ target_icon_width, target_icon_height, 0 ], auto = true)
offset(delta = 0.001) import(icon);
}
}
card(index, icon = icon, horizontal = 61, vertical = 87);
translate([ 100, 0, 0 ])
{
card2(index + 0, icon = icon, horizontal = 61, vertical = 87, tab_width = 16, tabs = 3, tab_angle = 30);
card2(index + 1, icon = icon, horizontal = 61, vertical = 87, tab_width = 16, tabs = 3, tab_angle = 30);
card2(index + 2, icon = icon, horizontal = 61, vertical = 87, tab_width = 16, tabs = 3, tab_angle = 30);
}