У меня проблема с печатью.
Скажите, пожалуйста, возможно ли напечатать каждый символ в своем собственном цвете? Мне нужно напечатать «пиксели» с их цветом. В настоящее время я использую черный / белый дистрибутив черный (либо все три из rgb равны 0, либо a равен 0)
`
from colorama import Fore
import matplotlib.pyplot as plt
import numpy as np
from PIL import Image
class picture:
def __init__(self, name="untitled image"):
self.height = 5
self.width = 5
self.name = "Untitled"
self.coords = dict()
self.name = name
for x in range(0, self.width):
for y in range(0, self.height):
self.coords[tuple((x,y))] = [255, 255, 255, 255]
def check_dict(self):
counter = 0
for coord in self.coords:
counter+=1
for pixel in coord:
if pixel <0 or pixel >255:
return 0
return counter == self.width*self.height
def fill_with(self, rgba):
for y in range(0, self.height):
for x in range(0, self.width):
self.coords[(x,y)] = list(rgba)
def fill_black(self):
self.fill_with([0,0,0, 255])
def get_matrix(self):
matrix = []
for y in range(0, self.height):
matrix.append([])
for x in range(0, self.width):
matrix[y].append(())
for coord in self.coords:
matrix[coord[0]][coord[1]] = self.coords[coord]
return matrix
def __str__(self):
result = ""
for y in range(0, self.height):
for x in range(0, self.width):
if sum(self.coords[(x,y)][:2])==0 or self.coords[(x,y)][3]==0:
result+="-"
else:
result+="*"
result+="\n"
return result
a = picture()
print(a.get_matrix())
b = picture()
print(b.get_matrix())
print(Fore.RED+str(a))
`