Code snippets
Create a Circle

Create a circle

code.js
function createCircle(props) {
  // details, dimensions, and placement
  const { name, x = 0, y = 0, size = 48 } = props;
 
  // fills
  const { fillColor = { r: 0, g: 0, b: 0 }, fillOpacity = 0.7 } = props;
 
  // strokes
  const { stroke = 2, strokeColor = { r: 1, g: 1, b: 1 } } = props;
 
  const radius = Math.floor(size / 2);
 
  const circle = figma.createRectangle();
  circle.name = name;
  circle.x = x;
  circle.y = y;
  circle.cornerRadius = radius;
  circle.fills = [{ type: 'SOLID', color: fillColor, fillOpacity }];
  circle.strokes = [{ type: 'SOLID', color: strokeColor }];
  circle.strokeWeight = stroke;
  circle.resizeWithoutConstraints(size, size); // w, h
 
  return circle;
}

Function props

proptypedefaultrequired
fillColorobject{ r: 0, g: 0, b: 0 }
fillOpacitynumber0.7
namestringX
sizenumber48
strokenumber2
strokeColorobject{ r: 1, g: 1, b: 1 }
xnumber0
ynumber0