Snap to grid demo

Snap to grid position Demo

This online demo demonstrates the snap to grid function. The interesting thing is that the magnets are defined in an array so they can be positioned anywhere.

In this demo the lighter grey are of the target is the snap area for objects which are relased and whose corners are in this are. Here the icon needs to cover the whole of the green target for the snap to happen.

How it works

It uses the typical (mouse click to put up, mouse click to put down), loops thorough all the possible position (magnet) where it could snap to on the "put down".

In this demo the lighter grey are of the target is the snap area. When checking if the corner of the object let put down has a corner on the grey area, it is gets x,y top left, works out the middle form width and sets the final coords to that of the magnet.

Application Idea:

I originally wanted to use it for quickly arranging system components, like this electrical components from Fischer Panda Generators to design an energy concept. By having preset the positions for battery, generator, distribution and inverter to snap to I could calculate how far apart they are and calcuate the optimal battery cable cross-sctions required when using fixed cable lengths and the increase in resitance on the battery charging current as the cables get longer.

There is probably no reason for this anymore because most interactive media is done using flash, fireworks or silverlight. But just incase you still old-skool and using javascript with jpgs, gifs, pngs or svgs - then it might be of use.