4 ms·
If you want to draw a line, say, from (0, 0) to (13, 5) by setting values in a pixel buffer (with no anti-aliasing) you have the same problem. The classical so
by csense 4y ago
If you want to draw a line, say, from (0, 0) to (13, 5) by setting values in a pixel buffer (with no anti-aliasing) you have the same problem.
The classical solution (Bresenham's algorithm) is basically to draw pixels in the direction of the longer axis (in this case the X axis), adding a fractional increment of 5/13 to an accumulator to represent the subpixel movement on the shorter axis (in this case the Y axis). When the accumulator exceeds the threshold, you move a pixel on the short axis and subtract 1 from the accumulator.
You can equivalently start the accumulator at 0.5 with threshold of 1, for an accumulator range of [0, 1], or start at 0 with a threshold of 0.5, for a range of [-0.5, 0.5]. Instead of tracking the accumulator directly, you can track the product accumulator*13, which lets you use all-integer arithmetic.
The explanation based on Bjorklund's algorithm seems less intuitive and more convoluted than one based on Bresenham's algorithm.
I also don't really see the connection to Euclid's algorithm.
In one sentence: Most "interesting rhythms" are integer approximations of repeatedly adding a fraction.
[1] https://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm https://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm