const { getSizesFromOptOrDefault, colorSets: getColorSets, deepFlatten, listOutputFiles, } = require('@themer/utils'); const render = (colors, options) => { try { var sizes = getSizesFromOptOrDefault(options['themer-wallpaper-octagon-size'], 36); } catch(e) { return [Promise.reject(e.message)]; } const colorSets = getColorSets(colors); const getOctagonPathData = size => ` M ${size/6} ${0} l ${size/9} ${size/9} l ${size/2.25} ${0} l ${size/9} ${size/-9} l ${size/6} ${size/6} l ${size/-9} ${size/9} l ${0} ${size/2.25} l ${size/9} ${size/9} l ${size/-6} ${size/6} l ${size/-9} ${size/-9} l ${size/-2.25} ${0} l ${size/-9} ${size/9} l ${size/-6} ${size/-6} l ${size/9} ${size/-9} l ${0} ${size/-2.25} l ${size/-9} ${size/-9} z `; return deepFlatten(colorSets.map(colorSet => sizes.map(size => { const colorList = [ colorSet.colors.accent0, colorSet.colors.accent1, colorSet.colors.accent2, colorSet.colors.accent3, colorSet.colors.accent4, colorSet.colors.accent5, colorSet.colors.accent6, colorSet.colors.accent7, ]; const radius = -300; const point1 = { x: 0, y: radius }; const point2 = { x: (radius * Math.sin(Math.PI / (colorList.length / -2))).toPrecision(5), y: (radius * Math.cos(Math.PI / (colorList.length / -2))).toPrecision(5) }; const point3 = { x: (radius * Math.sin(3 * Math.PI / (colorList.length / -2))).toPrecision(5), y: (radius * Math.cos(3 * Math.PI / (colorList.length / -2))).toPrecision(5) }; const paths = colorList.map((color, i) => ({ r: i * Math.PI / -4 * 180 / Math.PI, c: color, })); return Promise.resolve({ name: `themer-wallpaper-octagon-${colorSet.name}-${size.w}x${size.h}.svg`, contents: Buffer.from( ` ${paths.map((path, i) => ``).join('\n')} ${paths.map((path, i) => ``).join('\n')} `, 'utf8' ), }); }))); }; module.exports = { render, renderInstructions: listOutputFiles, };