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
|
int main( int argc, char** args )
{
SDL_Init(SDL_INIT_EVERYTHING); //Initializing SDL2
window = SDL_CreateWindow( "Koch Fractal", SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED, SCR_W, SCR_H, SDL_WINDOW_SHOWN ); //Creating window
renderer = SDL_CreateRenderer( window, -1, SDL_RENDERER_ACCELERATED ); //Creating renderer
SDL_SetRenderDrawColor(renderer,0,0,0,255); //Setting default screen color
//Horizontal line
//lines.push_back( new Line(SCR_W-10,SCR_H/2.0, SCR_W-20,180.0) );
//Vertical line
//lines.push_back( new Line(SCR_W/1.5,10, SCR_H-20,90.0) );
//Equilateral Triangle for forming Koch Snowflake
lines.push_back( new Line( SCR_W-100, 150, SCR_W-200, 180.0) );
lines.push_back( new Line( 100, 150, SCR_W-200, 60.0) );
Line* lineS = new Line( SCR_W-100, 150, SCR_W-200, 120.0);
lineS->x += cos(lineS->angle *(M_PI/180.0))*lineS->length;
lineS->y += sin(lineS->angle *(M_PI/180.0))*lineS->length;
lineS->angle -= 180.0;
lines.push_back( lineS );
while(!quit) //The loop
{
while(SDL_PollEvent(&in)) //Polling Events
{
if(in.type == SDL_QUIT)
quit = true;
}
SDL_RenderClear(renderer); //Clearing renderer
for(auto itr = lines.begin(); itr != lines.end(); itr++)
(*itr)->draw(); //Drawing all lines
SDL_RenderPresent(renderer); //Updating screen
SDL_Delay(2500); //Delay to show each iteration
kochFractal(lines); //Applying Koch Fractal
}
for(auto itr = lines.begin(); itr != lines.end(); itr++)
delete (*itr); //Deleting all lines at the end of a program
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
SDL_Quit(); //Clearing all SDL resources
return 0;
}
|