I was searching for a method to place a relatively small *N* number of (identical square) sprites within the scene via random seed, such that the sprites maintain a minimum distance from each other and have a more natural looking distribution.

This link is the nearest and clearest example of such I could find. (You can edit values and rerun.) In my case, a sprite would be centered at each dot (rather than dot drawn), and the "dotRadius" would that of a circle containing the sprite plus padding.

I was curious as to whether this would be a suitable solution for Construct 2 and how one might implement it. Below is the code from the above link:

`/* Inspiration:`

`bl.ocks.org/mbostock/d7bf3bd67d00ed79695b[/p] [/p] Amazingly, even with high numbers of dots and high levels of smoothing,[/p] finding the ideal position for a new dot never takes takes longer than[/p] a millisecond. I was sure the brute-force approach would lag and I'd [/p] have to implement a quadtree or something.[/p] [/p] */[/p] [/p] (function (canvas) {[/p] 'use strict';[/p] [/p] var ctx = canvas.getContext('2d'),[/p] cw = canvas.width,[/p] ch = canvas.height,[/p] twoPi = Math.PI * 2,[/p] dotRadius = 32,[/p] dotColor = '#0AA594',[/p] dotCount = 30,[/p] samples = 50, // candidate dots attempted, higher is better[/p] placedDots = [], // a dot is represented as [x, y][/p] [/p] initialize = function () {[/p] var dotsDrawn = 0,[/p] interval = setInterval(function () {[/p] // var elapsed = (new Date()).getTime();[/p] placeNewDot();[/p] // elapsed = (new Date()).getTime() - elapsed;[/p] dotsDrawn++;[/p] // console.log('Dot #' + dotsDrawn + ' drawn in ' + elapsed + 'ms.');[/p] if (dotsDrawn === dotCount) clearInterval(interval);[/p] }, 20);[/p] },[/p] [/p] generateRandomPosition = function () {[/p] return [ Math.round(Math.random() * cw), Math.round(Math.random() * ch)];[/p] },[/p] [/p] getDistanceToNearestDot = function (dot) {[/p] var shortest;[/p] for (var i = placedDots.length - 1; i >= 0; i--) {[/p] var distance = getDistance(placedDots[i], dot);[/p] if (!shortest || distance < shortest) shortest = distance;[/p] }[/p] return shortest;[/p] },[/p] [/p] getDistance = function (dot1, dot2) {[/p] var xDistance = Math.abs(dot1[0] - dot2[0]),[/p] yDistance = Math.abs(dot1[1] - dot2[1]),[/p] distance = Math.sqrt(Math.pow(xDistance, 2) + Math.pow(yDistance, 2));[/p] return Math.floor(distance);[/p] },[/p] [/p] generateBestDot = function () {[/p] var bestDot, bestDotDistance;[/p] for (var i = 0; i < samples; i++) {[/p] var candidateDot = generateRandomPosition(),[/p] distance;[/p] if (!placedDots.length) return candidateDot;[/p] distance = getDistanceToNearestDot(candidateDot);[/p] if (!bestDot || distance > bestDotDistance) {[/p] bestDot = candidateDot;[/p] bestDotDistance = distance;[/p] }[/p] }[/p] return bestDot;[/p] },[/p] [/p] placeNewDot = function () {[/p] var dot = generateBestDot();[/p] placedDots.push(dot);[/p] drawDot(dot);[/p] },[/p] [/p] drawDot = function (dot) {[/p] ctx.fillStyle = dotColor;[/p] ctx.beginPath();[/p] ctx.arc(dot[0], dot[1], dotRadius, 0, twoPi);[/p] ctx.fill();[/p] };[/p] [/p] initialize();[/p] [/p] }(document.getElementById('canvas')));[/code:2j133ne4]`