Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- #include <graphics.h>
- double factor;
- void koch( int level, int scale, int rot )
- {
- if(level > 0){
- koch(level-1, scale/3, rot);
- koch(level-1, scale/3, (rot+1)%6);
- koch(level-1, scale/3, (rot+5)%6);
- koch(level-1, scale/3, rot);
- }else{
- switch (rot){
- case 0: linerel(scale, 0); break;
- case 1: linerel(scale/2, scale*factor); break;
- case 2: linerel(-scale/2, scale*factor); break;
- case 3: linerel(-scale, 0); break;
- case 4: linerel(-scale/ 2, -scale*factor); break;
- case 5: linerel(scale/2, -scale*factor); break;
- }
- }
- }
- void startGraphics(){
- int gd=DETECT, gm;
- initgraph(&gd, &gm, "C:\\TURBOC3\\BGI");
- }
- void main(){
- int n, i;
- factor = sqrt(3)/-2;
- printf("Enter the level: ");
- scanf("%d", &n);
- startGraphics();
- for(i = 0; i <= n; i++){
- clearviewport();
- moveto(0, getmaxy()-50);
- koch(i, getmaxx(), 0);
- delay(1000);
- }
- getch();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement