I am implementing Paint application in WPF. I am able to implement pencil tool and line tool. But I am unable to implement fill tool which will help me to color a shape (like on in ms paint)

See my main problem is not to color shapes like rectangle or ellipse but a custom shape which i draw using my pencil tool. To make it more clear following is logic of my pencil tool.

Here each line is a object and I have to fill a shape is is created by numerous of such object.

Pencil Tool Logic
get initial_coordinates coordinates

function mousemove
final_coordinates = get mouse coordinates
draw line(inital_coordinates, final coordinates)

initial_coordinates = final_coordinates;