linear gradient on text

#include <stdio.h>

void printGradientText(const char *text, int startColor, int endColor);

int main() {
    const char *message = "Hello, Gradient!";
    int startColor = 31;  // Red ANSI color code
    int endColor = 36;    // Cyan ANSI color code

    printGradientText(message, startColor, endColor);

    return 0;
}

void printGradientText(const char *text, int startColor, int endColor) {
    int i, j;
    int length = strlen(text);

    for (i = 0; i < length; ++i) {
        float ratio = (float)i / (float)(length - 1);
        int color = (int)((1 - ratio)  startColor + ratio  endColor);

        printf("\033[38;5;%dm%c", color, text[i]);
    }

    printf("\033[0m\n");
}