paint-by-numbers

Relaxing paint-by-numbers game  https://p.ce9e.org/paint-by-numbers/
git clone https://git.ce9e.org/paint-by-numbers.git

commit
1f02c96fa8188da07e163c4471e12e56fe30b076
parent
2ec0f32913ad73d7c98420ba5a0db5f33803ecb5
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2025-08-20 05:30
do not restrict colors to 4bit per channel

Diffstat

M js/color.js 20 +++++---------------

1 files changed, 5 insertions, 15 deletions


diff --git a/js/color.js b/js/color.js

@@ -57,24 +57,14 @@ export var labToRgb = function(lab) {
   57    57 };
   58    58 
   59    59 export var hex = function(rgb) {
   60    -1     return '#'
   61    -1         + Math.floor(rgb[0] / 16).toString(16)
   62    -1         + Math.floor(rgb[1] / 16).toString(16)
   63    -1         + Math.floor(rgb[2] / 16).toString(16);
   64    -1 };
   65    -1 
   66    -1 export var roundLab = function(lab) {
   67    -1     var rgb = labToRgb(lab);
   68    -1     rgb = rgb.map(c => Math.floor(c / 16) * 16);
   69    -1     return rgbToLab(rgb);
   -1    60     var f = c => Math.floor(c).toString(16).padStart(2, '0');
   -1    61     return '#' + f(rgb[0]) + f(rgb[1]) + f(rgb[2]);
   70    62 };
   71    63 
   72    64 export var distance = function(lab1, lab2) {
   73    -1     var rounded1 = roundLab(lab1);
   74    -1     var rounded2 = roundLab(lab2);
   75    65     return Math.sqrt(
   76    -1         Math.pow(rounded1[0] - rounded2[0], 2)
   77    -1         + Math.pow(rounded1[1] - rounded2[1], 2)
   78    -1         + Math.pow(rounded1[2] - rounded2[2], 2)
   -1    66         Math.pow(lab1[0] - lab2[0], 2)
   -1    67         + Math.pow(lab1[1] - lab2[1], 2)
   -1    68         + Math.pow(lab1[2] - lab2[2], 2)
   79    69     );
   80    70 };