function pad(num, size) {
num = num.toString();
while (num.length < size) num = "0" + num;
return num;
}
const msg:string = "Einen Farbverlauf (schwarz-rot-gold) programmieren:";
let r = 0;
let g = 0;
let b = 0;
let s = "$";
let half = msg.length / 2;
for (let i = 0; i < msg.length; i++) {
if (i < half) {
r = Math.round(255 * i / half);
} else {
g = Math.round(255 * (i - half) / half);
}
s += `\\color{#${pad(r.toString(16), 2)}${pad(g.toString(16), 2)}${pad(b.toString(16), 2)}}`;
let c = msg.charAt(i);
if (c == ' ')
s += `{\\${c}}`;
else
s += `{${c}}`;
}
s += "$"
console.log(s);
To embed this program on your website, copy the following code and paste it into your website's HTML: