views:

8

answers:

0

Say I'm creating a raster-based paint program. My brush is ellipse-shaped. The user clicks and then drags the mouse to paint an area. I now have two points: pointA (where they clicked) and pointB (the first point returned from the mouse-drag). I want to fill in all pixels that fall within the brush region. What's the best way to do this?

My first approach is to calculate the slope between the two points and then increment from pointA to pointB. For each point in between, I search for all pixels within range of the ellipse and turn them on if they are in range. But this seems inefficient, since pixels will often be checked more than once -- often several times over, since the increment is much smaller than the ellipse (think Venn diagram).

Is there a better approach to this? One that is more efficient and minimizes the number of times a pixel needs to be checked.