1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
| #include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <SDL2/SDL.h>
int cercle(SDL_Window *fenetre, int x, int y, int largeur, int hauteur, int R, int V, int B);
int main(int argc, char *argv[]){
SDL_Window *win = NULL;
if(SDL_Init(SDL_INIT_VIDEO) != 0)
printf("error");
if((win = SDL_CreateWindow("Test cercle", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 700, 600, 0)) == NULL)
printf("error");
int i = 0;
while(i<256){
cercle(win, 350, 300, 256-i, 256-i, i, i/6, 255-i);
i += 1;
}
SDL_Delay(4000);
SDL_DestroyWindow(win);
SDL_Quit();
return 0;
}
int cercle(SDL_Window *fenetre, int x, int y, int largeur, int hauteur, int R, int V, int B){
SDL_Renderer *rendu = NULL;
if((rendu = SDL_CreateRenderer(fenetre, -1, SDL_RENDERER_SOFTWARE)) == NULL){
return 0;
}
if((SDL_SetRenderDrawColor(rendu, R, V, B, SDL_ALPHA_OPAQUE)) != 0){
return 0;
}
const double pi = 3.141592;
double angle = pi;
double L, P;
while(angle<2*pi){
L = cos(angle)*largeur;
P = sin(angle)*hauteur;
SDL_RenderDrawLine(rendu, x+L, y+P, x+L, y-P);
angle += 0.004;
}
SDL_RenderPresent(rendu);
SDL_DestroyRenderer(rendu);
} |