私は1つのDelphi XE2
プロジェクトを持っています。私のプロジェクトでは、MainForm
、Label01
、Label02
、Label03
、Label04
、Label05
、Label06
、Edit01
、Edit02
、Edit03
およびがあります。 Edit04
BitBtn01
BitBtn02
Timer01
Timer02
私は以下を実装しようとしています:
の後にButton Click
、「Windows 7 でタスクバーの作業が完了した後、Microsoft がこのことを行った」のように、連続的に増減します。Brightness
Label01.Font.Color
だから私の論理は次のBitBtn01.Click
とおりです。が 100% 未満の場合は、だけ増加します。100% に達した後、最大 25% 減少します。は常に、保持および定数と呼ばれる手順に従って更新されます。これらの手順は、に従って機能します。 Label01.Font.Color
HSB Color Model
RGBToHSV
Brightness
Timer01
Brightness
Timer02
Brightness
Label01.Font.Color
HSVToRGV
Hue
Saturation
Color Conversion Algorithm
私の要件によると、次のコードを作成しました。
unit ApplicationWizard01;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls, Vcl.StdCtrls, Vcl.Buttons, Math;
type
TMainForm = class(TForm)
BitBtn01: TBitBtn;
BitBtn02: TBitBtn;
Edit01: TEdit;
Edit02: TEdit;
Edit03: TEdit;
Edit04: TEdit;
Label01: TLabel;
Label02: TLabel;
Label03: TLabel;
Label04: TLabel;
Label05: TLabel;
Label06: TLabel;
Timer01: TTimer;
Timer02: TTimer;
procedure BitBtn01Click(Sender: TObject);
procedure Timer01Timer(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure BitBtn02Click(Sender: TObject);
procedure Timer02Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
MainForm: TMainForm;
implementation
{$R *.dfm}
procedure HSVToRGB(Const H, S, V: Real; { 'H' In '000' To '001', 'S' In '000' To '001', 'V' In '000' To '255' }
Out R, G, B: Real); { 'R' In '000' To '255', 'G' In '000' To '255', 'B' In '000' To '255' }
const
SectionSize = 60/360;
var
F: real;
P, Q, T: real;
Section: real;
SectionIndex: integer;
begin
if H < 0 then
begin
R:= V;
G:= R;
B:= R;
end
else
begin
Section:= H/SectionSize;
SectionIndex:= Floor(Section);
F:= Section - SectionIndex;
P:= V * ( 1 - S );
Q:= V * ( 1 - S * F );
T:= V * ( 1 - S * ( 1 - F ) );
case SectionIndex of
0:
begin
R:= V;
G:= T;
B:= P;
end;
1:
begin
R:= Q;
G:= V;
B:= P;
end;
2:
begin
R:= P;
G:= V;
B:= T;
end;
3:
begin
R:= P;
G:= Q;
B:= V;
end;
4:
begin
R:= T;
G:= P;
B:= V;
end;
else
begin
R:= V;
G:= P;
B:= Q;
end;
end;
end;
end;
procedure RGBToHSV(Const R, G, B: Real; { 'R' In '000' To '255', 'G' In '000' To '255', 'B' In '000' To '255' }
Out H, S, V: Real); { 'H' In '000' To '001', 'S' In '000' To '001', 'V' In '000' To '255' }
var
Range: real;
RGB: array[0..2] of real;
MinIndex, MaxIndex: integer;
begin
RGB[0]:= R;
RGB[1]:= G;
RGB[2]:= B;
MinIndex:= 0;
if G < R then MinIndex:= 1;
if B < RGB[MinIndex] then MinIndex:= 2;
MaxIndex:= 0;
if G > R then MaxIndex:= 1;
if B > RGB[MaxIndex] then MaxIndex:= 2;
Range:= RGB[MaxIndex] - RGB[MinIndex];
if Range = 0 then
begin
H:= 0;
S:= 0;
V:= R;
end
else
begin
case MaxIndex of
0:
begin
H:= (G-B)/Range;
end;
1:
begin
H:= 2 + (B-R)/Range;
end;
2:
begin
H:= 4 + (R-G)/Range;
end;
end;
S:= Range/RGB[MaxIndex];
V:= RGB[MaxIndex];
H:= H * (1/6);
if H < 0 then H:= 1 + H;
end;
end;
procedure TMainForm.BitBtn01Click(Sender: TObject);
begin
Timer01.Enabled := true;
end;
procedure TMainForm.BitBtn02Click(Sender: TObject);
begin
Timer01.Enabled := false;
Timer02.Enabled := false;
end;
procedure TMainForm.FormCreate(Sender: TObject);
const
HueStandardisationFactor = 360;
SaturationStandardisationFactor = 100;
BrightnessStandardisationFactor = 100/255;
var
H, S, V, R, G, B: Real;
begin
R := 98;
G := 128;
B := 33;
Label01.Font.Color := RGB(Round(R), Round(G), Round(B));
Edit01.Text := FloatToStr(Round(R)) + ' ' + FloatToStr(Round(G)) + ' ' + FloatToStr(Round(B));
RGBToHSV(R, G, B, H, S, V);
Edit02.Text := FloatToStr(Round(H*HueStandardisationFactor)) + ' ' + FloatToStr(Round(S*SaturationStandardisationFactor)) + ' ' + FloatToStr(Round(V*BrightnessStandardisationFactor));
Label02.Caption := 'Starting RGB Value : ' + '(' + FloatToStr(R) + ' ' + FloatToStr(G) + ' ' + FloatToStr(V) + ')';
Label03.Caption := 'Starting HSV Value : ' + '(' + FloatToStr(Round(H*HueStandardisationFactor)) + ' ' + FloatToStr(Round(S*SaturationStandardisationFactor)) + ' ' + FloatToStr(Round(V*BrightnessStandardisationFactor)) + ')';
end;
procedure TMainForm.Timer01Timer(Sender: TObject);
const
HueStandardisationFactor = 360;
SaturationStandardisationFactor = 100;
BrightnessStandardisationFactor = 100/255;
var
Brightness : Integer;
H1, S1, V1, R1, G1, B1: Real;
H2, S2, V2, R2, G2, B2: Real;
begin
R1 := GetRValue(Label01.Font.Color);
G1 := GetGValue(Label01.Font.Color);
B1 := GetBValue(Label01.Font.Color);
RGBToHSV(R1, G1, B1, H1, S1, V1);
Brightness := Round(V1);
Brightness := Brightness + 1;
if Brightness >= 255 then
begin
Timer01.Enabled := false;
Timer02.Enabled := true;
end;
H2 := H1;
S2 := S1;
V2 := Brightness;
Edit03.Text := FloatToStr(Round(H2*HueStandardisationFactor)) + ' ' + FloatToStr(Round(S2*SaturationStandardisationFactor)) + ' ' + FloatToStr(Round(V2*BrightnessStandardisationFactor));
HSVToRGB(H2, S2, V2, R2, G2, B2);
Label01.Font.Color := RGB(Round(R2), Round(G2), Round(B2));
Edit04.Font.Color := RGB(95, 25, 255);
Edit04.Text := FloatToStr(Round(R2)) + ' ' + FloatToStr(Round(G2)) + ' ' + FloatToStr(Round(B2));
end;
procedure TMainForm.Timer02Timer(Sender: TObject);
const
HueStandardisationFactor = 360;
SaturationStandardisationFactor = 100;
BrightnessStandardisationFactor = 100/255;
var
Brightness : Integer;
H1, S1, V1, R1, G1, B1: Real;
H2, S2, V2, R2, G2, B2: Real;
begin
R1 := GetRValue(Label01.Font.Color);
G1 := GetGValue(Label01.Font.Color);
B1 := GetBValue(Label01.Font.Color);
RGBToHSV(R1, G1, B1, H1, S1, V1);
Brightness := Round(V1);
Brightness := Brightness - 1;
if Brightness <= 25 then
begin
Timer01.Enabled := true;
Timer02.Enabled := false;
end;
H2 := H1;
S2 := S1;
V2 := Brightness;
Edit03.Text := FloatToStr(Round(H2*HueStandardisationFactor)) + ' ' + FloatToStr(Round(S2*SaturationStandardisationFactor)) + ' ' + FloatToStr(Round(V2*BrightnessStandardisationFactor));
HSVToRGB(H2, S2, V2, R2, G2, B2);
Label01.Font.Color := RGB(Round(R2), Round(G2), Round(B2));
Edit04.Font.Color := RGB(15, 135, 255);
Edit04.Text := FloatToStr(Round(R2)) + ' ' + FloatToStr(Round(G2)) + ' ' + FloatToStr(Round(B2));
end;
end.
必要なリンクは次のとおりです。
HSVToRGB 手順 - hxxp://www.delphipages.com/forum/showthread.php?t=133111
RGBToHSV 手順 - hxxp://www.delphipages.com/forum/showthread.php?t=133111
色変換アルゴリズム - hxxp://www.cs.rit.edu/~ncs/color/t_convert.html
「x」を「t」に置き換えます。
私のコーディングは正しく、完全にコンパイルされます。
Hue
しかし、問題は、プログラムを数回実行した後Saturation
、必要なすべての変数をReal
.
そのため、色が元の色からずれています。
色の変化を避けるために、より正確に適用する方法を見つけることができません。