Skip to content

Instantly share code, notes, and snippets.

View edprince's full-sized avatar

Ed Prince edprince

View GitHub Profile
@LukeFinch
LukeFinch / rotate-center.js
Created January 6, 2021 11:15
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