Advertisement
Shailrshah

Fractal Tree

Oct 30th, 2014
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.73 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<conio.h>
  3. #include<graphics.h>
  4. #include<math.h>
  5.  
  6. double angle=(30*3.14)/180;
  7. void fractal(int l,double a,int x,int y){
  8.     if(l!=0){
  9.         double a1=a+angle, a2=a-angle;
  10.  
  11.         int x1=x+l*cos(a1);   int y1=y-l*sin(a1);
  12.         line(x,y,x1,y1);      fractal(l/2,a1,x1,y1);
  13.  
  14.         x1=x+l*cos(a2);       y1=y-l*sin(a2);
  15.         line(x,y,x1,y1);      fractal(l/2,a2,x1,y1);
  16.  
  17.         a1=a1+angle;          a2=a2-angle;
  18.  
  19.         x1=x+l*cos(a1);       y1=y-l*sin(a1);
  20.         line(x,y,x1,y1);      fractal(l/2,a1,x1,y1);
  21.  
  22.         x1=x+l*cos(a2);       y1=y-l*sin(a2);
  23.         line(x,y,x1,y1);      fractal(l/2,a2,x1,y1);
  24.     }
  25. }
  26.  
  27. void main(){
  28.     int gd=DETECT,gm;
  29.     initgraph(&gd,&gm," ");
  30.     fractal(100, (90*3.14)/180, 320, 400);
  31.     getch();
  32.     closegraph();
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement