-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode.ts
More file actions
65 lines (45 loc) · 2.04 KB
/
code.ts
File metadata and controls
65 lines (45 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
figma.showUI(__html__, {width: 240, height: 500, title: "Color Gradient"});
figma.ui.onmessage = msg => {
if (msg.type === 'actionGenerate'){
const {circleSize, circleSpacing, colorCode, colorName, frameDirection, tintNumber} = msg.formDataObj
const parentFrame = figma.createFrame()
parentFrame.name = colorName + ' color';
parentFrame.layoutMode = frameDirection.toUpperCase() //режим компановки auto layout
// отступы слева, справа, снизу и сверху
parentFrame.paddingLeft = 64
parentFrame.paddingRight = 64
parentFrame.paddingBottom = 64
parentFrame.paddingTop = 64
parentFrame.itemSpacing = parseInt(circleSpacing)
parentFrame.primaryAxisSizingMode = 'AUTO'
parentFrame.counterAxisSizingMode = 'AUTO'
for (let i = 0; i < tintNumber; i++){
const tintNode = figma.createEllipse();
tintNode.name = colorName + ' ' + (100-i*10)
tintNode.resize(parseInt(circleSize), parseInt(circleSize));
const hexToRgb = (hex: any) => {
let result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
return result
? {
r: parseInt(result[1], 16),
g: parseInt(result[2], 16),
b: parseInt(result[3], 16)
} : null
}
const colorR = hexToRgb(colorCode).r / 255,
colorG = hexToRgb(colorCode).g / 255,
colorB = hexToRgb(colorCode).b / 255
tintNode.fills = [{ type: 'SOLID', color: { r: colorR, g: colorG, b: colorB }}]
tintNode.opacity = (100-i*10)/100 // прозрачность элемента
parentFrame.appendChild(tintNode)
const selectFrame: FrameNode[] = []
selectFrame.push(parentFrame)
figma.currentPage.selection = selectFrame
figma.viewport.scrollAndZoomIntoView(selectFrame)
}
/*console.log(msg.formDataObj)*/
figma.closePlugin('Tints generated successfully!');
} else if (msg.type === 'actionExit'){
figma.closePlugin();
}
};