`gap=1px` means 1px around each module, i.e. 2px between modules, not 1px. yep, i know, such a bad name for this parameter, but who cares?
Made a separate function `intDiv` for integer division, that's more readable than `Math.floor` inside expression. The function performs `a / b` and then truncates the fractional part using the fastest method: binary `~~`