Graphics in C

To create graphics in C, you can use libraries such as the Simple DirectMedia Layer (SDL), OpenGL, or the Graphics Device Interface (GDI). These libraries provide functions and tools for drawing shapes, rendering images, and handling user input.

Here is an example of how to create a simple graphic using the SDL library:

#include <SDL.h>

int main() {
    SDL_Init(SDL_INIT_VIDEO);
    SDL_Window* window = SDL_CreateWindow("Graphics Example", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 800, 600, SDL_WINDOW_SHOWN);
    SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);

    SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255);
    SDL_RenderClear(renderer);

    SDL_SetRenderDrawColor(renderer, 0, 255, 0, 255);
    SDL_Rect rect = { 100, 100, 200, 200 };
    SDL_RenderFillRect(renderer, &rect);

    SDL_RenderPresent(renderer);

    SDL_Delay(3000);

    SDL_DestroyRenderer(renderer);
    SDL_DestroyWindow(window);
    SDL_Quit();

    return 0;
}

In this example, we first initialize the SDL library and create a window to display our graphic. Then, we create a renderer to draw on the window. We set the color for rendering using SDL_SetRenderDrawColor, and clear the renderer using SDL_RenderClear.

Next, we set a different color and create a rectangle using SDL_Rect. We fill the rectangle with the specified color using SDL_RenderFillRect. Finally, we present the renderer to display the graphic on the window and delay the program for 3 seconds using SDL_Delay.

Remember to link the SDL library when compiling the code. This can be done by adding the appropriate linker flags, such as -lSDL2 for SDL 2.0.

This is just a basic example, and there are many more advanced graphics techniques you can explore using C and different libraries.