// 21 January 2012: An improved grayRamp() function and call: // The function: //-------------------------------------------------------- GRAY RAMP FUNCTION TColor grayRamp(int part, int whole) { if (whole == 0) whole = 1; // prevent divide by zero part = part % whole; // keep part less than whole int distance = ( part * 255 ) / whole; return static_cast(RGB(distance, distance, distance)); } // The call: Form1->PaintBoxGrayRamp->Canvas->Pixels[i][j] = grayRamp(part, whole);