0% found this document useful (0 votes)
64 views3 pages

CG Exp-7

The document describes the implementation of the Koch curve fractal. It includes code to recursively draw the curve using OpenGL graphics functions. The code takes the initial angle, length and number of iterations as parameters and draws the curve by recursively dividing each line segment into four parts and adjusting the angle. The main function initializes the graphics window and calls the display function, which draws the curve with different initial angles in red color.

Uploaded by

piyush
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
64 views3 pages

CG Exp-7

The document describes the implementation of the Koch curve fractal. It includes code to recursively draw the curve using OpenGL graphics functions. The code takes the initial angle, length and number of iterations as parameters and draws the curve by recursively dividing each line segment into four parts and adjusting the angle. The main function initializes the graphics window and calls the display function, which draws the curve with different initial angles in red color.

Uploaded by

piyush
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Pratiksha D.

Laldas
SE Computer A
Roll No. 53
Exiperiment No : 07
Aim: Implementation of Koch Curve.
Code:
#include <GL/glut.h>
#include <math.h>

GLfloat oldx=-0.7,oldy=0.5;

void drawkoch(GLfloat dir,GLfloat len,GLint iter) {


GLdouble dirRad = 0.0174533 * dir;
GLfloat newX = oldx + len * cos(dirRad);
GLfloat newY = oldy + len * sin(dirRad);
if (iter==0) {
glVertex2f(oldx, oldy);
glVertex2f(newX, newY);
oldx = newX;
oldy = newY;
}
else {
iter--;
//draw the four parts of the side _/\_
drawkoch(dir, len, iter);
dir += 60.0;
drawkoch(dir, len, iter);
dir -= 120.0;
drawkoch(dir, len, iter);
dir += 60.0;
drawkoch(dir, len, iter);
}
}

void display(){
glClear( GL_COLOR_BUFFER_BIT );
glBegin(GL_LINES);
glColor3f(0.0, 1.0, 0.0);
drawkoch(0.0,0.04,3);
drawkoch(-120.0, 0.04, 3);
drawkoch(120.0,0.04,3);
glEnd();
glFlush();
}

int main(int argc, char** argv)


{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(500,500);
glutInitWindowPosition(0,0);
glutCreateWindow("Koch Curve");
glutDisplayFunc(display);
glutMainLoop();
}
OUTPUT:

Conclusion:
Hence, we have successfully studied and implemented Koch Curve.

You might also like