views:

272

answers:

1

Hi there,

I’m generating multiple, random sized, circular elements using the Raphael JavaScript library but because it’s random a lot of the circular elements being generate overlap or cover each other. What I wanted to know, is there any way with JavaScript to tell if one element is in already in particular position so to avoid the overlapping? Essentially, I want to create random elements on a canvas, of a random size that don’t overlap or cover each other.

There's a couple of test files I created here to give you an idea of what I'm doing. The first one generates random objects and the second link sets them to a grid to stop the overlapping.

http://files.nicklowman.co.uk/movies/raphael_test_01/

http://files.nicklowman.co.uk/movies/raphael_test_03/

A: 

The easiest way is to create an object and give it a repulsive force that degrades towards zero at it's edge. As you drop these objects onto the canvas the objects will push away from each other until they reach a point of equilibrium.

graham.reeds
WOW. I'm not entirely sure what you've just said but as it's the only answer and it sounds bloody good I'll mark it as correct and then look up what you've posted and see if I can create it. It's probably a bit cheeky but would you know of any examples I can look at.Many, many thanks
Nick Lowman
I can't tell whether this was a glib answer or a real one, but if the latter, I'd love to know more. Google offers no help that I can discern, but if this kind of edge detection is possible, I'd surely like to know how.
Rob Wilkerson