Think about Loose Coupling | |
PerlMonks |
Re: Plotting A Lineby Abigail-II (Bishop) |
on Oct 27, 2003 at 22:11 UTC ( [id://302541]=note: print w/replies, xml ) | Need Help?? |
Bresenham is an algorithm for devices that only have 1 bit
pixels, on and off. You also get very nasty artifacts.
A line from (0, 0) to (8, 2) would look like:
Now, if all your pixels are either black or white, this isn't too bad. But the human eye is very good in seeing the non-smoothness, the "staircase" sticks out like a sore thumb. But if you have a grayscale (or full colour) device available, there are much better techniques. One technique revolves around the observation a line needs thickness to be seen. So, if you want to draw a line from say (0, 0) to (8, 2), assume you have a rectangle of width 1 and length 2 * sqrt (17), running from (0, 0) to (8, 2). This will cover some of the pixels partially. If a pixel is covered for say, 61%, the pixel should get a gray value that's 61% of pure black. Now, this still isn't perfect, but it's a step better. There are lots of line drawing algorithms, each of them finding a different balance between simplicity, speed, good results and avoidance of artifacts. Abigail
In Section
Seekers of Perl Wisdom
|
|