This is just banding: https://en.wikipedia.org/wiki/Colour_banding

It's not a fault of your code, it's because you're drawing to an 8-bit-per-channel framebuffer (24-bit or 32-bit colour), and is...