Chittagong University of Engineering and Technology
Department Of Computer Science and Engineering
Lab Report
Course No. : CSE-458
Course Title : Computer Graphics (Sessional)
Experiment No : 07
Experiment Name : Implementation of C Curve, Gasket and Koch
Curve Algorithm
Date of Submission : 20/07/2023
Submitted To:
Shuhena Salam Aonty
Lecturer,
Department of CSE, CUET
Submitted By: Remarks
Name : Estiak Ahamed Sazid
ID : 1804051
Section :A
Level :4
Term :1
C_Curve Source Code:
#include<windows.h> void display(void){
#include<GL/glut.h> alpha = ((alpha*PI)/180);
#include<stdlib.h> C_curve(x,y,len,alpha,n);
#include<stdio.h> }
#include<math.h>
#define PI 3.14159 void init(void){
float x=10, y=20, len=50, alpha=0; glClear(GL_COLOR_BUFFER_BIT);
int n=3; glClearColor(0,0,0,0);
void C_curve(float x, float y, float len, float glMatrixMode(GL_PROJECTION);
alpha,int n){ glLoadIdentity();
gluOrtho2D(-100,100,-100,100);
if(n>0){ }
len = len/sqrt(2.0); int main(int argc, char** argv){
C_curve(x,y,len,alpha+(45*PI)/180,n- glutInit(&argc, argv);
1); glutInitDisplayMode(GLUT_SINGLE |
x = x + len*cos(alpha+(45*PI)/180); GLUT_RGB);
y = y + len*sin(alpha+(45*PI)/180); glutInitWindowSize(500,500);
C_curve(x,y,len,alpha-(45*PI)/180,n- glutInitWindowPosition(100,100);
1); glutCreateWindow("C-Curve");
} init();
else{ glutDisplayFunc(display);
glBegin(GL_LINES); glutMainLoop();
glVertex2f(x,y); return 0;
}
glVertex2f(x+len*cos(alpha),y+len*sin(alph
a));
}
glEnd();
glFlush();
}
Gasket Source Code: else{
#include<windows.h> line(x1, y1, x2, y2, x3, y3);
#include<GL/glu.h> return;
#include<GL/glut.h> }
#include<stdlib.h> }
#include <cmath> void reshape(int width, int height) {
void line(float x1, float y1, float x2, float y2, glViewport(0, 0, width, height);
float x3, float y3) { glMatrixMode(GL_PROJECTION);
glBegin(GL_TRIANGLES); glLoadIdentity();
glVertex2f(x1, y1); gluOrtho2D(0, width, 0, height);
glVertex2f(x2, y2); }
glVertex2f(x3, y3); void display() {
glEnd(); glClear(GL_COLOR_BUFFER_BIT);
} float x1 = 100.0, y1 = 100.0;
void Gasket(float x1, float y1, float x2, float float x2 = 300.0, y2 = 100.0;
y2, float x3, float y3, int n) { float x3 = 200.0, y3 = 300.0;
if (n>0) { int n = 3;
float x1_mid = (x1 + x2) / 2.0; glColor3f(1.0, 1.0, 1.0);
float y1_mid = (y1 + y2) / 2.0; Gasket(x1, y1, x2, y2, x3, y3, n);
float x2_mid = (x2 + x3) / 2.0; glFlush();
float y2_mid = (y2 + y3) / 2.0; }
float x3_mid = (x3 + x1) / 2.0; int main(int argc, char** argv) {
float y3_mid = (y3 + y1) / 2.0; glutInit(&argc, argv);
Gasket(x1, y1, x1_mid, y1_mid, glutInitDisplayMode(GLUT_SINGLE |
x3_mid, y3_mid, n - 1); GLUT_RGB);
Gasket(x1_mid, y1_mid, x2, y2, glutInitWindowSize(600, 600);
x2_mid, y2_mid, n - 1); glutCreateWindow("Gasket Algorithm");
Gasket(x3_mid, y3_mid, x2_mid, glutDisplayFunc(display);
y2_mid, x3, y3, n - 1); glutReshapeFunc(reshape);
} 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
float x=-50, y=30, len=100, alpha=0; a));
int n=3; }
void Koch_curve (float x, float y, float len, glEnd();
float alpha, int n) glFlush();
{ }
if (n > 0) { void display(void){
len = len/3; alpha = ((alpha*PI)/180);
Koch_curve(x, y, len, alpha, Koch_curve(x,y,len,alpha,n);
n - 1); }
x = x + len*cos(alpha); void init(void){
y = y + len*sin(alpha); glClear(GL_COLOR_BUFFER_BIT);
Koch_curve(x, y, len, alpha - glClearColor(0,0,0,0);
(60*PI)/180, n - 1); glMatrixMode(GL_PROJECTION);
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){
(60*PI)/180, n - 1); glutInit(&argc, 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: