Take the 2-minute tour ×  A brief background: I'm working on a
web-based drawing application and one of the tools I'm
implementing is a 1-pixel thick pencil. The tool allows the user
to draw 1px aliased lines on the canvas.  In order to determine
where the user is drawing on the canvas, mouse coordinates are
monitored. If mouse1 is held down, the pixel the cursor is over
will change. Essentially it works just like the pencil tool in
Photoshop.  NOTE: Bresenham's algorithm will not work for this
situation. My input is submitted in real-time, so I'm not
drawing a line from P0 to P1 where the distance between P0 and
P1 is many pixels. In general, P1 is a neighbor of P0.  The
issue I'm having is that my resulting lines do not have a
perfectly clean 1px weight. Here's an example:  Line comparison
Note that both of the lines are hand drawn, so there is some
variance. What's interesting is that Photoshop is able to make a
much cleaner 1px representation of the line that I draw. The
reason why my line looks dirtier