Skip to content

Instantly share code, notes, and snippets.

@JakeSays
Last active November 2, 2021 03:25
Show Gist options
  • Save JakeSays/0e737352bf38ed8d6a475dfa05f86dd3 to your computer and use it in GitHub Desktop.
Save JakeSays/0e737352bf38ed8d6a475dfa05f86dd3 to your computer and use it in GitHub Desktop.
module number(digit, drawTop = false, drawBottom = false, whole = false, size = 130,
forceShowCaps = $forceShowCaps,
fShowDevice = $forceShowDevice,
nofliptop = false)
{
font = "Comic Sans MS:style=Bold";
numberSize = size;
numberHeight = 30;
numberValue = str(digit);
sideThickness = 1.5;
topThickness = 3;
shelfZOffset = 12;
shelfHeight = 2;
shelfThickness = 2;
bottomThickness = numberBaseThickness();
if (drawBottom)
{
bottom();
}
if (drawTop)
{
top();
}
module numberText()
{
fontres = $preview ? 50 : 250;
text(numberValue, size = numberSize, font = font, $fn = fontres);
}
module bottom()
{
color("lightgrey", alpha = 1)
linear_extrude(bottomThickness)
offset(-(sideThickness + .2))
numberText();
}
module top()
{
module topCore()
{
module sideOuline(o)
{
difference()
{
offset(o + .5)
children();
offset(-o + .5) children();
}
}
module topShelfOutline(o)
{
difference()
{
offset(o + .5)
children();
offset(-(o + shelfThickness)) children();
}
}
module sides()
{
difference()
{
linear_extrude(numberHeight)
sideOuline(sideThickness)
numberText();
//what i really want is:
children_of_module_number();
//instead of hardcoding them like this:
if (digit == 7)
{
translate([55, 130, -epsilon()])
{
cube([3, 6, 8]);
}
translate([33, -8, -epsilon()])
{
cube([3, 6, 8]);
}
}
}
}
union()
{
sides();
if (!whole && !nofliptop)
{
color("green", alpha = .4)
translate([0, 0, numberHeight - topThickness])
linear_extrude(topThickness)
numberText();
}
Blue()
translate([0, 0, shelfZOffset])
linear_extrude(shelfHeight)
topShelfOutline(sideThickness)
numberText();
}
}
if (whole)
{
translate([0, 0, -shelfZOffset + numberBaseThickness()])
topCore();
}
else
{
if (!nofliptop)
{
rotate(a=180, v=[0, 1, 0])
translate([0, 0, -numberHeight])
topCore();
}
else
{
topCore();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment