Code restructuring, average color calculation

The instance only needs to be initialised once and can be reused to
prevent the textures from being reloaded on each run.
The average color is used to make debug text more visible on very dark
or very light backgrounds.
Updated topdown image generation