0% found this document useful (0 votes)
39 views2 pages

Exp11 CG 245

This document contains code to implement a Koch curve fractal in C++. The code takes in coordinates for a starting and ending point of a line segment, and the number of iterations to run. It recursively divides the line segment into four parts, replacing the middle segment with an equilateral triangle. This process is repeated on the smaller segments for the specified number of iterations to generate the fractal pattern of the Koch curve. The code was run with a line from (100,100) to (400,400) over 4 iterations.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views2 pages

Exp11 CG 245

This document contains code to implement a Koch curve fractal in C++. The code takes in coordinates for a starting and ending point of a line segment, and the number of iterations to run. It recursively divides the line segment into four parts, replacing the middle segment with an equilateral triangle. This process is repeated on the smaller segments for the specified number of iterations to generate the fractal pattern of the Koch curve. The code was run with a line from (100,100) to (400,400) over 4 iterations.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

VAIBHAVI BHAGWAN WELIS SECMPNB

245 192123
EXPERIMENT NO.:11
AIM: TO IMPLEMENT FRACTAL(KOCH CURVE)

CODE:

#include<graphics.h>

#include<conio.h>

#include<math.h>

void koch(int x1, int y1, int x2, int y2, int it)

float angle = 60*M_PI/180;//calculating angle in radians

int x3 = (2*x1+x2)/3;

int y3 = (2*y1+y2)/3;

int x4 = (x1+2*x2)/3;

int y4 = (y1+2*y2)/3;

int x = x3 + (x4-x3)*cos(angle)+(y4-y3)*sin(angle);

int y = y3 - (x4-x3)*sin(angle)+(y4-y3)*cos(angle);
/*If order is greater than zero, the line is divided into four line segments, each of which is a fractal
*line of the next lower order. The four segments connect the same endpoints as the straight line,

* but include a triangular wedge replacing the center third of the segment. */

if(it > 0)

koch(x1, y1, x3, y3, it-1);


koch(x3, y3, x, y, it-1);

koch(x, y, x4, y4, it-1);


koch(x4, y4, x2, y2, it-1);

else /*If order is 0, the fractal line is just a straight line*/

{
line(x1, y1, x3, y3);

line(x3, y3, x, y);

line(x, y, x4, y4);

line(x4, y4, x2, y2);

int main(void)

int gd = DETECT, gm;

initgraph(&gd, &gm, "C://TURBOC3//BGI");


int x1 = 100, y1 = 100, x2 = 400, y2 = 400;

koch(x1, y1, x2, y2, 4);

getch();
return 0;

OUTPUT:

****************************

You might also like