Given a 2D pixel array where any pixel can be either 0 or 1, what algorithm would output a new 2D pixel array, where each pixel with a value of 1 would get a new value based on the minimum amount of line segments required to reach a specific "light source" pixel, while only crossing pixels that have an input value of 1? Input values of 0 would not change.
Example of input array, magenta cross represents the "light source" pixel:
https://cdn3.imggmi.com/uploads/2019/1/8/2a5f6dd0ebdc9c72115f9ce93af3337a-full.png
Output array with output values 1 and 2 (Photoshopped, not a pixel perfect image):
https://cdn3.imggmi.com/uploads/2019/1/8/0025709aaa826c26ee0a8e17476419cb-full.png
- Red region = 1 line segment away from source
- Yellow region = 2 line segments away from source
- White region = 3 or more line segments away from source
(The algorithm wouldn't stop at 3, it would continue until every pixel is evaluated.)
EDIT: I'm not sure whether StackOverflow is the right Stack Exchange site to post this in, if not please let me know!