daily pastebin goal
53%
SHARE
TWEET

Efficient code

a guest Jan 12th, 2018 57 in 3 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def position (radius, listofStars, maxX, maxY):
  2.     global occupied
  3.     overlap = True
  4.     while starsOverlap:
  5.         overlap = False
  6.         pos=[randint(radius, 6283-radius), randint(radius, 2000-radius)]
  7.         newXrange = set(range(pos[0]-radius, pos[0]+radius+1))
  8.         newYrange = set(range(pos[1]-radius, pos[1]+radius+1))
  9.         for i in newXrange:
  10.             for j in newYrange:
  11.                 if occupied[i][j]==1:
  12.                     overlap=True
  13.                     break #this only breaks the Y value for loop. must cerebrate more on that.
  14.             if overlap:
  15.                 break
  16.         #if there is no overlap, place the star at pos and create the occupied box
  17.         for i in newXrange:
  18.             for j in newYrange:
  19.                 occupied[i][j]=1
  20.     return pos
RAW Paste Data
Top