Day 87/100 100 Days of Code
Chris Douris
1 min read
I worked on creating the ball. SDL alone can't generate circles. I used the solution from this post to draw it.
Ball structure
struct Ball
{
float x;
float y;
float radius;
};
Generate Ball
void GenerateBall(struct Ball ball, SDL_Renderer *renderer)
{
// Center of ball
SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0xFF, 0xFF);
// Generate center
SDL_RenderPoint(renderer, ball.x, ball.y);
// special thanks
// https://math.stackexchange.com/questions/260096/find-the-coordinates-of-a-point-on-a-circle
// https://www.sanfoundry.com/c-tutorials-various-trigonometric-functions-standard-library/
for (float i = 0; i < 360; i += 1)
{
printf("%f\n", (ball.radius) * cos(i));
SDL_RenderPoint(renderer, (ball.radius * cos(i)) + ball.x, (ball.radius* sin(i)) + ball.y);
}
}
Result
0
Subscribe to my newsletter
Read articles from Chris Douris directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Chris Douris
Chris Douris
AKA Chris, is a software developer from Athens, Greece. He started programming with basic when he was very young. He lost interest in programming during school years but after an unsuccessful career in audio, he decided focus on what he really loves which is technology. He loves working with older languages like C and wants to start programming electronics and microcontrollers because he wants to get into embedded systems programming.