请教颜色渐变的算法(100分)

  • 主题发起人 半窍不通
  • 开始时间

半窍不通

Unregistered / Unconfirmed
GUEST, unregistred user!
在离线包找了很久,只见到以下代码及相类似的代码
procedure TForm1.FormPaint(Sender: TObject);
var
I: Word ;
Y,YStep: Real;
begin
Y:=0; // 设置Y方向的初
YStep:=ClientHeight/256; // 设置步长
for I:=255 downto 0 do
begin
Canvas.Brush.Color:=$00000000+i*$10000; // 改变颜色
Canvas.FillRect(Rect(0,Round(Y),ClientWidth,Round(Y+YStep)));
Y:=Y+YStep;
end;
end;

而我使用 linux 时,它的背景色可以选择任意两种颜色,并能实现两种颜色之间的
渐变,请问是如何实现的?

我在 delphi 里任意选择两种颜色,将颜色值代入上面的程序中,但出来的效果是一条条的。:(
 
看我的:
unit rbgrdutils;

interface

uses Windows, Classes, Graphics, Forms, Controls, Dialogs;

type
TGradientFillType=(rgsHorizontal, rgsVertical, rgsElliptic, rgsRectangle, rgsVerticalCenter,
rgsHorizontalCenter, rgsNWSE, rgsNWSW, rgsSENW,rgsSWNE, rgsSweet, rgsStrange, rgsNeo);

procedure RbsGradientFill( Canvas:TCanvas; grdType:TGradientFillType; fromCol:TColor;
toCol:TColor;ARect:TRect);

implementation

procedure RbsGradientFill( Canvas:TCanvas;grdType:TGradientFillType;fromCol:TColor;
toCol:TColor;ARect:TRect);
var
FromR, FromG, FromB : Integer;
DiffR, DiffG, DiffB : Integer;

i: integer;
bm:TBitmap;
ColorRect:TRect;
R,G,B:Byte;

//for elliptical
Pw, Ph : Real;
x0,y0,x1,y1,x2,y2,x3,y3 : Real;
points:array[0..3] of TPoint;
haf:Integer;

begin
//set bitmap
bm:=TBitmap.Create;
bm.Width := ARect.Right;
bm.Height := ARect.Bottom;

//calc colors
FromR := fromcol and $000000ff; //Strip out separate RGB values
FromG := (fromcol shr 8) and $000000ff;
FromB := (fromcol shr 16) and $000000ff;
DiffR := (tocol and $000000ff) - FromR; //Find the difference
DiffG := ((tocol shr 8) and $000000ff) - FromG;
DiffB := ((tocol shr 16) and $000000ff) - FromB;

//draw gradient
case grdType of
rgsHorizontal:
begin
ColorRect.Top:= 0; //Set rectangle top
ColorRect.Bottom := bm.Height;
for I := 0 to 255 do begin //Make lines (rectangles) of color
ColorRect.Left:= MulDiv (I, bm.Width, 256); //Find left for this color
ColorRect.Right:= MulDiv (I + 1, bm.Width, 256); //Find Right
R := fromR + MulDiv(I, diffr, 255); //Find the RGB values
G := fromG + MulDiv(I, diffg, 255);
B := fromB + MulDiv(I, diffb, 255);
bm.Canvas.Brush.Color := RGB(R, G, B); //Plug colors into brush
bm.Canvas.FillRect(ColorRect); //Draw on Bitmap
end;

end;
rgsVertical:
begin
ColorRect.Left:= 0; //Set rectangle left&right
ColorRect.Right:= bm.Width;
for I := 0 to 255 do begin //Make lines (rectangles) of color
ColorRect.Top:= MulDiv (I, bm.Height, 256); //Find top for this color
ColorRect.Bottom:= MulDiv (I + 1, bm.Height, 256); //Find Bottom
R := fromr + MulDiv(I, diffr, 255); //Find the RGB values
G := fromg + MulDiv(I, diffg, 255);
B := fromb + MulDiv(I, diffb, 255);
bm.Canvas.Brush.Color := RGB(R, G, B); //Plug colors into brush
bm.Canvas.FillRect(ColorRect); //Draw on Bitmap
end;

end;
rgsElliptic:
begin
bm.Canvas.Pen.Style := psClear;
bm.Canvas.Pen.Mode := pmCopy;
x1 := 0 - (bm.Width / 4);
x2 := bm.Width + (bm.Width / 4)+4;
y1 := 0 - (bm.Height / 4);
y2 := bm.Height + (bm.Height / 4)+4;
Pw := ((bm.Width / 4) + (bm.Width / 2)) / 155;
Ph := ((bm.Height / 4) + (bm.Height / 2)) / 155;
for I := 0 to 155 do begin //Make ellipses of color
x1 := x1 + Pw;
x2 := X2 - Pw;
y1 := y1 + Ph;
y2 := y2 - Ph;
R := fromr + MulDiv(I, diffr, 155); //Find the RGB values
G := fromg + MulDiv(I, diffg, 155);
B := fromb + MulDiv(I, diffb, 155);
bm.Canvas.Brush.Color := R or (G shl 8) or (b shl 16); //Plug colors into brush
bm.Canvas.Ellipse(Trunc(x1),Trunc(y1),Trunc(x2),Trunc(y2));
end;
end;

rgsRectangle:
begin
bm.Canvas.Pen.Style := psClear;
bm.Canvas.Pen.Mode := pmCopy;
x1 := 0;
x2 := bm.Width+2;
y1 := 0;
y2 := bm.Height+2;
Pw := (bm.Width / 2) / 255;
Ph := (bm.Height / 2) / 255;
for I := 0 to 255 do begin //Make rectangles of color
x1 := x1 + Pw;
x2 := X2 - Pw;
y1 := y1 + Ph;
y2 := y2 - Ph;
R := fromr + MulDiv(I, diffr, 255); //Find the RGB values
G := fromg + MulDiv(I, diffg, 255);
B := fromb + MulDiv(I, diffb, 255);
bm.Canvas.Brush.Color := RGB(R, G, B); //Plug colors into brush
bm.Canvas.FillRect(Rect(Trunc(x1),Trunc(y1),Trunc(x2),Trunc(y2)));
end;
end;

rgsVerticalCenter:
begin
Haf := bm.Height Div 2;
ColorRect.Left := 0;
ColorRect.Right := bm.Width;
for I := 0 to Haf do begin
ColorRect.Top := MulDiv (I, Haf, Haf);
ColorRect.Bottom := MulDiv (I + 1, Haf, Haf);
R := fromr + MulDiv(I, diffr, Haf);
G := fromg + MulDiv(I, diffg, Haf);
B := fromb + MulDiv(I, diffb, Haf);
bm.Canvas.Brush.Color := RGB(R, G, B);
bm.Canvas.FillRect(ColorRect);
ColorRect.Top := bm.Height - (MulDiv (I, Haf, Haf));
ColorRect.Bottom := bm.Height - (MulDiv (I + 1, Haf, Haf));
bm.Canvas.FillRect(ColorRect);
end;

end;
rgsHorizontalCenter:
begin
Haf := bm.Width Div 2;
ColorRect.Top := 0;
ColorRect.Bottom := bm.Height;
for I := 0 to Haf do begin
ColorRect.Left := MulDiv (I, Haf, Haf);
ColorRect.Right := MulDiv (I + 1, Haf, Haf);
R := fromr + MulDiv(I, diffr, Haf);
G := fromg + MulDiv(I, diffg, Haf);
B := fromb + MulDiv(I, diffb, Haf);
bm.Canvas.Brush.Color := RGB(R, G, B);
bm.Canvas.FillRect(ColorRect);
ColorRect.Left := bm.Width - (MulDiv (I, Haf, Haf));
ColorRect.Right := bm.Width - (MulDiv (I + 1, Haf, Haf));
bm.Canvas.FillRect(ColorRect);
end;
end;
rgsNWSE:
begin
bm.canvas.Pen.Style := psclear;
bm.canvas.Pen.Mode := pmCopy;
Pw := (bm.Width+bm.height) / 255;
for I := 0 to 254 do begin //Make trapeziums of color
x0 := i*Pw;
if (x0<bm.width) then y0:=0 else
begin
y0:=x0-bm.width;
x0:=bm.width-1;
end;
x1:=(i+1)*pw;
if (x1<bm.width) then begin
y1:=0;
end
else begin
y1:=x1-bm.width;
x1:=bm.width-1;
end;
y2:=i*pw;
if (y2<bm.height) then x2:=0 else
begin
x2:=y2-bm.height;
y2:=bm.height-1;
end;
y3:=(i+1)*pw;
if (y3<bm.height) then x3:=0 else
begin
x3:=y3-bm.height;
y3:=bm.height-1;
end;
R := fromr + MulDiv(I, diffr, 255); //Find the RGB values
G := fromg + MulDiv(I, diffg, 255);
B := fromb + MulDiv(I, diffb, 255);
bm.canvas.Brush.Color := RGB(R, G, B); //Plug colors into brush
points[0]:=point(Trunc(x0),Trunc(y0));
points[1]:=point(Trunc(x1),Trunc(y1));
points[3]:=point(Trunc(x2),Trunc(y2));
points[2]:=point(Trunc(x3),Trunc(y3));
bm.canvas.polygon(points);
end;
end;

rgsNWSW:
begin
bm.canvas.Pen.Style := psclear;
bm.canvas.Pen.Mode := pmCopy;
Pw := (bm.width+bm.height) / 255;
for I := 0 to 254 do begin //Make trapeziums of color
y0 := i*Pw;
if (y0<bm.height) then x0:=bm.width-1 else
begin
x0:=bm.width-1-(y0-bm.height);
y0:=bm.height-1;
end;
y1:=(i+1)*pw;
if (y1<bm.height) then x1:=bm.width-1 else
begin
x1:=bm.width-1;
end;
x2:=bm.width-1-(i*pw);
if (x2>0) then y2:=0 else
begin
y2:=-x2;
x2:=0;
end;
x3:=bm.width-1-((i+1)*pw);
if (x3>0) then y3:=0 else
begin
y3:=-x3;
x3:=0;
end;
R := fromr + MulDiv(I, diffr, 255); //Find the RGB values
G := fromg + MulDiv(I, diffg, 255);
B := fromb + MulDiv(I, diffb, 255);
bm.canvas.Brush.Color := RGB(R, G, B); //Plug colors into brush
points[0]:=point(Trunc(x0),Trunc(y0));
points[1]:=point(Trunc(x1),Trunc(y1));
points[3]:=point(Trunc(x2),Trunc(y2));
points[2]:=point(Trunc(x3),Trunc(y3));
bm.canvas.polygon(points);
end;
end;

rgsSENW:
begin
bm.canvas.Pen.Style := psclear;
bm.canvas.Pen.Mode := pmCopy;
Pw := (bm.width+bm.height) / 255;
for I := 0 to 254 do begin //Make trapeziums of color
y0 := bm.height-1-(i*Pw);
if (y0>0) then x0:=bm.width-1 else
begin
x0:=bm.width-1+y0;
y0:=0;
end;
y1:=bm.height-1-((i+1)*pw);
if (y1>0) then x1:=bm.width-1 else
begin
x1:=bm.width-1+y1;
y1:=0;
end;
x2:=bm.width-1-(i*pw);
if (x2>0) then y2:=bm.height-1 else
begin
y2:=bm.height-1+x2;
x2:=0;
end;
x3:=bm.width-1-((i+1)*pw);
if (x3>0) then y3:=bm.height-1 else
begin
y3:=bm.height-1+x3;
x3:=0;
end;
R := fromr + MulDiv(I, diffr, 255); //Find the RGB values
G := fromg + MulDiv(I, diffg, 255);
B := fromb + MulDiv(I, diffb, 255);
bm.canvas.Brush.Color := RGB(R, G, B); //Plug colors into brush
points[0]:=point(Trunc(x0),Trunc(y0));
points[1]:=point(Trunc(x1),Trunc(y1));
points[3]:=point(Trunc(x2),Trunc(y2));
points[2]:=point(Trunc(x3),Trunc(y3));
bm.canvas.polygon(points);
end;
end;

rgsSWNE:
begin
bm.canvas.Pen.Style := psclear;
bm.canvas.Pen.Mode := pmCopy;
Pw := (bm.width+bm.height) / 255;
for I := 0 to 254 do begin //Make trapeziums of color
y0 := bm.height-1-(i*Pw);
if (y0>0) then x0:=0 else
begin
x0:=-y0;
y0:=0;
end;
y1:=bm.height-1-((i+1)*pw);
if (y1>0) then x1:=0 else
begin
x1:=-y1;
y1:=0;
end;
x2:=(i*pw);
if (x2<bm.width) then y2:=bm.height-1 else
begin
y2:=bm.height-1-(x2-bm.width);
x2:=bm.width-1;
end;
x3:=(i+1)*pw;
if (x3<bm.width) then y3:=bm.height-1 else
begin
y3:=bm.height-1-(x3-bm.width);
x3:=bm.width-1;
end;
R := fromr + MulDiv(I, diffr, 255); //Find the RGB values
G := fromg + MulDiv(I, diffg, 255);
B := fromb + MulDiv(I, diffb, 255);
bm.canvas.Brush.Color := RGB(R, G, B); //Plug colors into brush
points[0]:=point(Trunc(x0),Trunc(y0));
points[1]:=point(Trunc(x1),Trunc(y1));
points[3]:=point(Trunc(x2),Trunc(y2));
points[2]:=point(Trunc(x3),Trunc(y3));
bm.canvas.polygon(points);
end;
end;

rgssweet:
begin
bm.canvas.Pen.Style := psclear;
bm.canvas.Pen.Mode := pmCopy;
for i:=0 to 255 do
begin
x1:=muldiv(i,bm.Width,255);
x2:=muldiv(i+1,bm.Width,255);
y1:=muldiv(i,bm.Height,255);
y2:=muldiv(i+1,bm.Height,255);

R := fromr + MulDiv(I, diffr, 255); //Find the RGB values
G := fromg + MulDiv(I, diffg, 255);
B := fromb + MulDiv(I, diffb, 255);

bm.Canvas.Brush.Color:=RGB(R,G,B);

points[0]:=point(bm.Width div 2,bm.Height div 2);
points[1]:=point(0,trunc(y1));
points[2]:=point(0,trunc(y2));
points[3]:=points[2];
bm.canvas.polygon(points);

points[0]:=point(bm.Width div 2,bm.Height div 2);
points[1]:=point(bm.Width,bm.Height-trunc(y1));
points[2]:=point(bm.Width,bm.Height-trunc(y2));
points[3]:=points[2];
bm.canvas.polygon(points);

points[0]:=point(bm.Width div 2,bm.Height div 2);
points[1]:=point(trunc(x1),0);
points[2]:=point(trunc(x2),0);
points[3]:=points[2];
bm.canvas.polygon(points);

points[0]:=point(bm.Width div 2,bm.Height div 2);
points[1]:=point(bm.Width-trunc(x1),bm.Height);
points[2]:=point(bm.Width-trunc(x2),bm.Height);
points[3]:=points[2];
bm.canvas.polygon(points);
end;
end;

rgsStrange:
begin
bm.canvas.Pen.Style := psclear;
bm.canvas.Pen.Mode := pmCopy;
for i:=0 to 255 do
begin
x1:=muldiv(i,bm.Width,255);
y1:=muldiv(i,bm.Height,255);

R := fromr + MulDiv(I, diffr, 255); //Find the RGB values
G := fromg + MulDiv(I, diffg, 255);
B := fromb + MulDiv(I, diffb, 255);

bm.Canvas.Brush.Color:=RGB(R,G,B);

points[0]:=point(trunc(x1),trunc(y1));
points[1]:=point(0,bm.Height-trunc(y1));
points[2]:=point(bm.Width,bm.Height);
points[3]:=point(bm.width,0);
bm.canvas.polygon(points);
end;
end;

rgsNeo:
begin
bm.canvas.Pen.Style := psclear;
bm.canvas.Pen.Mode := pmCopy;
for i:=0 to 255 do
begin
x1:=muldiv(i,bm.Width div 2,255);
y1:=muldiv(i,bm.Height div 2,255);

R := fromr + MulDiv(I, diffr, 255); //Find the RGB values
G := fromg + MulDiv(I, diffg, 255);
B := fromb + MulDiv(I, diffb, 255);

bm.Canvas.Brush.Color:=RGB(R,G,B);

points[0]:=point(trunc(x1),trunc(y1));
points[1]:=point(0,bm.Height);
points[2]:=point(bm.Width-trunc(x1),bm.Height-trunc(y1));
points[3]:=point(bm.width,0);
bm.canvas.polygon(points);
end;

end;
end;
BitBlt(Canvas.Handle,0,0,bm.Width,bm.Height,bm.Canvas.Handle,0,0,SRCCOPY);
//Canvas.CopyRect(arect,bm.Canvas,arect);
bm.Free;
end;


end.
 
这是云彩效果,看看
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
procedure FormPaint(Sender: TObject);

procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure PaintRainbow(Dc : hDc; {Canvas to paint to}
x : integer; {Start position X}
y : integer; {Start position Y}
Width : integer; {Width of the rainbow}
Height : integer {Height of the rainbow};
bVertical : bool; {Paint verticallty}
WrapToRed : bool);
procedure Button1Click(Sender: TObject);
procedure FormResize(Sender: TObject); {Wrap spectrum back to red}

private
{ Private declarations }
public

function ColorAtRainbowPoint(ColorPlace : integer;
RainbowWidth : integer;
WrapToRed : bool) : TColorref;
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormPaint(Sender: TObject);
begin
PaintRainbow(Form1.Canvas.Handle,
0,
0,
Form1.ClientWidth,
Form1.ClientHeight,
false,
true);

end;



procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
Color : TColorRef;
begin
Color :=canvas.Pixels[x,y];// ColorAtRainbowPoint(y,Form1.ClientWidth,true);
ShowMessage(IntToStr(GetRValue(Color)) + #32 +IntToStr(GetGValue(Color)) + #32 +
IntToStr(GetBValue(Color)));
end;


procedure TForm1.PaintRainbow(Dc: hDc; x, y, Width, Height: integer;
bVertical, WrapToRed: bool);
var
i : integer;
ColorChunk : integer;
OldBrush : hBrush;
OldPen : hPen;
r : integer;
g : integer;
b : integer;
Chunks : integer;
ChunksMinus1 : integer;
pt : TPoint;
begin
OffsetViewportOrgEx(Dc,x,y,pt);

if WrapToRed = false then
Chunks := 5
else
Chunks := 6;
ChunksMinus1 := Chunks - 1;
if bVertical = false then
ColorChunk := Width div Chunks else
ColorChunk := Height div Chunks;

{Red To Yellow}
r := 255;
b := 0;
for i := 0 to ColorChunk do
begin
g:= (255 div ColorChunk) * i;
OldBrush := SelectObject(Dc, CreateSolidBrush(Rgb(r, g, b)));
if bVertical = false then
PatBlt(Dc, i, 0, 1, Height, PatCopy) else
PatBlt(Dc, 0, i, Width, 1, PatCopy);
DeleteObject(SelectObject(Dc, OldBrush));
end;

{Yellow To Green}
g:=255;
b:=0;
for i := ColorChunk to (ColorChunk * 2) do
begin
r := 255 - (255 div ColorChunk) * (i - ColorChunk);
OldBrush := SelectObject(Dc, CreateSolidBrush(Rgb(r, g, b)));
if bVertical = false then
PatBlt(Dc, i, 0, 1, Height, PatCopy) else
PatBlt(Dc, 0, i, Width, 1, PatCopy);
DeleteObject(SelectObject(Dc, OldBrush));
end;

{Green To Cyan}
r:=0;
g:=255;
for i:= (ColorChunk * 2) to (ColorChunk * 3) do
begin
b := (255 div ColorChunk)*(i - ColorChunk * 2);
OldBrush := SelectObject(Dc, CreateSolidBrush(Rgb(r, g, b)));
if bVertical = false then
PatBlt(Dc, i, 0, 1, Height, PatCopy) else
PatBlt(Dc, 0, i, Width, 1, PatCopy);
DeleteObject(SelectObject(Dc,OldBrush));
end;

{Cyan To Blue}
r := 0;
b := 255;
for i:= (ColorChunk * 3) to (ColorChunk * 4) do
begin
g := 255 - ((255 div ColorChunk) * (i - ColorChunk * 3));
OldBrush := SelectObject(Dc, CreateSolidBrush(Rgb(r, g, b)));
if bVertical = false then
PatBlt(Dc, i, 0, 1, Height, PatCopy) else
PatBlt(Dc, 0, i, Width, 1, PatCopy);
DeleteObject(SelectObject(Dc, OldBrush));
end;

{Blue To Magenta}
g := 0;
b := 255;
for i:= (ColorChunk * 4) to (ColorChunk * 5) do
begin
r := (255 div ColorChunk) * (i - ColorChunk * 4);
OldBrush := SelectObject(Dc, CreateSolidBrush(Rgb(r, g, b)));
if bVertical = false then
PatBlt(Dc, i, 0, 1, Height, PatCopy) else
PatBlt(Dc, 0, i, Width, 1, PatCopy);
DeleteObject(SelectObject(Dc, OldBrush))
end;

if WrapToRed <> false then begin
{Magenta To Red}
r := 255;
g := 0;
for i := (ColorChunk * 5) to ((ColorChunk * 6) - 1) do
begin
b := 255 -((255 div ColorChunk) * (i - ColorChunk * 5));
OldBrush := SelectObject(Dc, CreateSolidBrush(Rgb(r,g,b)));
if bVertical = false then
PatBlt(Dc, i, 0, 1, Height, PatCopy) else
PatBlt(Dc, 0, i, Width, 1, PatCopy);
DeleteObject(SelectObject(Dc,OldBrush));
end;
end;

{Fill Remainder}
if (Width - (ColorChunk * Chunks) - 1 ) > 0 then
begin
if WrapToRed <> false then
begin
r := 255;
g := 0;
b := 0;
end else begin
r := 255;
g := 0;
b := 255;
end;
OldBrush := SelectObject(Dc, CreateSolidBrush(Rgb(r, g, b)));
if bVertical = false then
PatBlt(Dc,ColorChunk * Chunks,0,Width - (ColorChunk * Chunks),Height,PatCopy)
else
PatBlt(Dc,0,ColorChunk * Chunks,Width,Height - (ColorChunk * Chunks),PatCopy);
DeleteObject(SelectObject(Dc,OldBrush));
end;
OffsetViewportOrgEx(Dc,Pt.x,Pt.y,pt);
end;

////&amp;AElig;&amp;auml;&amp;Ecirc;&amp;micro;&amp;frac34;&amp;Iacute;&amp;Ecirc;&amp;Ccedil;&amp;raquo;&amp;ntilde;&amp;Egrave;&amp;iexcl;&amp;Auml;&amp;sup3;&amp;micro;&amp;atilde;&amp;micro;&amp;Auml;&amp;Ntilde;&amp;Otilde;&amp;Eacute;&amp;laquo;&amp;Ouml;&amp;micro;&amp;Oacute;&amp;Atilde;pixels[x,y]&amp;acute;ú&amp;Igrave;&amp;aelig;&amp;frac34;&amp;Iacute;&amp;iquest;&amp;Eacute;&amp;Ograve;&amp;Ocirc;
function TForm1.ColorAtRainbowPoint(ColorPlace, RainbowWidth: integer;
WrapToRed: bool): TColorRef;
var
ColorChunk : integer;
ColorChunkIndex : integer;
ColorChunkStart : integer;
begin
if ColorPlace = 0 then begin
result := RGB(255, 0, 0);
exit;
end;
{WhatChunk}
if WrapToRed <> false then
ColorChunk := RainbowWidth div 6 else
ColorChunk := RainbowWidth div 5;
ColorChunkStart := ColorPlace div ColorChunk;
ColorChunkIndex := ColorPlace mod ColorChunk;
case ColorChunkStart of
0 : result := RGB(255,(255 div ColorChunk) * ColorChunkIndex,0);
1 : result := RGB(255 - (255 div ColorChunk) * ColorChunkIndex,255,0);
2 : result := RGB(0, 255, (255 div ColorChunk) * ColorChunkIndex);
3 : result := RGB(0,255 - (255 div ColorChunk) * ColorChunkIndex,255);
4 : result := RGB((255 div ColorChunk) * ColorChunkIndex,0,255);
5 : result := RGB(255,0,255 - (255 div ColorChunk) * ColorChunkIndex);
else
if WrapToRed <> false then
result := RGB(255, 0, 0) else
result := RGB(255, 0, 255);
end;{Case}
end;


procedure TForm1.Button1Click(Sender: TObject);
begin
PaintRainbow(Form1.Canvas.Handle,0,0,Form1.ClientWidth,Form1.ClientHeight,false,true);
end;

procedure TForm1.FormResize(Sender: TObject);
begin
button1click(sender);
end;

end.
 
:)

吓我一跳,这么复杂的,仔细看后才知道可以搞成十三种效果,谢谢 toli 兄;

huazai 兄虽然也贴出完整的源码,但使用了第三方的控件,我并未安装过这个控件,
所以程序不能编译,但也谢谢啦
 
顶部