DISC.C 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*
  2. THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
  3. SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
  4. END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
  5. ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
  6. IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
  7. SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
  8. FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
  9. CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
  10. AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
  11. COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
  12. */
  13. /*
  14. * $Source: f:/miner/source/2d/rcs/disc.c $
  15. * $Revision: 1.5 $
  16. * $Author: john $
  17. * $Date: 1994/11/18 22:50:16 $
  18. *
  19. * Graphical routines for drawing a disk.
  20. *
  21. * $Log: disc.c $
  22. * Revision 1.5 1994/11/18 22:50:16 john
  23. * Changed shorts to ints in parameters.
  24. *
  25. * Revision 1.4 1994/05/06 12:50:12 john
  26. * Added supertransparency; neatend things up; took out warnings.
  27. *
  28. * Revision 1.3 1994/04/22 11:16:04 john
  29. * *** empty log message ***
  30. *
  31. * Revision 1.2 1993/10/15 16:22:24 john
  32. * *** empty log message ***
  33. *
  34. * Revision 1.1 1993/09/08 11:43:24 john
  35. * Initial revision
  36. *
  37. *
  38. */
  39. #include "mem.h"
  40. #include "gr.h"
  41. #include "grdef.h"
  42. int gr_disk(fix xc1,fix yc1,fix r1)
  43. {
  44. int p,x, y, xc, yc, r;
  45. r = f2i(r1);
  46. xc = f2i(xc1);
  47. yc = f2i(yc1);
  48. p=3-(r*2);
  49. x=0;
  50. y=r;
  51. // Big clip
  52. if ( (xc+r) < 0 ) return 1;
  53. if ( (xc-r) > WIDTH ) return 1;
  54. if ( (yc+r) < 0 ) return 1;
  55. if ( (yc-r) > HEIGHT ) return 1;
  56. while(x<y)
  57. {
  58. // Draw the first octant
  59. gr_scanline( xc-y, xc+y, yc-x );
  60. gr_scanline( xc-y, xc+y, yc+x );
  61. if (p<0)
  62. p=p+(x<<2)+6;
  63. else {
  64. // Draw the second octant
  65. gr_scanline( xc-x, xc+x, yc-y );
  66. gr_scanline( xc-x, xc+x, yc+y );
  67. p=p+((x-y)<<2)+10;
  68. y--;
  69. }
  70. x++;
  71. }
  72. if(x==y) {
  73. gr_scanline( xc-x, xc+x, yc-y );
  74. gr_scanline( xc-x, xc+x, yc+y );
  75. }
  76. return 0;
  77. }
  78. int gr_udisk(fix xc1,fix yc1,fix r1)
  79. {
  80. int p,x, y, xc, yc, r;
  81. r = f2i(r1);
  82. xc = f2i(xc1);
  83. yc = f2i(yc1);
  84. p=3-(r*2);
  85. x=0;
  86. y=r;
  87. while(x<y)
  88. {
  89. // Draw the first octant
  90. gr_uscanline( xc-y, xc+y, yc-x );
  91. gr_uscanline( xc-y, xc+y, yc+x );
  92. if (p<0)
  93. p=p+(x<<2)+6;
  94. else {
  95. // Draw the second octant
  96. gr_uscanline( xc-x, xc+x, yc-y );
  97. gr_uscanline( xc-x, xc+x, yc+y );
  98. p=p+((x-y)<<2)+10;
  99. y--;
  100. }
  101. x++;
  102. }
  103. if(x==y) {
  104. gr_uscanline( xc-x, xc+x, yc-y );
  105. gr_uscanline( xc-x, xc+x, yc+y );
  106. }
  107. return 0;
  108. }
  109.