Well part of the secret is the map itself. It only stores a number - that number is used for the color of the square but also the number of lines to draw.
Thus the track borders with a value of 4 are complete squares, while the 'rest of the world' is 2-line Lshapes that form a grid, to cut back on the total number of lines to transform.
Their actual xy in the transformation is just assigned from their position in the array.
Just thought of another speedup: ditch the array cell draw, and calculate the start and end of all the lines on the grid as huge lines from left to right, and top to bottom. Easy enough. Then simply draw black lines over them for the main track center.
That would result in probably 1/4 the total number of lines.