0

I'm asking myself how to create a long shadow programmatically. Here its already working.

I would like to provide this functionality in a Java library (Android and maybe in JavaFX). What amazes me the most is the fact that the shadow creation works for a given text and also a image file.

If someone has any idea / advice how to get this working, please let me know, thanks in advance.

To draw black pixels in a loop which increments X and Y is the easiest part, I guess.

halfer
  • 19,824
  • 17
  • 99
  • 186
Martin Pfeffer
  • 12,471
  • 9
  • 59
  • 68
  • it's hard to see the long shadow - i finally managed to see it ^^ – Martin Frank Feb 10 '16 at 13:21
  • 1
    are you looking for a line algorithm (https://de.wikipedia.org/wiki/Bresenham-Algorithmus) ? – Martin Frank Feb 10 '16 at 13:31
  • Thanks Martin, thats a very good point. I guess it would be a decent solution to analyze the image colors (like here http://stackoverflow.com/questions/7807360/how-to-get-pixel-colour-in-android) and apply the shadow with the Bresenham. Will update if I have a result. – Martin Pfeffer Feb 10 '16 at 13:53
  • ok if that really helped, then have a look into http://www.redblobgames.com/articles/visibility/ .... there is described, how to use/detect corners and from there cast a 'shadow' – Martin Frank Feb 11 '16 at 04:51
  • instead of rotating around, you have one fixed direction and go (either vertically or horizontally) across the whole draw-content. draw your shadow (or draw your light, either way works)... – Martin Frank Feb 11 '16 at 05:05

1 Answers1

1

You have to define a line (red line, see Bresenham) and move the line across your whole image...
in my example: we move move horizontallyenter image description here

1) set the line to the very left (maybe even outside the visible scope).
2) set the line color to 'light'.
3) walk along each pixel from the line and draw the pixel with the line color. if the pixel hits a visible pixel (green rectangle), change the line color to 'shadow'
4) move the line one pixel to the right
5) if(not reached_right_border) goto 1
6) redraw text/image over the shadow

Martin Frank
  • 3,445
  • 1
  • 27
  • 47