correct palette for 172

This commit is contained in:
Matt Walsh committed 2021-03-01 20:04:34 -06:00
1 parent 3fb81c209f
commit d84e1d203d
2 files changed
+53 -13

No files matched your search

+28 -7
View File
@@ -3,7 +3,10 @@
// generate a palette as rgb[a](r,g,b)
// input can be rgb (3) or rgba (4) palette[] elements per color
// output can be structured the same as input
const generate = (palette = [], _options) => {
// input can consist of an array where each 3/4 elements represents a color
// or an object {colors: [r1,g1,b1,r2,g2,b2,...], thresholds: [t1,t2]}
// all values less than the threshold at index 0 will receive the set of colors at index zero
const generate = (palette, _options) => {
// combine options with defaults
const options = {
inSize: 3,
@@ -11,13 +14,31 @@ const generate = (palette = [], _options) => {
..._options,
};
const output = [];
for (let i = 0; i < palette.length; i += options.inSize) {
const color = palette.slice(i, i + options.inSize);
if (options.outSize === 3) output.push(`rgb(${color[0]},${color[1]},${color[2]})`);
if (options.outSize === 4) output.push(`rgba(${color[0]},${color[1]},${color[2]},${(color[3] ?? 255) / 255})`);
// grab the color values
const colors = palette.colors ?? palette;
// expand the colors to css format
const rgbColors = [];
for (let i = 0; i < colors.length; i += options.inSize) {
const color = colors.slice(i, i + options.inSize);
if (options.outSize === 3) rgbColors.push(`rgb(${color[0]},${color[1]},${color[2]})`);
if (options.outSize === 4) rgbColors.push(`rgba(${color[0]},${color[1]},${color[2]},${(color[3] ?? 255) / 255})`);
}
return output;
// if no thresholds were provided, return
if (!palette.thresholds) return rgbColors;
// expand the palette following thresholds
const expanded = [];
let currentThreshold = 0;
for (let i = 0; i < 256; i += 1) {
// test for next threshold
if (i > palette.thresholds[currentThreshold]) {
currentThreshold += 1;
}
// add value to array
expanded.push(rgbColors[currentThreshold]);
}
return expanded;
};
module.exports = {
+25 -6
View File
@@ -2,12 +2,31 @@ const code = 172;
const abbreviation = 'DTA';
const description = 'Digital Total Accumulation';
// 4-bit palette
// same as 78 N1P
const palette = [];
for (let i = 0; i < 256; i += 1) {
palette.push(0, 0, i * 4);
}
const palette = {
colors: [
0, 0, 0,
0, 10, 100,
0, 50, 200,
0, 80, 230,
0, 110, 255,
128, 224, 80,
100, 184, 64,
72, 144, 48,
32, 104, 32,
16, 64, 16,
250, 240, 0,
240, 128, 32,
240, 16, 32,
134, 0, 0,
115, 0, 155,
196, 42, 128,
175, 0, 215,
190, 190, 190,
230, 230, 230,
255, 255, 255,
],
thresholds: [8, 16, 24, 32, 40, 56, 72, 88, 104, 120, 136, 152, 168, 184, 200, 208, 216, 224, 232],
};
module.exports = {
code,