Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- def hex_to_rgb(hex_color):
- hex_color = hex_color.lstrip("#")
- return tuple(int(hex_color[i:i+2], 16) for i in (0, 2, 4))
- def generate_linear_gradient_text(sentence, start_hex, end_hex):
- start_rgb = hex_to_rgb(start_hex)
- end_rgb = hex_to_rgb(end_hex)
- num_colors = len(sentence)
- r_values = np.linspace(start_rgb[0], end_rgb[0], num_colors, dtype=int)
- g_values = np.linspace(start_rgb[1], end_rgb[1], num_colors, dtype=int)
- b_values = np.linspace(start_rgb[2], end_rgb[2], num_colors, dtype=int)
- return "".join(
- f"[COLOR=rgb({r},{g},{b})]{char}[/COLOR]"
- for char, r, g, b in zip(sentence, r_values, g_values, b_values)
- )
- sentence = "gradient text"
- start_hex = "#00FFC8"
- end_hex = "#C800FF"
- colored_text = generate_linear_gradient_text(sentence, start_hex, end_hex)
- print(colored_text)
Add Comment
Please, Sign In to add comment