Skip to content

Instantly share code, notes, and snippets.

@alexmaryin
Created May 6, 2022 12:40
Show Gist options
  • Save alexmaryin/4771083c83fcf1b8bc8458800d3a2ccd to your computer and use it in GitHub Desktop.
Save alexmaryin/4771083c83fcf1b8bc8458800d3a2ccd to your computer and use it in GitHub Desktop.
Starfield Pascal Circle
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