By deinterleaving bits in a value you can create a space where the next point in a linear iteration is always interpreted as the closest point in 2D space.

To do this just take N, the total number of points in the 2D space and iterate 0 - N

Use the following function to deinterleave the bit in N. This will convert N to X, Y coordinates in the particular way needed to make the "curve" you see.

function deinterleave_bits(N) {
    let x = 0, y = 0;
    for (let i = 0; i < 32; i++) {
        x |= ((N & (1 << (2*i))) >> i);
        y |= ((N & (1 << (2*i+1))) >> (i+1));
    }
    return [x, y];
}

Notice that the curve always covers the nearest area first.

The curve has been expanded for visibility. If it weren't, it would entirely fill the space.