Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

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;
Comment

PREVIOUS NEXT
Code Example
Javascript :: repeat string n times javascript 
Javascript :: play audio javascript 
Javascript :: javascript synchronous wait 
Javascript :: compare and filter two array of object 
Javascript :: jquery image change on hover 
Javascript :: check if localstorage key exists js 
Javascript :: remove undefined from javascript array map 
Javascript :: count number of divs inside a div jquery 
Javascript :: audio in react 
Javascript :: trigger click on checkbox jquery 
Javascript :: how to run nextjs in another port 
Javascript :: only allow numbers in text input in js 
Javascript :: usenavigate react router dom v6 
Javascript :: javascript for...of index 
Javascript :: javascript url decode online 
Javascript :: call function on modal open 
Javascript :: livewire progress indicators javascript 
Javascript :: how to delete element at a particular index of array in react js 
Javascript :: toggle in react 
Javascript :: javascript date get future 5minutes 
Javascript :: jquery remove items from dropdownlist 
Javascript :: generate random integer javascript 
Javascript :: jquery select clear options 
Javascript :: find duplicates in array javascript 
Javascript :: add month date now javascript 
Javascript :: json.stringify parameters 
Javascript :: random int javascript 
Javascript :: how to change text to italic in javascript 
Javascript :: radio button set value in javascript 
Javascript :: cannot use import statement outside a module in jest 
ADD CONTENT
Topic
Content
Source link
Name
9+6 =