Let's say you have a rectangle $W$ by $H$, $W > H$. Take a point in one of the smaller sides, and consider an angle theta relative to the base (in degrees, $0 < \theta < 90$). Consider that this point is "thrown" to the other side with this initial theta angle, and that every time it hits a "wall", it is "bounced" the same way as the light (see image below). Express $y$ in function of $x, \theta, W, H$. Notice that the point can bounce from 0 to $\infty$ times (when theta tends to $90^\circ$).

Note:
1) I hope the question was understandable
2) I am sorry for the quality of the image.
Reflecting the rectangle repeatedly on its long side gives a straight line:
The vertical distance travelled after the first reflection is $W\tan\theta-x$. Let $q$ and $r$ be the quotient and remainder after dividing by $H$.
If $q$ is odd, as in the above picture, the top rectangle has the same orientation as the bottom one, giving $y=H-r$. If $q$ is even, the top rectangle has opposite orientation and $y=r$.