 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
dimitris Guest
|
Posted: Mon Mar 14, 2005 12:51 pm Post subject: Painting a map |
|
|
I have a 3d function z:=f(x,y) over an area and I want to paint a map of
this area using all the spectrum. What is the best method for picking colors
for values from -1 to 0 and from 0 to 1 ?
|
|
| Back to top |
|
 |
Jens Gruschel Guest
|
Posted: Mon Mar 14, 2005 3:54 pm Post subject: Re: Painting a map |
|
|
| Quote: | I have a 3d function z:=f(x,y) over an area and I want to paint a map of
this area using all the spectrum. What is the best method for picking colors
for values from -1 to 0 and from 0 to 1 ?
|
Depends Sometimes red colors are used for high values, blue or green
colors for low values, medium values might be represented with yellow
(just like temperature maps known from the weather forecast). To get the
color for a value (in range -1..1) you could use something like:
function GetMyColor(Value: Double): TColor;
begin
if Value < 0 then
Result := $00FF00 + Round((1.0 + Value) * $FF)
else
Result := $0000FF + (Round((1.0 - Value) * $FF) shl ;
end;
To get more special color gradient, you can use my TColorGradient class
(see b.p.attachments "Color gradients). You can use it like that:
var
Gradient: TPegtopColorGradient;
Colors: TPegtopColorArray;
begin
// do this at the beginning:
Gradient := TPegtopColorGradient.Create(
[clBlue, clGreen, clYellow, clRed]);
try
SetLength(Colors, 2001);
Gradient.GetColors(Colors);
// do this while painting:
// (-1.0 <= MyValue <= 1.0)
MyColor := Colors[Round(MyValue * 1000) + 1000];
// don't forget to clean up:
finally
Gradient.Free;
end;
end;
Jens
|
|
| Back to top |
|
 |
dimitris Guest
|
Posted: Mon Mar 14, 2005 8:17 pm Post subject: Re: Painting a map |
|
|
Thx a lot Jens for the quick reply.
I'll try both methods to see which one works better.
"Jens Gruschel" <nospam (AT) thisurldoesnotexist (DOT) com> wrote
| Quote: | I have a 3d function z:=f(x,y) over an area and I want to paint a map of
this area using all the spectrum. What is the best method for picking
colors
for values from -1 to 0 and from 0 to 1 ?
Depends Sometimes red colors are used for high values, blue or green
colors for low values, medium values might be represented with yellow
(just like temperature maps known from the weather forecast). To get the
color for a value (in range -1..1) you could use something like:
function GetMyColor(Value: Double): TColor;
begin
if Value < 0 then
Result := $00FF00 + Round((1.0 + Value) * $FF)
else
Result := $0000FF + (Round((1.0 - Value) * $FF) shl ;
end;
To get more special color gradient, you can use my TColorGradient class
(see b.p.attachments "Color gradients). You can use it like that:
var
Gradient: TPegtopColorGradient;
Colors: TPegtopColorArray;
begin
// do this at the beginning:
Gradient := TPegtopColorGradient.Create(
[clBlue, clGreen, clYellow, clRed]);
try
SetLength(Colors, 2001);
Gradient.GetColors(Colors);
// do this while painting:
// (-1.0 <= MyValue <= 1.0)
MyColor := Colors[Round(MyValue * 1000) + 1000];
// don't forget to clean up:
finally
Gradient.Free;
end;
end;
Jens
|
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|