Day 87/100 100 Days of Code

Day 87/100 100 Days of Code

Jumping Ball

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