namecantbebl0nk

multi-colour gradient

Feb 27th, 2025
9
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. import numpy as np
  2.  
  3. def hex_to_rgb(hex_color):
  4. hex_color = hex_color.lstrip("#")
  5. return tuple(int(hex_color[i:i+2], 16) for i in (0, 2, 4))
  6.  
  7. def generate_linear_gradient_text(sentence, start_hex, end_hex):
  8. start_rgb = hex_to_rgb(start_hex)
  9. end_rgb = hex_to_rgb(end_hex)
  10. num_colors = len(sentence)
  11.  
  12. r_values = np.linspace(start_rgb[0], end_rgb[0], num_colors, dtype=int)
  13. g_values = np.linspace(start_rgb[1], end_rgb[1], num_colors, dtype=int)
  14. b_values = np.linspace(start_rgb[2], end_rgb[2], num_colors, dtype=int)
  15.  
  16. return "".join(
  17. f"[COLOR=rgb({r},{g},{b})]{char}[/COLOR]"
  18. for char, r, g, b in zip(sentence, r_values, g_values, b_values)
  19. )
  20.  
  21. sentence = "gradient text"
  22. start_hex = "#00FFC8"
  23. end_hex = "#C800FF"
  24.  
  25. colored_text = generate_linear_gradient_text(sentence, start_hex, end_hex)
  26. print(colored_text)
Add Comment
Please, Sign In to add comment