Skip to content

Instantly share code, notes, and snippets.

@LukeFinch
Created January 6, 2021 11:15
Show Gist options
  • Save LukeFinch/d3c93d79a9dcd6970358be1d17838318 to your computer and use it in GitHub Desktop.
Save LukeFinch/d3c93d79a9dcd6970358be1d17838318 to your computer and use it in GitHub Desktop.
figma plugin to rotate selection around the center of itself.
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