function pad(num, size) {
num = num.toString();
while (num.length < size) num = "0" + num;
return num;
}
function color(a, n, maxIncl) {
return Math.round(1.0 / n * a * maxIncl);
}
const msg:string = "Testtext:";
const n1:number = msg.length;
const n2:number = n1 / 2;
const n3:number = n1 % 2 / 2.0;
let r = 0;
let g = 0;
let b = 0;
let s = "$";
for (let i = 0; i < n1; i++) {
if (i < n2) {
r = color(i + 1, n2 + n3, 255);
} else {
g = color(i - n2 + n3 + 1, n2 + n3, 256 / 4 * 3);
}
console.log(r, g, b);
let c = msg.charAt(i);
if (c == ' ') {
s += `\\color{#${pad(r.toString(16), 2)}${pad(g.toString(16), 2)}${pad(b.toString(16), 2)}}{\\${c}}`
} else {
s += `\\color{#${pad(r.toString(16), 2)}${pad(g.toString(16), 2)}${pad(b.toString(16), 2)}}{${c}}`
}
}
s += "$"
console.log(s);
To embed this program on your website, copy the following code and paste it into your website's HTML: