Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

how to plot points and/or draw lines on the screen

+6 votes
asked Jul 31 by Steve Sacks (190 points)
Is there any way to draw a line or plot points on the screen using C++ ?

1 Answer

+2 votes
answered Nov 19 by ARTEMII KOZHEMIAK (540 points)

Yes, there is, and if you ask how to do it here, welcome to terminal graphics. The easiest way you might think of is having 2d array, representing "pixels" of your program(for screen pixels, you need to learn OpenGL or other graphics library, with windows creation and other cool stuff, but I'm sure it's not supported here)

And easiest way would be to output that array to terminal. Here the increase in x is to the right of the screen and increase in y is to the down of the screen(0,0 is upper left corner)

Points are pretty easy to do: just fill the array cell at given coordinates with something representing your point.

Lines are a bit harder to do, but thankfully to Jack Elton Bresenham, we have the Bresenham's line drawing algorithm It basically approximates a line between 2 points and does that very fast.

The problem with this one is that there's no safety features, so putting pixels outside of the "screen" is an issue, to be easily solved with modulo operator: take a modulo of input x/y coordinate and "screen's" width/height, like such:

screen[ x%screenSizeX][y%screenSizeY]

And yes, there is much more algorithms and other stuff for graphics, and for than I would recommend taking a read on old guides, for old computers, like zx spectrum or commodore 64, since it is similar to what you are doing right now, and programmers somehow did draw stuff quickly with these slow(relatively) computers

commented Nov 19 by Steve Sacks (190 points)
Thank you, Artemii, for your reply.
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...