Created
January 6, 2021 11:15
-
-
Save LukeFinch/d3c93d79a9dcd6970358be1d17838318 to your computer and use it in GitHub Desktop.
figma plugin to rotate selection around the center of itself.
This file contains 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
let angle = 45 | |
let theta = angle * (Math.PI/180) //radians | |
let sel = figma.currentPage.selection[0] | |
//cx,cy is the center of the node | |
let cx = sel.x + sel.width/2 | |
let cy = sel.y + sel.height/2 | |
let newx = Math.cos(theta) * sel.x + sel.y * Math.sin(theta) - cy * Math.sin(theta) - cx * Math.cos(theta) + cx | |
let newy = - Math.sin(theta) * sel.x + cx * Math.sin(theta) + sel.y * Math.cos(theta) - cy * Math.cos(theta) + cy | |
sel.relativeTransform = [[Math.cos(theta), Math.sin(theta), newx], | |
[-Math.sin(theta), Math.cos(theta), newy ]] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment