How to generate a 2d grid from a set of randomly generated coordinates?
<p>The plan for the use of this is in a text based Space RPG game. I want to generate random points (x,y coordinates) - which I have already done - followed by plotting them with connections shown on a 2d grid. As a side, how would I label these coordinates?</p>

<p><strong>The code for the random generation is included below:</strong></p>

<pre><code>import time
import random
import math

radius = 200
rangeX = (0, 2500)
rangeY = (0, 2500)
qty = 40 

deltas = set()
for x in range(-radius, radius+1):
    for y in range(-radius, radius+1):
        if x*x + y*y &lt;= radius*radius:
            deltas.add((x,y))

randPoints = []
excluded = set()
i = 0
while i&lt;qty:
    x = random.randrange(*rangeX)
    y = random.randrange(*rangeY)
    if (x,y) in excluded: continue
    randPoints.append((x,y))
    i += 1
    excluded.update((x+dx, y+dy) for (dx,dy) in deltas)
    time.sleep(0.001)

stars = {}
keyName = 1
for item in randPoints:
    stars[str(keyName)] = [item, 0,]
    keyName += 1
</code></pre>

<p>Instead of providing you with a direct answer I will point you in a general direction as the scope of this question seems rather big.</p>

<p>Consider using pygame; it provides you with drawing functions, has an event system that you can use to detect user input and has many other helpful features for creating games as the name suggests.</p>

<p>Strongly consider using classes; your code will become more readable and more flexible. Adding features to your stars such as a label, surface temperature, color of emitted (pulsing?) light, available raw materials.. etc. becomes much easier to handle.</p>

<p>To generate names you could put existing star names in a text file, load it and pick one at random. For added bonus points use a markov chain to generate seemingly random names.</p>

<p><a href="https://www.pygame.org" rel="nofollow">https://www.pygame.org</a></p>

<p><a href="https://docs.python.org/3/tutorial/classes.html" rel="nofollow">https://docs.python.org/3/tutorial/classes.html</a></p>

<p><a href="https://en.wikipedia.org/wiki/Markov_chain" rel="nofollow">https://en.wikipedia.org/wiki/Markov_chain</a></p>

python random grid 2d