utils.py

Created by mino-1289

Created on June 05, 2021

1.01 KB


try:
    from kandinsky import set_pixel, color
except:
    def set_pixel(x: int, y: int, c: Color):
        pass


    def color(r: int, g: int, b: int):
        return (r, g, b)


class Color:
    """
    Représente une couleur sous un tuple de trois valeurs RGB
    """

    def __init__(self, r: int, g: int, b: int) -> None:
        c = color(r, g, b)
        for k in c:
            if not (0 <= k <= 255) or not isinstance(k, int):
                c = (0, 0, 0)
        self.c = c

    def __repr__(self) -> str:
        return str(tuple(self.c))


class Screen:
    """
    Représente l'écran de la calculatrice en 320*222
    """

    def __init__(self) -> None:
        self.cells = [
            [Color(255, 255, 255) for _ in range(320)]
            for _ in range(222)
        ]

    def __getitem__(self, i: int):
        return self.cells[i]

    def prntsc(self) -> None:
        for i in range(self.cells):
            for j in range(self.cells[i]):
                set_pixel(i, j, self.cells[i][j])

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.