Search code examples
python-3.xcommand-linegame-engine

Is it possible to draw a single pixel to command prompt in python


So i wanna create game engine with python. Running on command prompt.

I wanna know what method an draw a single pixel to command prompt.


Solution

  • The curses may help you doing so, here's a quick example drawing a diagonal of points:

    import time
    import curses
    
    window = curses.initscr()
    for x in range(30):
        window.addch(x, x, ".")
    window.refresh()
    time.sleep(1)
    curses.endwin()
    

    Keep in mind that the terminal has a character resolution: you won't be able to place pixels at any places.

    But you can trick by using other chars than a dot, see for example the bb demo:

    apt install bb
    DISPLAY= bb
    

    (cleaning the DISPLAY variable to force it to run inside your terminal)