Skip to content

Instantly share code, notes, and snippets.

@kevinmungai
Created November 2, 2017 09:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kevinmungai/b3df3273bde396ae6bd41bb230c0cdbf to your computer and use it in GitHub Desktop.
Save kevinmungai/b3df3273bde396ae6bd41bb230c0cdbf to your computer and use it in GitHub Desktop.
f (x) = e ^ -x cos (2 . pi . x)
// lab assignment
// f (x) = e ^ -x cos (2 pi x)
#include <windows.h> // for MS Windows
#include <GL/glut.h> // GLUT, include glu.h and gl.h
#include <GL/gl.h>
#include <cmath>
#include <math.h>
/* Initialize OpenGL Graphics */
GLdouble special (GLdouble x);
void initGL();
void display ();
void initGL() {
// Set "clearing" or background color
glClearColor(0.0f, 0.0f, 0.0f, 1.0f); // Black and opaque BackGround
gluOrtho2D(0.0, 4.0, -2.0, 2.0); // World View gluOrtho2d(left, right, bottom, top);
glViewport(0, 0, 640, 480); // Is the View Port glViewport(left, bottom, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
}
GLdouble special(GLdouble x) {
const double EulerConstant = std::exp(1.0);
GLdouble a = pow (EulerConstant, (-x)) ;
GLdouble b = cos (2 * M_PI * x);
return a * b;
}
void display() {
glClear(GL_COLOR_BUFFER_BIT);
GLdouble x;
glBegin(GL_LINE_STRIP);
for (x = 0.0; x <= 4.0; x+= 0.000001 ) {
glVertex2d(x, special(x));
}
glEnd();
glFlush();
}
/* Main function: GLUT runs as a console application starting at main() */
int main(int argc, char** argv) {
glutInit(&argc, argv); // Initialize GLUT
glutCreateWindow(" f (x) = e ^ -x cos (2 * PI * x)"); // Create window with the given title
glutInitWindowSize(320, 320); // Set the window's initial width & height
glutInitWindowPosition(50, 50); // Position the window's initial top-left corner
glutDisplayFunc(display); // Register callback handler for window re-paint event
initGL(); // Our own OpenGL initialization
glutMainLoop(); // Enter the event-processing loop
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment