fork download
  1. def generate_gradient():
  2. # Define the repeated pattern string
  3. s = "/\\/\\/\\/\\/\\" * 8 # Repeat the pattern 8 times to match the AWK example
  4.  
  5. for colnum in range(77): # Iterate over 77 columns
  6. # Calculate RGB values for the background color
  7. r = int(255 - (colnum * 255 / 76))
  8. g = int((colnum * 510 / 76))
  9. b = int((colnum * 255 / 76))
  10. if g > 255:
  11. g = 510 - g
  12.  
  13. # Calculate RGB values for the foreground (inverse of background)
  14. inv_r = 255 - r
  15. inv_g = 255 - g
  16. inv_b = 255 - b
  17.  
  18. # Print the character with background and foreground colors
  19. print(f"\033[48;2;{r};{g};{b}m\033[38;2;{inv_r};{inv_g};{inv_b}m{s[colnum]}\033[0m", end="")
  20.  
  21. print() # Add a newline at the end
  22.  
  23. if __name__ == "__main__":
  24. generate_gradient()
  25.  
Success #stdin #stdout 0.1s 14204KB
stdin
Standard input is empty
stdout
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/