This commit is contained in:
2026-01-16 20:56:16 -06:00
parent 9f6435ece9
commit 22962bbd63
33 changed files with 643 additions and 315 deletions

View File

@@ -1,7 +1,7 @@
function tohex(n) {
var s = number.floor(n).toString(16);
var s = floor(n).toString(16);
if (s.length == 1) s = "0" + s;
return s.toUpperCase();
return upper(s);
};
var Color = {
@@ -22,19 +22,15 @@ Color.editor = {};
Color.editor.ur = Color.green;
Color.tohtml = function (v) {
var html = v.map(function (n) {
return tohex(n * 255);
});
return "#" + html.join("");
var html = array(v, n => tohex(n * 255));
return "#" + text(html);
};
var esc = {};
esc.reset = "\x1b[0";
esc.color = function (v) {
var c = v.map(function (n) {
return number.floor(n * 255);
});
var truecolor = "\x1b[38;2;" + c.join(";") + ";";
var c = array(v, n => floor(n * 255));
var truecolor = "\x1b[38;2;" + text(c, ";") + ";";
return truecolor;
};
@@ -92,7 +88,7 @@ Color.Editor = {
/* Detects the format of all colors and munges them into a floating point format */
Color.normalize = function (c) {
var add_a = function (a) {
var n = this.slice();
var n = array(this);
n[3] = a;
return n;
};
@@ -120,9 +116,7 @@ Color.normalize = function (c) {
// Convert from 0-255 to 0-1 if needed
if (needs_conversion) {
c[p] = c[p].map(function (x) {
return x / 255;
});
c[p] = array(c[p], x => x / 255);
}
c[p].alpha = add_a;
@@ -192,7 +186,7 @@ ColorMap.sample = function (t, map = this) {
if (t > 1) return map[1];
var lastkey = 0;
for (var key of array(map).sort()) {
for (var key of sorted(array(map))) {
if (t < key) {
var b = map[key];
var a = map[lastkey];