Created
May 6, 2022 12:40
-
-
Save alexmaryin/4771083c83fcf1b8bc8458800d3a2ccd to your computer and use it in GitHub Desktop.
Starfield Pascal Circle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
unit SDL_DrawCircles; | |
{$mode objfpc}{$H+} | |
interface | |
uses | |
Classes, SysUtils, sdl2, ctypes; | |
function SDL_RenderFillCircle(renderer: PSDL_Renderer; x: cint32; | |
y: cint32; radius: cint32): cint32; | |
implementation | |
function SDL_RenderFillCircle(renderer: PSDL_Renderer; x: cint32; | |
y: cint32; radius: cint32): cint32; | |
var | |
offsetX, offsetY, d, status: integer; | |
begin | |
offsetX := 0; | |
offsetY := radius; | |
d := radius - 1; | |
status := 0; | |
while offsetY >= offsetX do | |
begin | |
status += SDL_RenderDrawLine(renderer, x - offsety, y + offsetx, x + offsety, y + offsetx); | |
status += SDL_RenderDrawLine(renderer, x - offsetx, y + offsety, x + offsetx, y + offsety); | |
status += SDL_RenderDrawLine(renderer, x - offsetx, y - offsety, x + offsetx, y - offsety); | |
status += SDL_RenderDrawLine(renderer, x - offsety, y - offsetx, x + offsety, y - offsetx); | |
if status > 0 then | |
begin | |
Result := -1; | |
exit; | |
end; | |
if d >= 2 * offsetx then | |
begin | |
d -= 2 * offsetx + 1; | |
offsetx += 1; | |
end | |
else if d < 2 * (radius - offsety) then | |
begin | |
d += 2 * offsety - 1; | |
offsety -= 1; | |
end | |
else | |
begin | |
d += 2 * (offsety - offsetx - 1); | |
offsety -= 1; | |
offsetx += 1; | |
end; | |
end; | |
Result := status; | |
end; | |
end. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment