Initial rough dithering code, imported from Wavebucket