Division II

Earlier I mentioned division as finding the length of ticks given a side of land and the number of divisions upon it:

barHeight = screen.getHeight() / numBars;

Another division is to find the number of ticks instead:

numberOfMessages = screen.getHeight() / FONT_SIZE;

This lets you determine if there are more messages than you can draw on the screen:

if (messages.size() > screen.getHeight() / FONT_SIZE)

Where messages is a java.util.LinkedList.

The intuition of the first kind of division, in terms of multiplication, the product of barHeight and numBars to equal the screen’s height, becomes barHeight added to itself once plus (numBars – 1) times, as if you were filling the height of the space with individual bars of fractional height, totaling then to the full.

The second kind of division is more confusing: messages.size() speaks to a magnitude than a discrete collection – it feels strange to add numberOfMessages plus numberOfMessages (FONT_SIZE – 1) times. In this case, FONT_SIZE is the “barHeight,” and we sum it like this: FONT_SIZE + FONT_SIZE * (numberOfMessages – 1) to equal the screen’s height.

Pressing with this line, does it make sense that

numBars = screen.getHeight() / barHeight;

This should feel similar to the second example.

In fact, it seems there’s only one kind of division and two ways of looking at the term order.

Code from Brackeen.