[I agree with Stuart, but I insist on an academic exercise.]
Tricky ...
In a way, you are not repeating yourself; you do two similar things that are (literally and figuratively) orthogonal to each other.
I assume that you could do the following, although it was not more readable and, of course, more inefficient:
[pseudo #]:
void DrawGrid()
{
DrawLines(w, rowHeights, true);
DrawLines(h, colWidths, false);
}
void DrawLines(int lineLength, int[] lineSeparations, bool isHorizontal)
{
MyDrawLine(Point(0, 0), Point(lineLength, 0), isHorizontal);
int offset = 0;
for (int i = 0; i < widths.length; i++)
{
offset += lineSeparations[i];
MyDrawLine(Point(offset, 0), Point(offset, lineLength), isHorizontal);
}
}
void MyDrawLine(Point startPoint, Point endPoint, bool isHorizontal)
{
if (isHorizontal)
{
SwapXAndYCoordinates(startPoint);
SwapXAndYCoordinates(endPoint);
}
drawLine(startPoint, endPoint);
}
-, , ...: -)