# Board index » cppbuilder » which colors for a frame3d ?

## which colors for a frame3d ?

2003-11-18 05:22:58 PM
cppbuilder103
Hi, maybe this will seem a little stupid, but...
I want to represent small square tiles
(in green, red, yellow, blue and dark gray)
on a light gray background.
I would like to add a little 3d effect and I've
seen that maybe the Drame3D function can help:
Frame3D(Graphics::TCanvas * Canvas, Windows::TRect &Rect, Graphics::
TColor TopColor, Graphics::TColor BottomColor, int Width);
That function draws a 3d rectangular frame using two
given colors. To obtain a 3d effect I have to
fill the square with my color and then call frame3d with
a lighter and a darker color.
Now the question:
is there a mathematical formula to compute (in a consistent
way across tiles of different colors)
the rgb components of a ligher and darker color of a given color?
Thanks,
g.

## Re:which colors for a frame3d ?

Giovanni Resta < XXXX@XXXXX.COM >wrote:
##### Quote
To obtain a 3d effect I have to fill the square with my color
and then call frame3d with a lighter and a darker color.

Now the question:

is there a mathematical formula to compute (in a consistent
way across tiles of different colors) the rgb components of a
ligher and darker color of a given color?
I would simply compute the mean value of your color and white
TColor DarkerColor(TColor AColor)
{
static int ColorBlack = ColorToRGB(clBlack);
int Color = ColorToRGB(AColor);
BYTE Red = static_cast<BYTE>((GetRValue(Color) + GetRValue(ColorBlack)) / 2);
BYTE Green = static_cast<BYTE>((GetGValue(Color) + GetRValue(ColorBlack)) / 2);
BYTE Blue = static_cast<BYTE>((GetBValue(Color) + GetRValue(ColorBlack)) / 2);
return static_cast<TColor>(RGB(Red, Green, Blue));
}
TColor LighterColor(TColor AColor)
{
static int ColorWhite = ColorToRGB(clWhite);
int Color = ColorToRGB(AColor);
BYTE Red = static_cast<BYTE>((GetRValue(Color) + GetRValue(ColorWhite)) / 2);
BYTE Green = static_cast<BYTE>((GetGValue(Color) + GetRValue(ColorWhite)) / 2);
BYTE Blue = static_cast<BYTE>((GetBValue(Color) + GetRValue(ColorWhite)) / 2);
return static_cast<TColor>(RGB(Red, Green, Blue));
}
If that doesn't result in good colors you may have to play with
factors, i.e. instead of (color + white) / 2 you would do:
(color*f1 + white*f2) / (f1+f2)