-
Notifications
You must be signed in to change notification settings - Fork 0
/
11. Fractal
37 lines (29 loc) · 1.03 KB
/
11. Fractal
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
/********************************************************************************
TITLE: PROGRAM TO IMPLEMENT THE FRACTAL.
********************************************************************************/
#include <graphics.h>
#include<math.h>
#define PI 3.141592
void branch(float x,float y,float len,float theta)
{
float x2 = x + len*cos(theta),y2 = y + len*sin(theta); // FINDING ENDPOINT
putpixel(x,y,14);
putpixel(x2,y2,14);
float midX = x + len/1.8*cos(theta),midY = y + len/1.8*sin(theta);
if(len >20) // STOPPING CONDITION
{
branch(midX,midY,len/2,theta + PI/3); // RECURSIVE CALLS
branch(midX,midY,len/2,theta - PI/3);
branch(midX,midY,len/2,theta + PI/6);
branch(midX,midY,len/2,theta - PI/6);
}
}
int main()
{
int gd=DETECT,gm;//Detects the graphics drivers automatically
initgraph(&gd,&gm,"");//Initialize to graphics mode
branch(300,75,300,PI/2); // THE MAIN BARK OF TREE
getch(); //Pauses the Output Console until a key is pressed
closegraph(); //Closes the graphics mode
return 0;
}