C how to draw a point / set a pixel without using graphics library or any other library functions

前端 未结 3 1322
无人共我
无人共我 2020-12-31 20:33

I am trying to understand how I can draw a set of points (/set the pixels) that form a circle without using the library functions.

Now, getting the (x,y) co-ordinat

3条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-31 21:03

    It's a tough question because technically C doesn't have any built-in input/output capability. Even writing to a file requires a library. On certain systems, like real-mode DOS, you could directly access the video memory and set pixels by writing values into that memory, but modern OSes really get in the way of doing that. You could try writing a bootloader to launch the program in a more permissive CPU mode without an OS, but that's an enormous can of worms.

    So, using the bare mimimum, the stdio library, you can write to stdout using ascii graphics as the other answer shows, or you can output a simple graphics format like xbm which can be viewed with a separate image-viewing program. A better choice might be the netpbm formats.

    For the circle-drawing part, take a look at the classic Bresenham algorithm. Or, for way too much information, chapter 1 of Jim Blinn's A Trip Down the Graphics Pipeline describes 15 different circle-drawing algorithms!

提交回复
热议问题