-
-
Save javipacheco/f319a54d8aa6e22c41c4d3edf62ce99a to your computer and use it in GitHub Desktop.
OpenSCAD: dice.
This file contains 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
/* | |
* 6-sided play cube | |
*/ | |
DRAW_DOTS = 0; | |
DRAW_CHATS = 1; | |
// font face | |
font_face="Arial"; | |
// font style | |
font_style="Bold"; | |
// size of upper text | |
font_size=25; | |
drawType = DRAW_CHATS; | |
chars = ["A", "B", "C", "D", "E", "F"]; | |
$fn = 128 ; | |
WIDTH = 64 ; | |
DOT_DEEP = 3 ; | |
DOT_DENSITY = .2 ; | |
DOT_TABLE = [ | |
[ 2, [ 2, 3, 4, 5, 6 ] ] | |
, [ 5, [ 6 ] ] | |
, [ 8, [ 4, 5, 6 ] ] | |
, [ 0, [ 1, 3, 5 ] ] ]; | |
tr = [ cos($t*360)*360 , sin($t*360)*360 ]; | |
tc = [ abs(cos($t*360)), abs(sin($t*360)) ]; | |
rotate([tr[0],tr[1],0]) | |
color([tc[0],tc[1],tc[0]*tc[1]]) | |
playcube(); | |
module playcube() | |
difference() { | |
intersection(){ | |
cube(WIDTH,center=true); | |
sphere(WIDTH*2/3,center=true); | |
} | |
for(i=[ | |
[1,0,0] | |
,[2,90,0] | |
,[3,0,90] | |
,[4,0,270] | |
,[5,270,0] | |
,[6,180,0] | |
]) | |
rotate([i[1],i[2],0])_dots(i[0]); | |
} | |
module _dots( n ) | |
if (drawType == DRAW_DOTS) { | |
for(i=[-1:1],j=[-1:1]) | |
if(search(n,DOT_TABLE[search(abs(i*3+j*5),DOT_TABLE)[0]][1])) | |
_dot(1,DOT_DENSITY*i,DOT_DENSITY*j); | |
} else { | |
_charts(chars[n - 1]); | |
} | |
module _dot( n, x, y ) { | |
translate([WIDTH*x,WIDTH*y,WIDTH*.5-DOT_DEEP]) | |
cylinder(DOT_DEEP+1,r=WIDTH*.075); | |
} | |
module _charts( n ) { | |
translate([0,0,WIDTH*.5-DOT_DEEP]) | |
linear_extrude(height = 4) { | |
text(str(n),font=str(font_face, ":style=", font_style),size=font_size,valign="center",halign="center"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment