diff --git a/src/components/util/RGBUtils.ts b/src/components/util/RGBUtils.ts index d329a39f..c273a109 100644 --- a/src/components/util/RGBUtils.ts +++ b/src/components/util/RGBUtils.ts @@ -44,8 +44,8 @@ export function getRandomColor() { } export function getAnimFrames(store: typeof defaults) { + if (store.colors.length < 2) return { OutputArray: [], frames: [] }; const colors = store.colors.map(color => ({ rgb: convertToRGB(color.hex), pos: color.pos })); - if (colors.length < 2) return { OutputArray: [], frames: [] }; const text = store.text ?? 'Birdflop'; let loopAmount; @@ -66,7 +66,28 @@ export function getAnimFrames(store: typeof defaults) { const gradient = new AnimatedGradient(colors, length, n); let output = ''; gradient.next(); - if (store.type == 4) { + if (store.format.color == 'MiniMessage') { + const colors = sortColors(store.colors); + if (colors[0].pos !== 0) colors.unshift({ hex: colors[0].hex, pos: 0 }); + if (colors[colors.length - 1].pos !== 100) colors.push({ hex: colors[colors.length - 1].hex, pos: 100 }); + for (let i = 0; i < colors.length - 1; i++) { + let currentColor = colors[i]; + let nextColor = colors[i + 1]; + if (currentColor.pos > nextColor.pos) { + const newColor = currentColor; + currentColor = nextColor; + nextColor = newColor; + } + + const numSteps = text.length; + const lowerRange = Math.round(colors[i].pos / 100 * numSteps); + const upperRange = Math.round(colors[i + 1].pos / 100 * numSteps); + if (lowerRange === upperRange) continue; + output += `${text.substring(lowerRange, upperRange)}`; + } + OutputArray.push(output); + } + else if (store.type == 4) { const hex = convertToHex(gradient.next()); clrs.push(hex); let hexOutput = store.format.color; diff --git a/src/routes/resources/animtab/index.tsx b/src/routes/resources/animtab/index.tsx index 1db351b3..f74d3d96 100644 --- a/src/routes/resources/animtab/index.tsx +++ b/src/routes/resources/animtab/index.tsx @@ -376,7 +376,7 @@ export default component$(() => { const newColors = store.colors.map(color => ({ hex: getRandomColor(), pos: color.pos })); store.colors = newColors; }}> - +