Written response:

The when more than about 50 button clicks have been made, the applet has the following behavior: suppose that on button click n the vertical lines are regularly spaced across the whole applet. On button click N+1, there is indeed on more line, but the vertical lines, rather than spacing across the entire applet, cover only a portion of the applet. On button click N+2 one more line appears, to the right of the existing lines, but the spacing does not change. Hence,, there remains room at the right for more lines. This continues until N+M clicks, when there is no more room for more lines to be added with the existing spacing to the right of the current lines. On click N+M+1, the lines appear much closer together. This continues happening.

At about button click 151 you stop seeing lines and see instead one big black bar. This occurs because the lines are spaced at an interval of 1, that is they are next to each other. The lines are black and there is no space between them, so you get a black bar.

At about button click 400 something even weirder happens, the black bar disappears, and there is a single line at the right (and on the top) of the applet.

All of this can be accounted for by integer division. Suppose that you compute the spacing of the lines outside the loop drawing the lines. Further suppose that the applet has a with of 100. After 25 clicks, the spacing will be 4. after 26 the spacing will be 3. The spacing will remain 3 until the 34 click where it will change to 2. Then after 50 clicks it will change to 1. At this point you will get the black bar. (It took 151 clicks in the actual applet because the applet width was actually 300, not 100). Finally, after 101 click, the spacing would go to 0 (because 100 / 101 is 0 under integer math.

If you look at the code you will see the calculation of the variable "inc" is indeed, outside the loop.


Click Here to see the code.
geoffrey
Last modified: Fri Oct 15 15:22:00 EDT 2004