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
prop | type | default | required |
---|---|---|---|
fillColor | object | { r: 0, g: 0, b: 0 } | |
fillOpacity | number | 0.7 | |
name | string | X | |
size | number | 48 | |
stroke | number | 2 | |
strokeColor | object | { r: 1, g: 1, b: 1 } | |
x | number | 0 | |
y | number | 0 |