Skip to content

Instantly share code, notes, and snippets.

@hellos3b
Last active February 21, 2019 19:38
Show Gist options
  • Save hellos3b/447c18a6bf0cf961282233529d1c9171 to your computer and use it in GitHub Desktop.
Save hellos3b/447c18a6bf0cf961282233529d1c9171 to your computer and use it in GitHub Desktop.
const validDistance = node => !nodeList.find(n => distance(n, node) < 40)
for (var i = 0; i < nodes; i++) {
let rx = Math.random()*width
let ry = Math.random()*height
let node = new Node({ id: i, x: rx, y: ry})
while (!validDistance(node)) {
rx = Math.random()*width
ry = Math.random()*height
node = new Node({ id: i, x: rx, y: ry})
}
nodeList.push(new Node({id: i, x: rx, y: ry}))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment