/* [OpenSCAD] */
$fn=90;

/* [Spielstein] */
// Form, Größe, Füllung
Form = 0; // [0:Eckig, 1:Rund]
Size = 1; // [0:Klein, 1:Groß]
Hut = 0; // [0:Nein, 1:Ja]

/* [Spielstein] */
// Loch für Magnet im Fuß
Magnet = 0; // [0:Nein, 1:Ja]

/* [Hidden] */

module piece(f, s, h) {
}


module fuss() {
  hull() {
    translate([0,0,1]) rotate_extrude() translate([9,0]) circle(d=2);
    cylinder(d=20, h=0.01, center=false);
  }
  cylinder(d=6, h=10);
}

module wuerfel() {
  // https://reprap.org/forum/read.php?247,458171,458591#msg-458591
  w=90-acos(sqrt(2/3)); // Winkel der Raumdiagonale
  scale(20/sqrt(3)) for (i=[0:60:360]) {
    rotate([0, w, i]) translate([-sqrt(2)/2, 0, 0.5]) rotate([0, 0, 45]) cube(1, center=true);
  }
}

module hut() {
  cylinder(d=8, h=1);
  cylinder(d=5, h=4);
}

module eckig(hut) {
  fuss();
  wuerfel();
  if (hut==1) translate([0,0,18]) scale(1/3) wuerfel();
}

module rund(hut) {
  fuss();
  translate([0,0,10]) sphere(d=20);
  if (hut==1) translate([0,0,21]) scale(1/3) sphere(d=20);
}

////////////////////////////////////////////////////////////////////////////////////////////

difference() {
  union() {
    if (Form==0) {
      if (Size==0) {
        scale(1/sqrt(2)) eckig(Hut);
      }
      else {
        eckig(Hut);
      }
    }
    else {
      if (Size==0) {
        scale(1/sqrt(2)) rund(Hut);
      }
      else {
        rund(Hut);
      }
    }
  }
  if (Magnet==1) {
    translate([0,0,-0.01]) cylinder(d=3, h=5.5);
  }
}