fLineStippling.pas 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. unit fLineStippling;
  2. (* ***** BEGIN LICENSE BLOCK *****
  3. * Version: MPL 1.1 or LGPL 2.1 with linking exception
  4. *
  5. * The contents of this file are subject to the Mozilla Public License Version
  6. * 1.1 (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. * http://www.mozilla.org/MPL/
  9. *
  10. * Software distributed under the License is distributed on an "AS IS" basis,
  11. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  12. * for the specific language governing rights and limitations under the
  13. * License.
  14. *
  15. * Alternatively, the contents of this file may be used under the terms of the
  16. * Free Pascal modified version of the GNU Lesser General Public License
  17. * Version 2.1 (the "FPC modified LGPL License"), in which case the provisions
  18. * of this license are applicable instead of those above.
  19. * Please see the file LICENSE.txt for additional information concerning this
  20. * license.
  21. *
  22. * The Original Code is Line Stippling Example
  23. *
  24. * The Initial Developer of the Original Code is
  25. * Alex A. Denisov
  26. *
  27. * Portions created by the Initial Developer are Copyright (C) 2000-2005
  28. * the Initial Developer. All Rights Reserved.
  29. *
  30. * Contributor(s):
  31. *
  32. * ***** END LICENSE BLOCK ***** *)
  33. interface
  34. {$I GR32.inc}
  35. uses
  36. {$IFDEF FPC} LCLIntf, LResources, {$ENDIF}
  37. SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, GR32,
  38. GR32_Image;
  39. type
  40. TFormLineStippling = class(TForm)
  41. Image: TImage32;
  42. ScrollBar: TScrollBar;
  43. procedure FormCreate(Sender: TObject);
  44. procedure ScrollBarChange(Sender: TObject);
  45. public
  46. procedure Spiral(X, Y: Integer);
  47. end;
  48. var
  49. FormLineStippling: TFormLineStippling;
  50. implementation
  51. {$IFDEF FPC}
  52. {$R *.lfm}
  53. {$ELSE}
  54. {$R *.dfm}
  55. {$ENDIF}
  56. uses
  57. GR32_Gamma, GR32_Math;
  58. { TFormLineStippling }
  59. procedure TFormLineStippling.FormCreate(Sender: TObject);
  60. begin
  61. Image.SetupBitmap;
  62. ScrollBarChange(Sender);
  63. end;
  64. procedure TFormLineStippling.ScrollBarChange(Sender: TObject);
  65. var
  66. Step: Single;
  67. begin
  68. Step := ScrollBar.Position * 0.01;
  69. with Image.Bitmap do
  70. begin
  71. BeginUpdate;
  72. Clear(clBlack32);
  73. SetStipple([clWhite32, clWhite32, clWhite32, clWhite32, 0, 0, 0, 0]);
  74. StippleStep := Step;
  75. Spiral(50, 50);
  76. SetStipple([clWhite32, $00FFFFFF]);
  77. Spiral(150, 50);
  78. SetStipple([clWhite32, clRed32, clGreen32, 0, 0, 0]);
  79. Spiral(50, 150);
  80. SetStipple([clGreen32, clGreen32, clGreen32, 0, 0, clWhite32, 0, 0]);
  81. Spiral(150, 150);
  82. EndUpdate;
  83. end;
  84. Image.Repaint;
  85. end;
  86. procedure TFormLineStippling.Spiral(X, Y: Integer);
  87. var
  88. Theta: TFloat;
  89. Sn, Cn: TFloat;
  90. begin
  91. Theta := 0;
  92. Image.Bitmap.MoveToF(X, Y);
  93. while Theta < 15 * Pi do
  94. begin
  95. SinCos(Theta, Sn, Cn);
  96. Image.Bitmap.LineToFSP(X + Cn * Theta, Y + Sn * Theta);
  97. Theta := Theta + 0.2;
  98. end;
  99. end;
  100. end.