There are several things you can try for generating random shapes that are meant to represent islands.
You could modify your algorithm to make sure the resulting shape is convex. Although it's not required for the islands to be convex, I have a feeling that using it vanilla will lead to shapes that look odd as islands.
But more organic shapes are possible. Here are two suggestions:
- Generate one random point.
- For each point in the array with at least one empty neighbor that you have not already processed, fill each empty neighbor with some probability.
- Repeat step 2 until desired.
You can control the shapes and sizes of the islands with the value p that you choose. You need not keep p constant, it may work well to decrease it as you go on. You may also make it depend on the number of neighbors (for instance, make it proportional to the number of neighbors of the pixel you are processing).
You can (probably) make the algorithm more efficient by maintaining a list of border pixels, and another list of processed pixels. It becomes then something like this:
- Generate a random point, and add it to processed list and border list.
- While the border list is not empty and some other stop condition is not met:
1 Take the next point in it.
- Add the point to the processed list.
- For each neighbor of that point not in the processed list:
- Fill that neighbor with probability p.
- Add the neighbor to the border list.
- Remove the point from the border list
(Other possibilities are also possible if this is too slow.)
Generate cloudy noise (or Perlin noise, as some people* mistakenly calls it) in an array of the same size, and then use a threshold function to make the island.
Check this out for generating the noise:
To generate islands, you can use this algorithm
noiseArray = MakeNoise(100, 100)
for each pixel in noiseArray
noiseArray[pixel] = noiseArray[pixel]^somePower //adjusts the gamma
if noiseArray[pixel] < someThreshold
boolArray[pixel] = true
You can control the shapes of the islands using the persistence value of the noise, the value of
somePower, and the threshold value you choose.
You will need to modify it somehow to make sure you only get one island. You will have to play around a bit; one idea is to start in the middle, and do a spiral search until you find a filled pixel, and then make a new array, and fill it with pixels that are filled in the bool array only if they are connected to the first pixel (the one you found in the spiral search).
(*Including me in the article :( )