# Build all parts centered on origin unless otherwise stated

from koko.lib.shapes import *
from math import sqrt

# One cad unit is 1mm
cad.mm_per_unit = 1

# Sizes for 12mm ply on shopbot with 6mm downcut tool
material_thickness = 12 #12 mm
tool_size = 6

scale = 50 #one castle unit is 5cm

wall_height = 2*scale
wall_width = 5*scale

tab_height = wall_height/2
tab_width = material_thickness #scale/2

tower_height = 4*scale
tower_side_width = 2*scale

# Make crenel with origin on top edge so it's easy to line up with top of wall sections.
crenel_width = 0.3*scale
crenel_depth = 0.2*scale
crenel_spacing = crenel_width*2.5
crenel = rectangle(-(crenel_width/2), crenel_width/2, -crenel_depth, 0)

wall = rectangle(-(wall_width/2), wall_width/2, -wall_height/2, wall_height/2)

count = int(wall_width/crenel_spacing) #4
x0 = -((crenel_spacing*(count-1))/2)
for i in range(count):
    wall -= move(crenel, x0+(crenel_spacing*i), wall_height/2)

tab = rectangle(0,tab_width, -(tab_height/2),tab_height/2)
dog = circle(0,0, tool_size/2)
dog_offset = tool_size/3

wall += move(tab, -((wall_width/2) + (tab_width)), 0)
wall -= move(dog, -((wall_width/2)+dog_offset), -((tab_height/2)+dog_offset))
wall -= move(dog, -((wall_width/2)+dog_offset), ((tab_height/2)+dog_offset))

wall -= move(tab, (wall_width/2)-tab_width, 0)
wall -= move(dog, ((wall_width/2)-tab_width+dog_offset), -((tab_height/2)-dog_offset))
wall -= move(dog, ((wall_width/2)-tab_width+dog_offset), ((tab_height/2)-dog_offset))


slot = rectangle(-(material_thickness/2), material_thickness/2, -(tab_height/2),tab_height/2)
slot += move(dog, -((material_thickness/2)-dog_offset), -((tab_height/2)-dog_offset))
slot += move(dog, -((material_thickness/2)-dog_offset), ((tab_height/2)-dog_offset))
slot += move(dog, ((material_thickness/2)-dog_offset), -((tab_height/2)-dog_offset))
slot += move(dog, ((material_thickness/2)-dog_offset), ((tab_height/2)-dog_offset))
wall -= slot


cad.shape = wall
