Skip to content

Instantly share code, notes, and snippets.

@adusak
Last active August 6, 2016 14:04
Show Gist options
  • Select an option

  • Save adusak/db46a2a40036e62b00c2 to your computer and use it in GitHub Desktop.

Select an option

Save adusak/db46a2a40036e62b00c2 to your computer and use it in GitHub Desktop.
Generates points within specified bounds
import random
def generate_points(n, canvas_size, gauss=False):
points = []
for i in range(n):
if gauss:
x = -1
y = -1
while not (point_in_bounds((x, y,), canvas_size)):
x = abs(random.gauss(canvas_size[0] / 2, canvas_size[0] / 4))
y = abs(random.gauss(canvas_size[1] / 2, canvas_size[1] / 4))
else:
x = random.uniform(0, canvas_size[0])
y = random.uniform(0, canvas_size[1])
points.append((x, y))
return points
def point_in_bounds(point, bounds):
if 0 < point[0] < bounds[0] and 0 < point[1] < bounds[1]:
return True
else:
return False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment