Loading...
Searching...
No Matches
circle.c File Reference
`#include "arc/graphics/circle.h"`
`#include "renderer.h"`
`#include <stdlib.h>`

Go to the source code of this file.

## Functions

void | ARC_Circle_Render (ARC_Circle *circle, ARC_Renderer *renderer, ARC_Color *color)
void | ARC_Circle_RenderFill (ARC_Circle *circle, ARC_Renderer *renderer, ARC_Color *color)

## Function Documentation

## ARC_Circle_Render()

void ARC_Circle_Render | ( | ARC_Circle * | circle,
|  | ARC_Renderer * | renderer,
|  | ARC_Color * | color )

Definition at line 6 of file circle.c.

{
SDL_SetRenderDrawColor((SDL_Renderer *)renderer, color->r, color->g, color->b, color->a);
int32_t diameter = (circle->r * 2);
int32_t x = (circle->r - 1);
int32_t y = 0;
int32_t tx = 1;
int32_t ty = 1;
int32_t error = (tx - diameter);
while(x >= y){
// Each of the following renders an octant of the circle
SDL_RenderDrawPoint((SDL_Renderer *)renderer, circle->x + x, circle->y - y);
SDL_RenderDrawPoint((SDL_Renderer *)renderer, circle->x + x, circle->y + y);
SDL_RenderDrawPoint((SDL_Renderer *)renderer, circle->x - x, circle->y - y);
SDL_RenderDrawPoint((SDL_Renderer *)renderer, circle->x - x, circle->y + y);
SDL_RenderDrawPoint((SDL_Renderer *)renderer, circle->x + y, circle->y - x);
SDL_RenderDrawPoint((SDL_Renderer *)renderer, circle->x + y, circle->y + x);
SDL_RenderDrawPoint((SDL_Renderer *)renderer, circle->x - y, circle->y - x);
SDL_RenderDrawPoint((SDL_Renderer *)renderer, circle->x - y, circle->y + x);
if(error <= 0){
++y;
error += ty;
ty += 2;
}
if(error > 0){
--x;
tx += 2;
error += (tx - diameter);
}
}
}
ARC_Circle::x
int32_t x
Definition circle.h:11
ARC_Circle::y
int32_t y
Definition circle.h:12
ARC_Circle::r
int32_t r
Definition circle.h:13
ARC_Color::a
uint8_t a
Definition color.h:11
ARC_Color::r
uint8_t r
Definition color.h:11
ARC_Color::b
uint8_t b
Definition color.h:11
ARC_Color::g
uint8_t g
Definition color.h:11

References ARC_Color::a, ARC_Color::b, ARC_Color::g, ARC_Circle::r, ARC_Color::r, ARC_Circle::x, and ARC_Circle::y.

Referenced by ARC_Circle_RenderFill().

## ARC_Circle_RenderFill()

void ARC_Circle_RenderFill | ( | ARC_Circle * | circle,
|  | ARC_Renderer * | renderer,
|  | ARC_Color * | color )

Definition at line 43 of file circle.c.

{
ARC_Circle temp = *circle;
for(; temp.r; temp.r--){
ARC_Circle_Render(&temp, renderer, color);
}
}
ARC_Circle_Render
void ARC_Circle_Render(ARC_Circle *circle, ARC_Renderer *renderer, ARC_Color *color)
Definition circle.c:6
ARC_Circle
Definition circle.h:10

References ARC_Circle_Render(), and ARC_Circle::r.