5 ms·
Ask HN: How to draw a single pixel?
This question is maybe an echo from the eighties, but I am interested to find resources so as to draw a single pixel on the terminal. If I could change the state of one pixel then it would be just math to go from pixel to lines and from lines to curves and from curves to shapes.
If I am not mistaken one of the important steps is to activate the so called video mode and not the text mode. Reading a bit about that I guess I have to access the memory buffer and modify individual chunks of memory. I cannot estimate how difficult this can be.
I know that there are libraries to let you do that on another window and of course to let you create images. Creating SVG pictures is rather trivial for example. I am interested to learn my self how to go in that level than to use a library.
I would be grateful to find resources for that and preferably in the following languages. Common Lisp > Python > C.
Feel free to ignore my question since it is driven by curiosity to hack and not from urgent need for productivity.
- mooism2 16y agoAre you running under Windows, OS X, Linux, something else?
- RiderOfGiraffes 16y agoAnd if you're running Linux, which window manager are you running?
- gsivil 16y agoI am running Linux (ubuntu 10.10) and I am using the Gnome terminal. Of course I could switch to something else if this could make things easier.
- mooism2 16y agoYou cannot draw graphics in a terminal window (he says, half-expecting to be corrected). Your program can open up a window of its own and draw graphics in that. Or you can do the low level thing on a different virtual console using Linux's framebuffer support (see the svgalib link octopus posted above) (as an aside, press Ctrl+Alt+F2, observe what happens, then Alt+F7 to return here).
- wnoise 16y ago> You cannot draw graphics in a terminal window (he says, half-expecting to be corrected). Depends on the terminal. xterm has a "tektronix mode" to emulate the old Tektronix 4014 graphic terminal. This has a 4096x4096 coordinate system for vector graphics. Most other terminals do not emulate this, of course. http://en.wikipedia.org/wiki/Tektronix_4010 http://en.wikipedia.org/wiki/Tektronix_4010
- sky87 16y agoWell, it pretty much depends on what system you are using. On linux for example you could use frame buffers (on windows or osx i have no idea). But i think you should check out some kind of library like SDL, which is easy to use and has bindings for common lisp and python (it's written in C). EDIT: take a look to http://code.google.com/p/lispbuilder/wiki/LispbuilderSDL http://code.google.com/p/lispbuilder/wiki/LispbuilderSDL
- octopus 16y agoRead the manual page about "vga_drawpixel" function. I'm not sure you can use this if you run under X. Here is a useful link: http://linux.die.net/man/3/vga_drawpixel http://linux.die.net/man/3/vga_drawpixel You should probably use a more advanced graphics library like the one provided by Gnome, but if you want to learn how to do it from scratch I suppose you need to start from a text mode Linux installation.
- sagacity 16y agoMust you make me jog back such old memories? (Well actually, Thank you :-)) FWIW, this is how we used to do it in BASIC, C and MASM in the good ol' DOS days, back in the 80s; hope it can give you at least some conceptual confirmation + insight: You wrote: > activate the so called video mode and not the text mode Spot on. > access the memory buffer and modify individual chunks of memory Spot on again. Unless I'm forgetting something, DOS used to reserve a chunk of RAM (that they called 'lower memory') as video RAM. We used to 'peek' and 'poke' bytes directly to this (at mem segment 0800:0000Hex or something). Of course, that was on CGA display adapters, and under DOS. With today's SVGA and whatnot + Ubuntu, a lot of these specifics would change but I'm afraid I won't be able to help you with all that - been a while (about 2 decades) since I could last indulge into that sort of hacking. Well, best wishes from an ancient hacker - may you keep at it for as long as you wish to.