include <BOSL2/std.scad>
include <BOSL2/fnliterals.scad>

$fn=50;

// Pudełeczko
soap_width = 90;
soap_depth = 55;
holder_height = 30;

t = 5;
union() {
  difference() {
    cuboid([soap_width+t,soap_depth+t,holder_height], rounding=5);
    translate([0,0,t + 10]) cuboid([soap_width, soap_depth, holder_height + 20], rounding=5);
  }
  for(i=[-1,0,1]) {
    translate([i*soap_width/3,soap_depth/2,-6]) cylinder(d1=0, d2=5, h=10, $fn=20);
    translate([i*soap_width/3,-soap_depth/2,-6]) cylinder(d1=0, d2=5, h=10, $fn=20);
  }
}

// haczyk do przyczepienia
hook_top = 17;
hook_bottom = 20;
hook_h = 30;
hook_t = 3;

hook_angle = 5; // atan((hook_bottom-hook_top)/hook_h);

fwd(soap_depth/2 + t/2) up(holder_height/2 - 5)  union() {
  fwd(hook_top/2) cuboid([soap_width, hook_top+hook_t, hook_t], rounding=1);
  fwd(hook_top) rotate([90 - hook_angle,0,0]) fwd(hook_h/2) 
    cuboid([soap_width, hook_h, hook_t], rounding=1);
}

// kratka na mydło
grate_t = 2;
hole_size = 5;
hole_t = 0.5;

up(holder_height) union() {
  difference() {
    cuboid([soap_width, soap_depth, grate_t], rounding=5, edges="Z");
    for(i=[1:hole_size+hole_t:soap_width+hole_size*2]) {
      for(j=[1:hole_size+hole_t:soap_depth+hole_size*2]) {
        left(soap_width/2) back(soap_depth/2) right(i) fwd(j) down(hole_size/2) 
          cube(hole_size);
      }
    }
  }
  difference() {
    cuboid([soap_width, soap_depth, grate_t], rounding=5, edges="Z");
    cuboid([soap_width-grate_t, soap_depth-grate_t, grate_t+0.2], rounding=5, edges="Z");
  }
}