I'm attempting to develop a straightforward script that converts RGB-16 colors to RGB-8. The script is functioning properly, but I'm having trouble converting it into a function that can handle two different palettes. Whenever I try using palette.forEach
, an error occurs. It seems like a simple issue, but I just can't seem to find the source of the problem.
const system41 = [
[65535, 65535, 65535],
[64512, 62333, 1327],
[65535, 25738, 652]
];
const system7 = [
[65535, 65535, 52428],
[65535, 52428, 39321],
[52428, 39321, 26214]
];
function convert(palette) {
palette.forEach((child) => {
const rgb8 = child.map(value => Math.round(value / 257));
document.querySelector('#' + palette).innerHTML += rgb8.join(', ') + '\n';
});
}
convert('system41');
convert('system7');
<p>System 4.1 system colors</p>
<pre id="system41"></pre>
<p>System 7 icon colors</p>
<pre id="system7"></pre>