poker-chips/chip.scad

69 lines
1.8 KiB
OpenSCAD

// Diameter of the coin (mm)
diameter = 39;
// Height of the coin (mm)
height = 3.5;
// Engraving depth (mm)
depth = 0.4;
// Number of sides on your coin
sides = 360; // [3:360]
// How many spokes do you want?
spokes = 6; // [0:12]
// Text to display
text = "100";
// The font must be installed locally on your system
font = "Droid Sans:style=Bold";
fontScale = (
sides == 3 ? 0.50
: sides == 4 ? 0.80
: sides == 5 ? 0.80
: sides == 6 ? 0.90
: 1.00
);
// Enough width to fit four digits
fontSize = diameter * 0.21 * fontScale;
// Rotate odd-numbers of sides to maximize width
rotation = (sides%2)?90:0;
module chip() {
intersection() {
cylinder(h=height, d=diameter, center=true, $fn=sides);
union() {
difference() {
cube([diameter, diameter, height], center=true);
difference() {
cylinder(h=height, d=diameter*0.8, center=true, $fn=sides);
cylinder(h=height, d=diameter*0.7, center=true, $fn=sides);
}
}
spokeHeight = height - (2*depth);
if (spokes == 0) {
cube([diameter, diameter, spokeHeight], center=true);
} else {
spokeWidth = (diameter/spokes) * 0.8;
rotate((sides+spokes)%2?90:0) {
for (i = [0 : 360/spokes : 360]) {
rotate(i) translate([diameter/2, 0, 0]) cube([diameter, spokeWidth, spokeHeight], center=true);
}
}
}
}
}
}
difference() {
rotate(rotation) chip();
translate([0, 0, height/2-depth])
linear_extrude(height=depth+0.1, convexity = 10, twist = 0)
text(text=text, font=font, size=fontSize, halign="center", valign="center");
}