#include
#include
const int WINDOW_WIDTH = 640;
const int WINDOW_HEIGHT = 480;
int main(int argc, char *argv[]) {
SDL_Window *window = nullptr;
SDL_Renderer *renderer = nullptr;
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
std::cerr << "SDL could not initialize! SDL_Error: " << SDL_GetError() << std::endl;
return 1;
}
window = SDL_CreateWindow("Circle and Line Example", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
WINDOW_WIDTH, WINDOW_HEIGHT, SDL_WINDOW_SHOWN);
if (window == nullptr) {
std::cerr << "Window could not be created! SDL_Error: " << SDL_GetError() << std::endl;
return 1;
}
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
if (renderer == nullptr) {
std::cerr << "Renderer could not be created! SDL_Error: " << SDL_GetError() << std::endl;
return 1;
}
// Set the background color to white
SDL_SetRenderDrawColor(renderer, 0xff, 0xff, 0xff, 0xff);
SDL_RenderClear(renderer);
// Set the color for the circle to blue
SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0xff, 0xff);
// Draw the circle
int center_x = WINDOW_WIDTH / 2;
int center_y = WINDOW_HEIGHT / 2;
int radius = WINDOW_WIDTH / 4;
for (int i = 0; i < 360; i++) {
int x = center_x + radius * cos(i * M_PI / 180.0);
int y = center_y + radius * sin(i * M_PI / 180.0);
SDL_RenderDrawPoint(renderer, x, y);
}
// Set the color for the line to red
SDL_SetRenderDrawColor(renderer, 0xff, 0x00, 0x00, 0xff);
// Draw the line through the center of the circle
SDL_RenderDrawLine(renderer, 0, center_y, WINDOW_WIDTH, center_y);
// Update the screen
SDL_RenderPresent(renderer);
// Wait for 5 seconds
SDL_Delay(5000);
// Clean up
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
SDL_Quit();
return 0;
}
Эта программа использует библиотеку SDL для создания окна и рендерера, устанавливает цвет фона на белый