MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/javaScriptStudyGroup/comments/4jgwpr/check_out_my_latest_codpen/d3a6qf9
r/javaScriptStudyGroup • u/ForScale • May 15 '16
28 comments sorted by
View all comments
Show parent comments
2
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!
Ah... okay. Thanks! That's pretty clever, man. Really nice work with that!
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.