Skip to content

Commit

Permalink
Update script.js
Browse files Browse the repository at this point in the history
  • Loading branch information
Mqxx committed May 24, 2024
1 parent fcc628d commit 092b7f3
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions image_to_tellraw/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,29 @@ const textArea = document.getElementById('textArea');

const tellrawParts = [];
let row = [];
let logRow = [];
let logRowParts = [];
pixels.forEach((pixel, index) => {
const { red, green, blue, alpha } = pixel;
const color = `#${red.toString(16).padStart(2, '0')}${green.toString(16).padStart(2, '0')}${blue.toString(16).padStart(2, '0')}`;
const color = `${red.toString(16).padStart(2, '0')}${green.toString(16).padStart(2, '0')}${blue.toString(16).padStart(2, '0')}`;
if (alpha >= 128) {
row.push(`{"color": "${color}", "text": "█"}`);
row.push(`{"color": "#${color}", "text": "█"}`);
logRow.push(color);
} else {
row.push(`" "`);
logRow.push(' ');
}
if ((index + 1) % img.width === 0) {
tellrawParts.push(`[${row.join(', ')}]`);
console.log(JSON.stringify(logRow));
logRowParts.push(logRow);
row = [];
logRow = [];
}
});

console.log(JSON.stringify(logRowParts,null,2));

const tellrawCommand = `tellraw @a [\n ${tellrawParts.join(', "\\n",\n ')}\n]`;

textArea.value = tellrawCommand;
Expand Down

0 comments on commit 092b7f3

Please sign in to comment.