I am currently creating a grand strategy space empire game as my python course project. I am using Pygame library and all was going suprisingly good until...
...until I wanted to generate a random star field.
Using the usual randint(a,b) occationally results in some stars being too tight clusters.
Here is an attachment with a picture of the problem.
I have managed to come up with something like this, but this is still not enough, because some stars still bleed into each other.
for i in range(200): x = random.randint(17, 776) y = random.randint(17, 471) while x in x_used == True or y in y_used == True: x = random.randint(17, 776) y = random.randint(17, 471) pygame.draw.circle(DISPLAYSURF, WHITE, (x, y), 2, 0) pygame.draw.circle(DISPLAYSURF, WHITE, (x, y), 5, 1) counter = 0 while counter < 19: x_used.append((x-9) + counter) y_used.append((y-9) + counter) counter += 1
The "200" in the range command is the number of stars I want to generate.
So, my question is: how can I generate random coordinates, so that each point generated has an area around it, into which other points cannot be generated?
Edited by Ironmaggot, 19 October 2013 - 02:33 PM.