Recent

Author Topic: [Solved] TBGRAGradientScanner and Arc  (Read 3506 times)

Gintas

  • Jr. Member
  • **
  • Posts: 71
    • Developer's Diary
[Solved] TBGRAGradientScanner and Arc
« on: May 23, 2012, 09:23:24 pm »
I want to use same gradient for each round arc I draw on Bitmap.Canvas2D. I am trying to position gradient
using those two PointF variables.
I am only getting good gradient just on a few arcs. So how to draw same gradient using a arc coordinates and size?

The result image is here:
http://dl.dropbox.com/u/17084229/Code/RadialGradient.png

Code: [Select]
function TAddBox.MakeGradient(gstyle:Integer;StartC,EndC:TColor;Alpha:byte;Size:Integer;X,Y:Integer;sn:boolean):TBGRAGradientScanner;
begin

  {

  Radial #1
  Radial #2
  Radial #3
  Horizontal
  Vertical
  Vertical Line
  Horizontal Line
  Vertical #2
  Diagonal #1
  Diagonal #2
  Reflected #1
  Reflected #2
  Reflected #3
  Reflected #4
  }

      case gstyle of

      //Radial gradients
      0:Result:=TBGRAGradientScanner.Create(ColorToBGRA(StartC,Alpha),ColorToBGRA(EndC,Alpha),gtRadial,PointF(X,Y),PointF(Round(X div 2),0),true,sn);
      1:Result:=TBGRAGradientScanner.Create(ColorToBGRA(StartC,Alpha),ColorToBGRA(EndC,Alpha),gtRadial,PointF(0,Y),PointF(X,0),true,sn);
      2:Result:=TBGRAGradientScanner.Create(ColorToBGRA(StartC,Alpha),ColorToBGRA(EndC,Alpha),gtRadial,PointF(X,0),PointF(0,0),true,sn);
      //Linear gradients
      3:Result:=TBGRAGradientScanner.Create(ColorToBGRA(StartC,Alpha),ColorToBGRA(EndC,Alpha),gtLinear,PointF(X,Y),PointF(Y,0),true,sn);
      4:Result:=TBGRAGradientScanner.Create(ColorToBGRA(StartC,Alpha),ColorToBGRA(EndC,Alpha),gtLinear,PointF(X,Y),PointF(0,Y),true,sn);
      5:Result:=TBGRAGradientScanner.Create(ColorToBGRA(StartC,Alpha),ColorToBGRA(EndC,Alpha),gtReflected,PointF(X,0),PointF(0,X),true,sn);
      6:Result:=TBGRAGradientScanner.Create(ColorToBGRA(StartC,Alpha),ColorToBGRA(EndC,Alpha),gtReflected,PointF(0,Y),PointF(0,X),true,sn);
      7:Result:=TBGRAGradientScanner.Create(ColorToBGRA(StartC,Alpha),ColorToBGRA(EndC,Alpha),gtLinear,PointF(Y,0),PointF(X,0),true,sn);
      //Diagonal gradients
      8:Result:=TBGRAGradientScanner.Create(ColorToBGRA(StartC,Alpha),ColorToBGRA(EndC,Alpha),gtDiamond,PointF(X,Y),PointF(0,Y),true,sn);
      9:Result:=TBGRAGradientScanner.Create(ColorToBGRA(StartC,Alpha),ColorToBGRA(EndC,Alpha),gtDiamond,PointF(X,Y),PointF(X,0),true,sn);

     10:Result:=TBGRAGradientScanner.Create(ColorToBGRA(StartC,Alpha),ColorToBGRA(EndC,Alpha),gtReflected,PointF(X,0),PointF(0,Y),true,sn);
     11:Result:=TBGRAGradientScanner.Create(ColorToBGRA(StartC,Alpha),ColorToBGRA(EndC,Alpha),gtReflected,PointF(0,X),PointF(X,0),true,sn);
     12:Result:=TBGRAGradientScanner.Create(ColorToBGRA(StartC,Alpha),ColorToBGRA(EndC,Alpha),gtReflected,PointF(Y,X),PointF(X+(Size div 3),Y),true,sn);
     13:Result:=TBGRAGradientScanner.Create(ColorToBGRA(StartC,Alpha),ColorToBGRA(EndC,Alpha),gtReflected,PointF(X,0),PointF(X,0),true,sn);



      end;

end;   
                 
« Last Edit: June 11, 2012, 12:36:52 pm by Gintas »

circular

  • Hero Member
  • *****
  • Posts: 3440
    • Personal webpage
Re: TBGRAGradientScanner and Arc
« Reply #1 on: May 24, 2012, 03:11:09 pm »
If you want to have a radial gradient that has the same size as a circle of center (x,y) and radius (r), you need to define one pointf(x,y) and another pointf(x+r,y) for example.
Conscience is the debugger of the mind

Gintas

  • Jr. Member
  • **
  • Posts: 71
    • Developer's Diary
Re: [Solved] TBGRAGradientScanner and Arc
« Reply #2 on: June 11, 2012, 12:37:43 pm »
Thanks,I calculated the right points for other gradient types too.

 

TinyPortal © 2005-2018