C Curve Algorithm
C Curve Algorithm
Submitted To:
Shuhena Salam Aonty
Lecturer,
Department of CSE, CUET
#include<GL/glu.h> return;
#include<GL/glut.h> }
#include<stdlib.h> }
void line(float x1, float y1, float x2, float y2, glViewport(0, 0, width, height);
glBegin(GL_TRIANGLES); glLoadIdentity();
glVertex2f(x2, y2); }
glEnd(); glClear(GL_COLOR_BUFFER_BIT);
void Gasket(float x1, float y1, float x2, float float x2 = 300.0, y2 = 100.0;
if (n>0) { int n = 3;
float y1_mid = (y1 + y2) / 2.0; Gasket(x1, y1, x2, y2, x3, y3, n);
float x3_mid = (x3 + x1) / 2.0; int main(int argc, char** argv) {
} glutMainLoop();
}
Koch_Curve Source Code: Koch_curve(x, y, len, alpha,
#include<windows.h> n - 1);
#include<GL/glut.h> } else {
#include<stdlib.h> glBegin(GL_LINES);
#include<stdio.h> glVertex2f(x,y);
#include<math.h>
#define PI 3.14159 glVertex2f(x+len*cos(alpha),y+len*sin(alph
int n=3; }
{ }
n - 1); }
y = y + len*sin(alpha); glClear(GL_COLOR_BUFFER_BIT);
x = x + len*cos(alpha - glLoadIdentity();
(60*PI)/180); gluOrtho2D(-100,100,-100,100);
y = y + len*sin(alpha - }
(60*PI)/180);
Koch_curve(x, y, len, alpha + int main(int argc, char** argv){
x = x + len*cos(alpha + glutInitDisplayMode(GLUT_SINGLE |
(60*PI)/180); GLUT_RGB);
y = y + len*sin(alpha + glutInitWindowSize(500,500);
(60*PI)/180); glutInitWindowPosition(100,100);
glutCreateWindow("Koch-Curve");
init();
glutDisplayFunc(display);
glutMainLoop();
return 0;
}
C_Curve Output: Koch_Curve Output:
Gasket Output: