----- parameters -----

width = 6:: int_slider("Width", 2, 30)
length = 6:: int_slider("Length", 2, 30)
height = 50:: int_slider("Height", 1, 500)
block_w = 3:: float_slider("Block Width", 0.2, 10, 0.2)
block_l = 1:: float_slider("Block Length", 0.2, 10, 0.2)
block_h = 1:: float_slider("Block Height", 0.2, 10, 0.2)
offset_mult = 0.5:: float_slider("Offset Mult", 0, 1)

block_dim = vec(block_w,block_h,block_l)

----------------------

c = col()
c.dim = block_dim

function wall(_pos, _dir, _width, _height, _off_mult)
 local even = false

 local rdir = vcross(vnorm(_dir), vec(0,1,0))

 local _off = _off_mult * c.dim.x
 local hlw = (c.dim.x * _width - _off) * 0.5;

 for ih=1,_height do
  for iw=1,_width do
   local b=brk(c)
   b.pos.y = (ih - 1) * b.col.dim.y
 
   local off = 0
   if even then off = _off end
  
   local _x = (iw - 1) * c.dim.x + off;
   _x = -hlw + _x --iw * b.col.dim.x + off
   b.pos = vadd(b.pos, vscl(rdir, _x))
   b.pos = vadd(b.pos, _pos)
   b.rot.y = dir2angle(_dir) * 2 + 90
  end

  even = not even
 end
end

function four_walls(_col, _pos, _width, _length, _height, _off_mult)
 local hW = _col.dim.x * _width * 0.5
 local hL = _col.dim.x * _length * 0.5
 local y = _col.dim.y * 0.5

 wall(vec(0,y,hL), vec(0,0,1), _width, _height, _off_mult)
 wall(vec(hW,y,0), vec(1,0,0), _length, _height, _off_mult)
 wall(vec(0,y,-hL), vec(0,0,-1), _width, _height, _off_mult)
 wall(vec(-hW,y,0), vec(-1,0,0), _length, _height, _off_mult)
end

four_walls(c, vec(0,0,0), width, length, height, offset_mult)

randomize_colors()