We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
magnetic grid (Read 624 times)
magnetic grid
Jun 20th, 2008, 7:29pm
 
hello,

once again, I need your help.

I want to script a program in which you can draw with (rect)angles on the screen. there are to be 3 sizes and they have to fit perfectly together, like in the image (see link).
http://www.loaditup.de/files/240693.jpeg

So when choosing the size of the rect it has to fit right in the whole image.

Is there any function like the magnetic grid in Adobe Illustrator? When clicking the rect has to appear at the right position, even if the click of the mouse is not 100% at the right position.

is there any chance to get this realised? I'm glad for any help.

Re: magnetic grid
Reply #1 - Jun 20th, 2008, 7:48pm
 
One way to achieve this is to do something like:

Code:
int xpos=(mouseX/8)*8;
int ypos=(mouseY/8)*8;


Now this looks like it does nothing, but the divide is an integer divide, not a floating point one, so it gets rounded to the nearest integer, so then multiplying it by 8 leaves the number as an exact multiple of 8, thereby giving you a snap to grid effect.
Re: magnetic grid
Reply #2 - Jun 20th, 2008, 8:55pm
 
dear johnG,

thanks for your quick help. it really gets close to the solution i want to achieve.

is there any chance to get a wider range where i can click to get to the same point? at the moment i think i have a range of about 3 or 4 pixels to get to the same point in my grid. is there a way to get a wider range (so that a user who is not that patient when clicking gets the same result as a user who is more careful by clicking?)

thanks for your help once again Smiley
Page Index Toggle Pages: 1