### Bookstore

 Computer Math and Games in Pascal (preview) Lazarus Handbook

### Recent

#### Gintas

• Jr. Member
• Posts: 71
« 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:

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 »

• Hero Member
• Posts: 3440