Answers for "snap to grid"

1

snap to grid

/* General idea:
	
    x = floor(x / gridSize) * gridSize;
    y = floor(y / gridSize) * gridSize;
    
    floor() sets it to the beginning of the cell
    round() to the tenth place multiplied by gridSize
    ceil() to the end of the cell
*/

// example in typescript:
x = Math.round(x / gridSize) * gridSize;
y = Math.round(y / gridSize) * gridSize;
Posted by: Guest on March-02-2022

Code answers related to "Javascript"

Browse Popular Code Answers by Language