function pad(num, size) {
num = num.toString();
while (num.length < size) num = "0" + num;
return num;
}
function color(a, n) {
return Math.round(1.0 / n * a * 256);
}
const msg:string = "Es ist aber immer noch nicht so gut zu lesen (wie bei dir zum Beispiel) ... Was ist noch falsch?";
const n:number = msg.length;
let r = 0;
let g = 0;
let b = 0;
let s = "$";
for (let i = 0; i < msg.length; i++) {
if (i < n / 2) {
r = color(i, n / 2.0);
} else {
g = color(i - n / 2.0, n / 2.0);
}
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: