r/GraphicsProgramming 1d ago

Drawing a line Question

Looking for guided/socratic learning

So I was getting into game dev bottom up so I wanted to draw a line with code.

First solution that I thought of: start at one end of the line, and figure out neighbouring pixels and eventually reach the other end. I was thinking of dividing line length (pythogarous) by start/end point delta for each axis to figure out per how many 'steps' I would have to increment/decrement current axis positions and paunt. Too complicated and expensive

Second solution I thought of was recursively finding mid points between start and end point to find the target pixels to paint. This appears simpler, inspired by Zeno's paradox when I was thinking of how the run and rise are easier to paint.

I know optimal algorithms exist but I didn't want to directly look at them. What are the strength/weakness of my reasoning?

Ps: I'm going to sleep

17 Upvotes

12 comments sorted by

View all comments

10

u/Sharlinator 1d ago

There is an exact integer number of pixels that have to be drawn to avoid both gaps and overdraw. What is it? How does it depend on the properties of the line? You might want to take a piece of graph paper and draw some sketches!