this slowpoke moves

Draw a Gradient Quader

function ColorBetween(C1, C2 : TColor; blend:Real):TColor;
var
   r, g, b : Byte;

   y1, y2 : Byte;
begin
   C1 := ColorToRGB(C1);
   C2 := ColorToRGB(C2);

   y1 := GetRValue(C1);
   y2 := GetRValue(C2);

   r := Round(y1 + (y2-y1)*blend);

   y1 := GetGValue(C1);
   y2 := GetGValue(C2);

   g := Round(y1 + (y2-y1)*blend);

   y1 := GetBValue(C1);
   y2 := GetBValue(C2);

   b := Round(y1 + (y2-y1)*blend);
   Result := RGB(r, g, b);
end;

// Farbe zwischen beliebig vielen vorgegebenen Farbwerten berechnen
function ColorsBetween(colors:array of TColor; blend:Real):TColor;
var
   a : Integer;
   faktor : Real;
begin
   if Length(colors) < 2 then
      raise Exception.Create('ColorsBetween() at least 2 Colors required');

   if blend <= 0.0 then
      Result := colors[0]
   else if blend >= 1.0 then
      Result := colors[High(colors)]
   else
   begin
      a := Trunc(High(colors) * blend);
      faktor := 1.0 / High(colors);

      Result := ColorBetween(colors[a], colors[a+1], (blend-(a * faktor)) / faktor);
   end;
end;
Beispiel :
procedure TForm1.TrackBar1Change(Sender: TObject);
var
   radius, r : Integer;
   rt : TRect;
begin
   radius := 100;
   for r := radius downto 1 do
   begin
      rt := Rect(-r, -r, r, r);
      OffsetRect(rt, 400, 200);
      Canvas.Pen.Color := ColorsBetween([clBlack, clRed, clYellow], r / radius);
      Canvas.Polygon([Point(rt.left, rt.top), Point(rt.right, rt.top), Point(rt.right, rt.Bottom), Point(rt.left, rt.bottom)]);
   end;
end;

Keine Kommentare:

Kommentar veröffentlichen

Beliebte Posts

Translate