ellipse.ppi 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1993,97 by the Free Pascal development team.
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. function CalcEllipse(x,y:Integer;XRadius,YRadius:word):Integer;
  12. var aq,bq,xq,yq,abq : Longint;
  13. xp,yp,count : integer;
  14. begin
  15. XRadius:=(XRadius*10000) div XAsp;
  16. YRadius:=(YRadius*10000) div YAsp;
  17. aq :=XRadius * XRadius;
  18. bq :=YRadius * YRadius;
  19. abq:=aq * bq;
  20. yp:=YRadius;
  21. xp:=0;
  22. count:=0;
  23. { Berechnung nach : X^2 / A^2 + Y^2 / B^2 = 1 }
  24. { umgestellt : X^2 * Y^2 * A^2 * B^2 = A^2*B^2 }
  25. { dadurch werden evtuelle Divisionen durch 0 vermieden }
  26. { und Integerarithmetik moeglich }
  27. repeat
  28. PWord(buffermem)[count ]:=x + xp;
  29. PWord(buffermem)[count+1]:=y + yp;
  30. PWord(buffermem)[count+2]:=x - xp;
  31. PWord(buffermem)[count+3]:=y - yp;
  32. xq:=xp * xp; yq:=yp * yp;
  33. if xq * bq + yq * aq >= abq then yp:=yp-1 else xp:=xp+1;
  34. Count:=Count+4;
  35. until yp < 0;
  36. CalcEllipse:=Count;
  37. end;
  38. Procedure _Ellipse(Count:Integer);
  39. const aq:Integer=0;
  40. begin
  41. { Das Zeichnen der Ellipse erfolgt in zwei Schleifen, um systematisch }
  42. { von oben nach unten zu zeichnen und somit ein staendiges Bank- }
  43. { umschalten zu verhindern }
  44. while aq <> count do begin
  45. PutPixel( PWord(buffermem)[aq] ,PWord(buffermem)[aq+3],aktcolor);
  46. PutPixel( PWord(buffermem)[aq+2],PWord(buffermem)[aq+3],aktcolor);
  47. aq:=aq+4;
  48. end;
  49. while aq <> 0 do begin
  50. aq:=aq-4;
  51. PutPixel( PWord(buffermem)[aq] ,PWord(buffermem)[aq+1],aktcolor);
  52. PutPixel( PWord(buffermem)[aq+2],PWord(buffermem)[aq+1],aktcolor);
  53. end;
  54. end;
  55. Procedure Fillellipse(x,y:Integer;XRadius,YRadius:word);
  56. var Count,index:Word;
  57. Count8:Word;
  58. begin
  59. _graphresult:=grOk;
  60. if not isgraphmode then
  61. begin
  62. _graphresult:=grnoinitgraph;
  63. exit;
  64. end;
  65. Count:=CalcEllipse(x,y,XRadius,YRadius);
  66. if Count=0 then exit;
  67. Count8:=Count-8;
  68. index:=0;
  69. while index < count do begin
  70. while (PWord(buffermem)[index+1]=PWord(buffermem)[index+5]) and
  71. (index < count8) do Index:=Index+4;
  72. PatternLine(PWord(buffermem)[index],PWord(buffermem)[index+2],
  73. PWord(buffermem)[index+3]);
  74. Index:=Index+4;
  75. end;
  76. while index > 0 do begin
  77. index:=index-4;
  78. PatternLine(PWord(buffermem)[index],PWord(buffermem)[index+2],
  79. PWord(buffermem)[index+1]);
  80. while (PWord(buffermem)[index+1]=PWord(buffermem)[index-3]) and
  81. (index > 4 ) do Index:=Index-4;
  82. end;
  83. if (aktColor <> aktFillSettings.Color) or (aktFillSettings.Pattern<>1)
  84. then _Ellipse(Count);
  85. end;
  86. procedure Circle(x,y:integer;radius:word);
  87. begin
  88. _graphresult:=grOk;
  89. if not isgraphmode then
  90. begin
  91. _graphresult:=grnoinitgraph;
  92. exit;
  93. end;
  94. _Ellipse(CalcEllipse(x,y,radius,radius));
  95. end;
  96. {
  97. $Log$
  98. Revision 1.1 1998-03-25 11:18:42 root
  99. Initial revision
  100. Revision 1.3 1998/01/26 11:57:54 michael
  101. + Added log at the end
  102. Working file: rtl/dos/ppi/ellipse.ppi
  103. description:
  104. ----------------------------
  105. revision 1.2
  106. date: 1997/12/01 12:21:29; author: michael; state: Exp; lines: +13 -1
  107. + added copyright reference in header.
  108. ----------------------------
  109. revision 1.1
  110. date: 1997/11/27 08:33:51; author: michael; state: Exp;
  111. Initial revision
  112. ----------------------------
  113. revision 1.1.1.1
  114. date: 1997/11/27 08:33:51; author: michael; state: Exp; lines: +0 -0
  115. FPC RTL CVS start
  116. =============================================================================
  117. }