Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@avadhbsd
Created January 22, 2020 12:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save avadhbsd/f2008e83f4a3393c6cc0d8768daf2ba5 to your computer and use it in GitHub Desktop.
Save avadhbsd/f2008e83f4a3393c6cc0d8768daf2ba5 to your computer and use it in GitHub Desktop.
function drawCurve(x1,y1,x2,y2,) {
var rect = figma.createFrame()
rect.resize(500, 100)
setFillColor(rect,"FFFFFF" )
// hexToRgbColor = hexToRgb("F6F6F6")
// rect.fills = [{type: 'SOLID',
// color: {
// r: hexToRgbColor.r,
// g: hexToRgbColor.g,
// b: hexToRgbColor.b,
// }
// }]
const nodes: SceneNode[] = [];
var curve = figma.createVector()
var startX = 0 + " "
var startY = 100 + " "
var canvasHeight = 100
var controlPointX1 = (100 * x1) + " "
var controlPointY1 = (canvasHeight - (100 * y1)) + " "
var controlPointX2 = (100 * x2) + " "
var controlPointY2 = (canvasHeight - (100 * y2)) + " "
var endX = 500 + " "
var endY = 0
var bezierExpression = "M " + startX + startY + "C " + controlPointX1
+ controlPointY1 + controlPointX2
+ controlPointY2 + endX
+ endY + " L 500 100" + " Z"
curve.vectorPaths = [{
windingRule: "NONE",
data: bezierExpression
}]
curve.x = 1
curve.y = 0
curve.strokeAlign = "OUTSIDE"
//clone the property then change it and then assign it to original one.
hexToRgbColor = hexToRgb("EBB15E")
const strokes = clone(curve.strokes)
strokes[0].color.r = hexToRgbColor.r
strokes[0].color.g = hexToRgbColor.g
strokes[0].color.b = hexToRgbColor.b
curve.strokes = strokes
curve.constraints = {
horizontal: "STRETCH",
vertical: "STRETCH"
}
rect.name= "Curve"
rect.appendChild(curve)
rect.y = rect.y + 24
return rect
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment