Posted By

icebob on 08/02/10


Tagged

gradient


Versions (?)

Draw a gradient line


 / Published in: Delphi
 

  1. procedure DrawGradientLine(bCanvas: TCanvas; X, Y, Width: integer;
  2. StartColor, EndColor: TColor);
  3. var
  4. fX:integer;
  5. dr,dg,db:Extended;
  6. C1,C2:TColor;
  7. r1,r2,g1,g2,b1,b2:Byte;
  8. R,G,B:Byte;
  9. cnt:integer;
  10. begin
  11. C1 := StartColor;
  12. R1 := GetRValue(C1) ;
  13. G1 := GetGValue(C1) ;
  14. B1 := GetBValue(C1) ;
  15.  
  16. C2 := EndColor;
  17. R2 := GetRValue(C2) ;
  18. G2 := GetGValue(C2) ;
  19. B2 := GetBValue(C2) ;
  20.  
  21. dr := (R2-R1) / Width;
  22. dg := (G2-G1) / Width;
  23. db := (B2-B1) / Width;
  24.  
  25. cnt := 0;
  26. for fX := X to X + Width - 1 do
  27. begin
  28. R := R1+Ceil(dr*cnt) ;
  29. G := G1+Ceil(dg*cnt) ;
  30. B := B1+Ceil(db*cnt) ;
  31.  
  32. bCanvas.Pixels[fX, Y] := RGB(R,G,B);
  33. inc(cnt) ;
  34. end;
  35. end;

Report this snippet  

You need to login to post a comment.