DISC.C 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
  12. */
  13. #include "mem.h"
  14. #include "gr.h"
  15. #include "grdef.h"
  16. int gr_disk(fix xc1,fix yc1,fix r1)
  17. {
  18. int p,x, y, xc, yc, r;
  19. r = f2i(r1);
  20. xc = f2i(xc1);
  21. yc = f2i(yc1);
  22. p=3-(r*2);
  23. x=0;
  24. y=r;
  25. // Big clip
  26. if ( (xc+r) < 0 ) return 1;
  27. if ( (xc-r) > WIDTH ) return 1;
  28. if ( (yc+r) < 0 ) return 1;
  29. if ( (yc-r) > HEIGHT ) return 1;
  30. while(x<y)
  31. {
  32. // Draw the first octant
  33. gr_scanline( xc-y, xc+y, yc-x );
  34. gr_scanline( xc-y, xc+y, yc+x );
  35. if (p<0)
  36. p=p+(x<<2)+6;
  37. else {
  38. // Draw the second octant
  39. gr_scanline( xc-x, xc+x, yc-y );
  40. gr_scanline( xc-x, xc+x, yc+y );
  41. p=p+((x-y)<<2)+10;
  42. y--;
  43. }
  44. x++;
  45. }
  46. if(x==y) {
  47. gr_scanline( xc-x, xc+x, yc-y );
  48. gr_scanline( xc-x, xc+x, yc+y );
  49. }
  50. return 0;
  51. }
  52. int gr_udisk(fix xc1,fix yc1,fix r1)
  53. {
  54. int p,x, y, xc, yc, r;
  55. r = f2i(r1);
  56. xc = f2i(xc1);
  57. yc = f2i(yc1);
  58. p=3-(r*2);
  59. x=0;
  60. y=r;
  61. while(x<y)
  62. {
  63. // Draw the first octant
  64. gr_uscanline( xc-y, xc+y, yc-x );
  65. gr_uscanline( xc-y, xc+y, yc+x );
  66. if (p<0)
  67. p=p+(x<<2)+6;
  68. else {
  69. // Draw the second octant
  70. gr_uscanline( xc-x, xc+x, yc-y );
  71. gr_uscanline( xc-x, xc+x, yc+y );
  72. p=p+((x-y)<<2)+10;
  73. y--;
  74. }
  75. x++;
  76. }
  77. if(x==y) {
  78. gr_uscanline( xc-x, xc+x, yc-y );
  79. gr_uscanline( xc-x, xc+x, yc+y );
  80. }
  81. return 0;
  82. }