r/javaScriptStudyGroup • • May 15 '16

Check out my latest CodPen!

http://codepen.io/ForScale/full/rebPvL
2 Upvotes

28 comments sorted by

View all comments

Show parent comments

2

u/Volv May 18 '16 edited May 18 '16

Thanks. Was fun (if a bit tricky) working on a bigger problem.
I've added more comments throughout the fill part.
 
Algorithm:

  • Looks at the pixel you clicked. Say it was black.

  • Check pixels at all 8 surrounding points. top left, top, top right etc

  • If they match original colour (black) change their colour to fill colour

  • Add them to array to check next

  • Use result array to start next round of checking.

  • Uses mem object so it doesn't check previously checked

 
So spreads out from clicked point until it hits a significantly different colour then stops.

2

u/ForScale May 18 '16

Ah... okay. Thanks! That's pretty clever, man. Really nice work with that!