this slowpoke moves

Draw Gradient Shapes

procedure CANVAS_DEGRADE_SHAPE(NaCanvas: TCanvas; InsideRect: TRect;
          OuterRect: TRect; InsideColor:Tcolor; OuterColor:Tcolor;
          Forma: TShapeType; X3, Y3: Integer);
          
//

procedure CANVAS_DEGRADE_SHAPE(NaCanvas: TCanvas; InsideRect: TRect;
          OuterRect: TRect; InsideColor:Tcolor; OuterColor:Tcolor;
          Forma: TShapeType; X3, Y3: Integer);

       procedure DesenharForma(_Rect: TRect);
       begin
         Case Forma Of
           stCircle, stEllipse: NaCanvas.Ellipse(_Rect);
           stRectangle, stSquare: NaCanvas.Rectangle(_Rect);
           stRoundRect, stRoundSquare: NaCanvas.RoundRect(_Rect.Left, _Rect.Top, _Rect.Right, _Rect.Bottom, X3, Y3);
         End;
       end;
var
  i: Integer;
  aRect: TRect;
  Arr_StartRGB : Array[0..2] of Byte;
  Arr_DifRGB   : Array[0..2] of integer;
  Arr_CurRGB   : Array[0..2] of Byte;
begin
  Arr_StartRGB[0] := GetRValue( ColorToRGB( InsideColor ) );
  Arr_StartRGB[1] := GetGValue( ColorToRGB( InsideColor ) );
  Arr_StartRGB[2] := GetBValue( ColorToRGB( InsideColor ) );

  Arr_DifRGB[0] := GetRValue( ColorToRGB( OuterColor )) - Arr_StartRGB[0] ;
  Arr_DifRGB[1] := GetgValue( ColorToRGB( OuterColor )) - Arr_StartRGB[1] ;
  Arr_DifRGB[2] := GetbValue( ColorToRGB( OuterColor )) - Arr_StartRGB[2] ;

  With NaCanvas do
  begin
    Brush.Style := bsSolid;
    Pen.Style   := psSolid;
    Pen.Mode    := pmCopy;
    Pen.Width   := 1;
    Pen.Color   := OuterColor;
    Brush.Color := OuterColor;
    DesenharForma(OuterRect);

    for i:= 255 Downto 0 do
    begin
      aRect.Left   := InsideRect.Left   + MulDiv(i, (OuterRect.Left   - InsideRect.Left),   256);
      aRect.right  := InsideRect.Right  + MulDiv(i, (OuterRect.Right  - InsideRect.Right),  256);
      aRect.Top    := InsideRect.Top    + MulDiv(i, (OuterRect.Top    - InsideRect.Top),    256);
      aRect.Bottom := InsideRect.Bottom + MulDiv(i, (OuterRect.Bottom - InsideRect.Bottom), 256);

      Arr_CurRGB[0] := Arr_StartRGB[0] + MulDiv( i, Arr_DifRGB[0] , 255 );
      Arr_CurRGB[1] := Arr_StartRGB[1] + MulDiv( i, Arr_DifRGB[1] , 255 );
      Arr_CurRGB[2] := Arr_StartRGB[2] + MulDiv( i, Arr_DifRGB[2] , 255 );

      Pen.Color   := RGB(Arr_CurRGB[0], Arr_CurRGB[1], Arr_CurRGB[2]);
      Brush.color := Pen.Color;
      DesenharForma(aRect);
    end;
  end;
end;

procedure TForm1.SBRectClick(Sender: TObject);
begin
  CANVAS_DEGRADE_SHAPE(Canvas,
                       classes.Rect(10, 100, 50, 140),
                       classes.Rect(20, 120, 60, 150),
                       clYellow, clRed, stRectangle, 0, 0);

  CANVAS_DEGRADE_SHAPE(Canvas,
                       classes.Rect(20, 300, 150, 400),
                       classes.Rect(60, 240, 230, 300),
                       clYellow, clRed, stRectangle, 0, 0);
end;

procedure TForm1.SBEllipseClick(Sender: TObject);
begin
  CANVAS_DEGRADE_SHAPE(Canvas,
                       classes.Rect(200, 50, 220, 70),
                       classes.Rect(180, 240, 350, 300),
                       clAqua, clNavy, stEllipse, 0, 0);

  CANVAS_DEGRADE_SHAPE(Canvas,
                       classes.Rect(500, 200, 400, 300),
                       classes.Rect(400, 100, 500, 200),
                       clAqua, clNavy, stEllipse, 0, 0);

  CANVAS_DEGRADE_SHAPE(Canvas,
                       classes.Rect(300, 400, 300, 400),
                       classes.Rect(350, 450, 250, 350),
                       clAqua, clNavy, stEllipse, 0, 0);

  CANVAS_DEGRADE_SHAPE(Canvas,
                       classes.Rect(700, 400, 800, 500),
                       classes.Rect(600, 300, 900, 400),
                       clAqua, clNavy, stEllipse, 0, 0);
end;

Keine Kommentare:

Kommentar veröffentlichen

Beliebte Posts

Translate