MCPcopy Create free account
hub / github.com/baraklevy20/Supercell-Extractor / createShapeWithColor

Function createShapeWithColor

src/imageUtils.js:68–98  ·  view source on GitHub ↗
(
  xy,
  xyRegion,
  color1,
  color2,
  isHorizontalGradient,
)

Source from the content-addressed store, hash-verified

66};
67
68const createShapeWithColor = async (
69 xy,
70 xyRegion,
71 color1,
72 color2,
73 isHorizontalGradient,
74) => {
75 // Move coordinates to origin and generate svg slice string
76 const width = xyRegion.right - xyRegion.left + 1;
77 const height = xyRegion.bottom - xyRegion.top + 1;
78
79 const sliceString = xy.reduce((acc, vertex) => `${acc} ${vertex[0] - xyRegion.left},${vertex[1] - xyRegion.top}`, '');
80
81 const sliceShape = sharp(Buffer.from(`<svg width="${width}" height="${height}">
82 <linearGradient
83 id="grad1"
84 x1="0%"
85 y1="0%"
86 x2="${isHorizontalGradient ? 100 : 0}%"
87 y2="${isHorizontalGradient ? 0 : 100}%">
88 <stop offset="0%" stop-color="rgba(${color1[0]},${color1[1]},${color1[2]},${color1[3]})" />
89 <stop offset="100%" stop-color="rgba(${color2[0]},${color2[1]},${color2[2]},${color2[3]})" />
90 </linearGradient>
91 <polygon fill="url(#grad1)" points="${sliceString}"/>
92 </svg>`));
93 return {
94 pixels: await sliceShape.raw().toBuffer(),
95 width,
96 height,
97 };
98};
99
100module.exports = {
101 saveImage,

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected