Last active
January 26, 2020 05:33
-
-
Save tinkerology/c18d0ff85018b0c89c472c9c70780588 to your computer and use it in GitHub Desktop.
OpenSCAD module to draw numbers around a circle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MODEL_COUNT=1; | |
function countFunc(count,numbers) = | |
(count > 0 ? count : len(numbers)); | |
function lableFunc(i, numbers) = | |
( len(numbers) > i ? numbers[i] : str(i) ); | |
module numberCircle(radius, size=5, | |
numbers=["1", "2", "3", "4", "5", "6", | |
"7", "8", "9", "10", "11", "12"], | |
count=0, alignment="center", | |
rotateLabelBy=0, clockStyle=0) | |
{ | |
angle = 360/countFunc(count,numbers); | |
// Rotate | |
rotate([0,0,90]) | |
for (i = [0 : countFunc(count,numbers)-1] ) | |
{ | |
// Rotate for each number | |
rotate([0,0,-1*angle*i]) | |
// Move the label out | |
translate([radius,0,0]) | |
// Center the number on the spot | |
rotate([0,0,rotateLabelBy]) | |
rotate([0,0,(-90+angle*i)*clockStyle]) | |
linear_extrude(1) | |
text(lableFunc(i,numbers), size=size, | |
valign = "center", halign = alignment); | |
} | |
} | |
// Just for testing | |
module _drawOutlineAtRadius(radius) | |
{ | |
color("blue") | |
translate([0,0,-1]) | |
difference() | |
{ | |
cylinder(0.5, 100, 100); | |
translate([0,0,-1]) | |
cylinder(3, 99.9, 99.5); | |
} | |
} | |
module testOptions() | |
{ | |
spacing=240; | |
_drawOutlineAtRadius(100); | |
numberCircle(100); | |
translate([spacing*1,0,0]) | |
{ | |
_drawOutlineAtRadius(100); | |
numberCircle(100, 10, [], 12, "center", 0, 1); | |
} | |
translate([spacing*2,0,0]) | |
{ | |
_drawOutlineAtRadius(100); | |
numberCircle(100, 10, ["N", "E", "S", "W"], | |
4, "center", 90); | |
} | |
translate([spacing*0,spacing*1,0]) | |
{ | |
_drawOutlineAtRadius(100); | |
numberCircle(100, 10, | |
["North", "East", "South", "West"], | |
4, "center", 0, 1); | |
} | |
translate([spacing*1,spacing*1,0]) | |
{ | |
_drawOutlineAtRadius(100); | |
numberCircle(100, 10, | |
["North", "East", "South", "West"], | |
4, "center", 0, 0); | |
} | |
translate([spacing*2,spacing*1,0]) | |
{ | |
_drawOutlineAtRadius(100); | |
numberCircle(100,10, ["N", "E", "S", "W"], 6, "left"); | |
} | |
translate([spacing*0,spacing*2,0]) | |
{ | |
_drawOutlineAtRadius(100); | |
numberCircle(100, 5, [], 36, "center", 0, 1); | |
} | |
translate([spacing*1,spacing*2,0]) | |
{ | |
_drawOutlineAtRadius(100); | |
numberCircle(100, 5, [], 36, "center", 0, 0); | |
} | |
} | |
MODEL_NUM=1; | |
if ( MODEL_NUM == 1 ) | |
translate([200,200,0]) | |
testOptions(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment