use <fonts/CasualStencil.ttf>

mode="bottom"; // Can be "top" or "bottom"

$fn=40;

module bumper_hole() {
    translate([0, 0, 1.5]) union() {
        cylinder(d =  8.5, center = true, h = 3.1);
        translate([0, 0, 0.76])
            cylinder(d = 14.5, center = true, h = 1.5);
    }
}

module arm_hole(angle) {
    rotate([0, 0, angle]) {
        //cube(size=[13, 22, 4], center = true);
        translate([-12.5, -14, 1.9])
            cylinder(d = 3, center = true, h = 4);
        translate([ 13  , -14, 1.9])
            cylinder(d = 3, center = true, h = 4);
        if (mode == "top") {
            translate([-12.5,  11.5, 1.9])
                cylinder(d = 3, center = true, h = 4);
            translate([ 13  ,  11.5, 1.9])
                cylinder(d = 3, center = true, h = 4);
        }
    }
}

module band_hole() {
    translate([0, 0, 1.5]) union() {
        translate([  9, 0, 0])
            cylinder(d =  2, center = true, h = 4);
        translate([- 9, 0, 0])
            cylinder(d =  2, center = true, h = 4);
        cube([18, 2, 4], center = true);
    }
}

module quad_name(x, y) {
    translate([x, y, 4])
        rotate([180, 0, 90])
            linear_extrude(height = 5)
                text("Anlyea", halign = "center", size = 7, font = "CasualStencil:style=Regular");       
}

intersection() {
    difference() {
        union() {
            translate([0, 0, 1.5])
                rotate([0, 0, -45])
                    cube(size=[105, 105, 3], center = true);
            
            if (mode == "bottom") {
                translate([   0,  21.5, 3.5])
                    cylinder(d = 5, center = true, h = 7);
                translate([   0,- 21.5, 3.5])
                    cylinder(d = 5, center = true, h = 7);
            }
        
        }
        union() {
            // Rounded corners are removed
            translate([   0, -90, 1.9])
                cylinder(d = 90, center = true, h = 4);
            translate([   0,  90, 1.9])
                cylinder(d = 90, center = true, h = 4);
            translate([ 90,    0, 1.9])
                cylinder(d = 90, center = true, h = 4);
            translate([-90,    0, 1.9])
                cylinder(d = 90, center = true, h = 4);
            
            // Arm holes are removed            
            translate([ 24,  24, 0]) arm_hole(- 45 + 180);
            translate([-24,  24, 0]) arm_hole(  45 + 180);
            translate([ 24, -24, 0]) arm_hole(  45);
            translate([-24, -24, 0]) arm_hole(- 45);
            
            
            // bumper holes are removed
            rotate([0, 0, 45]) {
                translate([  0,  32, 0]) bumper_hole();
                translate([  0,- 32, 0]) bumper_hole();
                translate([ 32,   0, 0]) bumper_hole();
                translate([-32,   0, 0]) bumper_hole();
            }
            
            if (mode == "bottom") {
                translate([ 20,  32, 0]) band_hole();
                translate([ 20,- 32, 0]) band_hole();
                translate([-20,  32, 0]) band_hole();
                translate([-20,- 32, 0]) band_hole();
            }
            
            if (mode == "bottom") {
                translate([   0,  21.25, 3.5])
                        cylinder(d = 3, center = true, h = 7.2);
                translate([   0,- 21.25, 3.5])
                        cylinder(d = 3, center = true, h = 7.2);
            }
            
            if (mode == "top") {
                quad_name(-40, 0);
            }
            
            // Through holes are removed
            translate([0, 0, 1.9])
                cylinder(d = 20, center = true, h = 4);
            
        }
    }
}