from keras.datasets import mnist
import matplotlib.pyplot as plt

(x_train, y_train), (x_test, y_test) = mnist.load_data()


def show(number: int, show_numbers=3, as_ascii: bool = True):
    image_index = 0
    shown = 0

    while shown < show_numbers:

        if y_train[image_index] == number:
            if as_ascii:
                show_ascii(image_index)
            else:
                show_plt(image_index)
            shown += 1
        image_index += 1


def show_plt(image_index: int):
    plt.imshow(x_train[image_index], cmap='Greys')
    plt.show()


def show_ascii(image_index: int):
    result = ""

    for row in x_train[image_index]:
        for col in row:
            if col == 0:
                result += '  '
            elif 0 < col < 150:
                result += '..'
            elif col >= 150:
                result += '**'
        result += '\n'

    print(result)


if __name__ == "__main__":
    show(3, 4, False)
