본문 바로가기

IT/Algorithm

Algorithm: 프랙탈 그래픽(Fractal Graphic)

소용돌이


#include <stdio.h>

#include <windows.h>

#include <time.h>


int x,y;

int t = 100;


void gotoxy(int x, int y);

void delay(clock_t n);

void left();

void right();

void up();

void down();


void main(){

int i,j;

x = 15;

y = 15;

gotoxy(x,y);

printf("A");

delay(1000);

for(i=1; i<=30; i++){

j = i;

if(j%2 == 1){

while(j--){

left();

}

j = i;

while(j--){

up();

}

}

if(j%2 == 0){

while(j--){

right();

}

j = i;

while(j--){

down();

}

}


}

gotoxy(30,30);

}


void left(){

x = x - 1;

gotoxy(x,y);

printf("A");

delay(t);

}


void up(){

y = y - 1;

gotoxy(x,y);

printf("A");

delay(t);

}


void right(){

x = x + 1;

gotoxy(x,y);

printf("A");

delay(t);

}


void down(){

y = y + 1; 

gotoxy(x,y);

printf("A");

delay(t);


}


void delay(clock_t n){

  clock_t start = clock();

  while(clock() - start < n);

}


void gotoxy(int x, int y){

     COORD Cur;

     Cur.X=x;

     Cur.Y=y;

     SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),Cur);

}