Here's what you do:
- Take standard output from a Perlin Noise function, this should be a float in the range (0-1)1
- Multiply by 5. This will range from (0-5)
- Round to nearest integer
All those values that were slightly in between your integer values will get clamped to one or the other, resulting in squared off results
If you want it to be blocky on the other two directions (the X and Y screenspace, rather than just height value) you need to use a scalar there as well, and one that's designed to perform no interpolation between values.
Something like this should work:
int getHeight(int x, int y) { float p1 = perlinNoise(x<<2, y<<2) * 5; int p2 = Mathf.RoundToInt(p1); return p2; }
Technically Mathf.RoundToInt is a Unity specific, but the function is named with the desired intent. Convert to your language as needed.
By dividing x and y by 4 (bitwise) it means that x, x+1, x+2, and x+3 all return the same perlin noise value, making the result blocky in screenspace (not just height). Blocks will be 4x4 pixels. Increase the bitwise operator or use integer division for larger blocks.
1Inclusive or exclusive doesn't really matter. Perlin Noise tends to never actually hit the upper and lower bounds, although technically possible. Heavily dependent on the implementation (GIMP's Perlin Noise has an effective actual range of [0.2-0.8], for example).