Color strings using ANSI escape codes. Uses "dithering" to attempt to match the specified RGB value as close as possible.
Project description
A package to color text with ANSI escape codes, but takes in an RGB value and uses dithering to try match it.
The colorize_text function accepts a string and a RGB tuple. It returns the colorized string. To see the package in use you can try the run_example function.
Example usage:
import colordithering
text = '''
███████████████████████████████████
██████████ Hello World! ███████████
███████████████████████████████████
'''
color = (255, 125, 0) # orange color
print(colordithering.colorize_text(text, color))
The return_array parameter of colorize_text will return a 2D array of each character rather than a string. The values in each cell will be a dict, with the keys text and color.
Text will be the character. Color will be the ANSI escape code.
Example usage with return_array:
import colordithering
text = '''
███████████████████████████████████
██████████ Hello World! ███████████
███████████████████████████████████
'''
color = (255, 125, 0) # orange color
colorized = colordithering.colorize_text(text, color, True) # set return_array to True
for y in range(len(colorized)):
for x in range(len(colorized[y])):
character_at_cell = colorized[y][x]["text"]
color_at_cell = colorized[y][x]["color"]
print(color_at_cell + character_at_cell, end="")
# print the ANSI escape code first to set the color, then the character.
# the end="" makes it so python doesn't print a new line automatically
print() # new line
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file colordithering-0.7.tar.gz.
File metadata
- Download URL: colordithering-0.7.tar.gz
- Upload date:
- Size: 3.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.11.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
12665e0d55b9ccdce98eec91db36d4c7950bf62999fc9b2d55d136def7d577d4
|
|
| MD5 |
ea19614d9ff8539350d7cbd79ebf37d1
|
|
| BLAKE2b-256 |
c7547eeb50c1ba0a3acb94ee1c7cff1f5956c1640d2aa5cedee54addafb47ad5
|