Droite graduée

XgaletteX Messages postés 102 Date d'inscription samedi 14 mai 2005 Statut Membre Dernière intervention 12 août 2005 - 3 juin 2005 à 11:33
adec0127 Messages postés 53 Date d'inscription samedi 7 août 2004 Statut Membre Dernière intervention 22 février 2008 - 28 juil. 2005 à 18:19
Bonjour,

Es ce que quelqu'un connai un composant ou autrre chose permettant de faire des droite graduée, c'est en faite un graphique 1D tout simplement

1 réponse

adec0127 Messages postés 53 Date d'inscription samedi 7 août 2004 Statut Membre Dernière intervention 22 février 2008
28 juil. 2005 à 18:19
unit Gradient;

interface

uses
Classes, Controls, Graphics, WinTypes, WinProcs;

type
TDireccion = (dHorizontal, dVertical);
TGradient = class(TGraphicControl)
private
FDireccion : TDireccion;
FColorDesde, FColorHasta : TColor;
procedure SetDireccion(valor : TDireccion);
procedure SetColorDesde(valor : TColor);
procedure SetColorHasta(valor : TColor);
protected
procedure Paint; override;
public
constructor Create(AOwner : TComponent); override;
published
property Direccion : TDireccion read FDireccion write SetDireccion default dHorizontal;
property ColorDesde : TColor read FColorDesde write SetColorDesde default clBlue;
property ColorHasta : TColor read FColorHasta write SetColorHasta default clBlack;
property Align;
end;

procedure Register;

implementation

constructor TGradient.Create(AOwner : TComponent);
begin
inherited Create(AOwner);
FDireccion:=dHorizontal;
FColorDesde:=clBlue;
FColorHasta:=clBlack;
Width:=100;
Height:=100;
end;

procedure TGradient.SetDireccion(Valor : TDireccion);
begin
if FDireccion <> valor then
begin
FDireccion := Valor;
Repaint;
end;
end;

procedure TGradient.SetColorDesde(Valor : TColor);
begin
if FColorDesde <> Valor then
begin
FColorDesde := Valor;
Repaint;
end;
end;

procedure TGradient.SetColorHasta(Valor : TColor);
begin
if FColorHasta <> Valor then
begin
FColorHasta := Valor;
Repaint;
end;
end;

procedure TGradient.Paint;
var
RGBDesde, RGBHasta, RGBDif : array[0..2] of byte;
contador, Rojo, Verde, Azul : integer;
Banda : TRect;
Factor : array[0..2] of shortint;
begin
RGBDesde[0]:=GetRValue(ColorToRGB(FColorDesde));
RGBDesde[1]:=GetGValue(ColorToRGB(FColorDesde));
RGBDesde[2]:=GetBValue(ColorToRGB(FColorDesde));
RGBHasta[0]:=GetRValue(ColorToRGB(FColorHasta));
RGBHasta[1]:=GetGValue(ColorToRGB(FColorHasta));
RGBHasta[2]:=GetBValue(ColorToRGB(FColorHasta));
for contador:=0 to 2 do
begin
RGBDif[contador]:=Abs(RGBHasta[contador]-RGBDesde[contador]);
If RGBHasta[contador]>RGBDesde[contador] then factor[contador]:=1 else factor[contador]:=-1;
end;
Canvas.Pen.Style:=psSolid; Canvas.Pen.Mode:=pmCopy;
if FDireccion = dHorizontal then
begin
Banda.Left:=0;
Banda.Right:=Width;
for contador:=0 to 255 do
begin
Banda.Top:=MulDiv(contador,height,256);
Banda.Bottom:=MulDIv(contador+1,height,256);
Rojo:=RGBDesde[0]+factor[0]*MulDiv(contador,RGBDif[0],255);
Verde:=RGBDesde[1]+factor[1]*MulDiv(contador,RGBDif[1],255);
Azul:=RGBDesde[2]+factor[2]*MulDiv(contador,RGBDif[2],255);
Canvas.Brush.Color:=RGB(Rojo,Verde,Azul);
Canvas.FillRect(Banda);
end;
end;
if FDireccion = dVertical then
begin
Banda.Top:=0;
Banda.Bottom:=Height;
for contador:=0 to 255 do
begin
Banda.Left:=MulDiv(contador,width,256);
Banda.Right:=MulDIv(contador+1,width,256);
Rojo:=RGBDesde[0]+factor[0]*MulDiv(contador,RGBDif[0],255);
Verde:=RGBDesde[1]+factor[1]*MulDiv(contador,RGBDif[1],255);
Azul:=RGBDesde[2]+factor[2]*MulDiv(contador,RGBDif[2],255);
Canvas.Brush.Color:=RGB(Rojo,Verde,Azul);
Canvas.FillRect(Banda);
end;
end;
end;

procedure Register;
begin
RegisterComponents('Gradient', [TGradient]);
end;
end.
0
Rejoignez-nous