Advertisement
Ulabael

midpointCircle

Sep 23rd, 2022
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. function scrMidpointCircle(xCentre, yCentre, radius){
  2. var arr = [];
  3. var _x = radius, _y = 0;
  4.  
  5. array_push(arr, [_x + xCentre, _y + yCentre]);
  6. if (radius> 0) {
  7. array_push(arr, [_x + xCentre, -_y + yCentre]);
  8. array_push(arr, [_y + xCentre, _x + yCentre]);
  9. array_push(arr, [_y + xCentre, -_x + yCentre]);
  10. array_push(arr, [-_y + xCentre, _x + yCentre]);
  11. array_push(arr, [-_x + xCentre, _y + yCentre]);
  12. }
  13.  
  14. var P = 1 - radius;
  15. while (_x > _y) {
  16. _y++;
  17. if (P <= 0)
  18. P = P + 2 * _y + 1;
  19.  
  20. else {
  21. _x--;
  22. P = P + 2 * _y - 2 * _x + 1;
  23. }
  24.  
  25. if (_x < _y) {
  26. break;
  27. }
  28.  
  29. array_push(arr, [_x + xCentre, _y + yCentre]);
  30. array_push(arr, [-_x + xCentre, _y + yCentre]);
  31. array_push(arr, [_x + xCentre, -_y + yCentre]);
  32. array_push(arr, [-_x + xCentre, -_y + yCentre]);
  33. if (_x != _y) {
  34.  
  35. array_push(arr, [_y + xCentre, _x + yCentre]);
  36. array_push(arr, [-_y + xCentre, _x + yCentre]);
  37. array_push(arr, [_y + xCentre, -_x + yCentre]);
  38. array_push(arr, [-_y + xCentre, -_x + yCentre]);
  39. }
  40. }
  41.  
  42. return arr;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement