Computer Graphics – 6. e^(-x)*cos(2*x*π ) Graph

[wpdm_package id=’1407′]
Sample Output-graph

[sourcecode lang=”c”]
#include<GL/glut.h>
#include
double f(GLdouble x)
{ return (exp(-1 * x)*cos(2*3.14159*x));
}
void display()
{ glClear(GL_COLOR_BUFFER_BIT);

glBegin(GL_POINTS);
for(GLdouble x=0;x<4.0;x+=0.005)
{ glVertex2d(x*(350.0/4),(f(x)*(350.0/2))+(350.0/2));
}

glEnd();
glFlush();
}
int main(int argc, char** argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(500,500);
glutCreateWindow("Graph");
glutDisplayFunc(display);
gluOrtho2D(0.0,500.0,0.0,500.0);
glClearColor(0.25,0.0,0.2,1.0);
glutMainLoop();
}
[/sourcecode]

To compile the above program in ubuntu terminal –
# g++ -lGL -lGLU -lglut graph.cpp
# ./a.out

Leave a Reply

Your email address will not be published. Required fields are marked *