31 lines
No EOL
845 B
OpenSCAD
31 lines
No EOL
845 B
OpenSCAD
module lcyl(size, depth){
|
|
translate([size/2,depth/2,size/2])
|
|
rotate([90,0,0])
|
|
cylinder(h = depth, d = size, center = true, $fn = 32);
|
|
}
|
|
|
|
module binary(n, size, depth = size, sep = size/2){
|
|
cube([sep,depth,size]);
|
|
translate([0,0,-size/4])
|
|
lcyl(size = sep, depth = depth);
|
|
translate([0,0,3*size/4])
|
|
lcyl(size = sep, depth = depth);
|
|
translate([2*sep,0,0])
|
|
binary_rec(n = n, size = size, depth = depth, sep = sep);
|
|
}
|
|
|
|
module binary_rec(n, size, depth, sep){
|
|
if(n != 0){
|
|
if(n % 2 == 0){
|
|
translate([size+sep,0,0])
|
|
binary_rec(n = n/2, size = size, depth = depth, sep = sep);
|
|
}
|
|
else{
|
|
lcyl(size = size, depth = depth);
|
|
translate([size+sep,0,0])
|
|
binary_rec(n = (n-1)/2, size = size, depth = depth, sep = sep);
|
|
}
|
|
}
|
|
}
|
|
|
|
binary(n = 23, size = 2, depth = 2, sep = 1); |