Advertisement
Guest User

Untitled

a guest
Mar 31st, 2015
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.18 KB | None | 0 0
  1. public void MidPoint(int x0, int y0, int a, int b, Color FrontClr)
  2. {
  3. int a2 = a * a;
  4. int b2 = b * b;
  5. int Twoa2 = 2 * a2;
  6. int Twob2 = 2 * b2;
  7. int p;
  8. int x = 0;
  9. int y = b;
  10. int px = 0;
  11. int py = Twoa2 * y;
  12.  
  13.  
  14. DrawPoint(x0 + x, y0 + y, FrontClr);
  15. DrawPoint(x0 - x, y0 + y, FrontClr);
  16. DrawPoint(x0 - x, y0 - y, FrontClr);
  17. DrawPoint(x0 + x, y0 - y, FrontClr);
  18. /* For Region 1 */
  19.  
  20. p =(int) Math.Round(b2 - (a2 * b) + (0.25) * a2);
  21.  
  22. while (px < py)
  23. {
  24. DrawPoint(x0 + x, y0 + y, FrontClr);
  25. DrawPoint(x0 - x, y0 + y, FrontClr);
  26. DrawPoint(x0 - x, y0 - y, FrontClr);
  27. DrawPoint(x0 + x, y0 - y, FrontClr);
  28. x++;
  29. px += Twob2;
  30. if (p < 0)
  31. {
  32. p += b2 + px;
  33. }
  34. else
  35. {
  36. y--;
  37. py -= Twoa2;
  38. p += b2 + px - py;
  39. }
  40.  
  41. }
  42.  
  43.  
  44. /* For Region 2*/
  45.  
  46. p = (int)Math.Round(b2 * (x + 0.5) * (x + 0.5) + a2 * (y - 1) * (y - 1) - a2 * b2);
  47.  
  48. while (y>0)
  49. {
  50. DrawPoint(x0 + x, y0 + y, FrontClr);
  51. DrawPoint(x0 - x, y0 + y, FrontClr);
  52. DrawPoint(x0 - x, y0 - y, FrontClr);
  53. DrawPoint(x0 + x, y0 - y, FrontClr);
  54. y--;
  55. py -= Twoa2;
  56. if (p > 0)
  57. {
  58. p += a2 - py;
  59. }
  60. else
  61. {
  62. x++;
  63. px += Twob2;
  64. p += a2 - py + px;
  65. }
  66.  
  67. }
  68. }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement