mardi 6 septembre 2016

How do i generate a 2d grid from a set of randomly generated coordinates?

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?

The code for the random generation is included below:

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 <= radius*radius:
            deltas.add((x,y))

randPoints = []
excluded = set()
i = 0
while i<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




Aucun commentaire:

Enregistrer un commentaire