Last active
December 23, 2015 03:59
-
-
Save IQAndreas/6576705 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// `bigRect.mouseX` can be replaced by `stage.mouseX - bigRect.x` | |
var ratioX:Number = bigRect.mouseX / bigRect.width; | |
var ratioY:Number = bigRect.mouseY / bigRect.height; | |
// This is the x and y location inside of the small rectangle which should line up with the above point | |
var offsetX:Number = ratioX * smallRect.width; | |
var offsetY:Number = ratioY * smallRect.height; | |
smallRect.x = bigRect.x + (ratioX * bigRect.width) - offsetX; | |
smallRect.y = bigRect.y + (ratioY * bigRect.height) - offsetY; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The code assumes the registration point for the rectangles is in the top left corner. It's not in processing, but only uses basic math operators, so it should be quick and easy to convert to any language.