I'm creating a world generator for my 2D game, which uses the Diamond-Square Algorithm in Java, and I've heard that it only works (or at least, only works well) with numbers that are 2n+1 (power of two).
The method that generates the world is called with generateWorld(width, height)
, but that creates a problem. I want to be able to input a width
, and the function will find the nearest number which is a power of two, if the input width isn't. I don't really know how I can do this, so all help is greatly appreciated!
Summarizing: If one number isn't power of two, I want to find the nearest number to that one, which is a power of two.