How to draw a single pixel in a terminal?
Have a look at the Drawille library. It uses the UTF braille characters to draw pixels.
Something like the following would set a single pixel:
from drawille import Canvas
c = Canvas()
c.set(10, 10)
print(c.frame())
Terminals are character-cell displays and don't support drawing pixel graphics. Not even when running in X11; although it's certainly possible to draw individual pixels when talking directly to an X server, if your program is talking to a terminal it can only ask the terminal to display characters.
To display graphics instead of text, you'll need to write a program that interacts directly with the X server. This is typically done through a UI toolkit library such as GTK, Qt, or wxWidgets.
You won't be able to draw single pixel colors in the terminal unless you can do what Wyzard's mentions, program it yourself, or find a tool already made for the job (this could be terminal-specific). However it is possible to use individual character coordinates in your terminal to draw 2D images using ASCII and UTF-8 characters. The tool for this is called tput
. This tool works by manipulating the cursor position according to the coordinates of your current terminal. Here is a sample list of tput
functionalities:
# tput Cursor Movement Capabilities:
tput cup Y X
# Move cursor to screen location X,Y (top left is 0,0)
tput sc
# Save the cursor position
tput rc
# Restore the cursor position
tput lines
# Output the number of lines of the terminal
tput cols
# Output the number of columns of the terminal
tput cub N
# Move N characters left
tput cuf N
# Move N characters right
tput cuu N
# up N lines
tput cud N
# down N lines