Académique Documents
Professionnel Documents
Culture Documents
#include <windows.h>
#include <GL/glu.h>
#include <GL/glut.h>
void drawSinWave()
{
float radius = 7.5;
float x2=0,y2,cx,cy,fx,fy;
float cos_y,cache_cos_y;
int cache = 0;
start += 1.0;
if(start >360) {
start = 0;
}
glBegin(GL_LINES);
float angle = 0;
for(angle=start; ; angle+=1.0) {
if(angle>1020) {
break;
angle = 0.0;
}
float rad_angle = angle * 3.14 / 180;
x2 = x2+0.1;
y2 = radius * sin((double)rad_angle);
cos_y = radius * sin((double)-rad_angle);
if (cache) {
glVertex2f(cx,cy);
glVertex2f(x2,y2);
glVertex2f(cx,cache_cos_y);
glVertex2f(x2,cos_y);
} else {
fx = x2;
fy = y2;
}
cache = 1;
cx = x2;
cy = y2;
cache_cos_y = cos_y;
}
glEnd();
}
void display(void) {
glClearColor (0.0,0.0,0.0,1.0);
glClear (GL_COLOR_BUFFER_BIT);
glLineWidth(10);
glLoadIdentity();
glTranslatef(-40,0,-30);
glColor3f(1,0,0);
drawSinWave();
glutSwapBuffers();
}
glutDisplayFunc (display);
glutIdleFunc (display);
glutReshapeFunc (reshape);
glutKeyboardFunc (keyboard);
glutMainLoop ();
return 0;
}
#include <iostream>
#include <stdlib.h>
#include <math.h>
#include <windows.h>
#include <GL/glu.h>
#include <GL/glut.h>
void drawSinWave()
{
float radius = 7.5;
float x2=0,y2,cx,cy,fx,fy;
//float cos_y,cache_cos_y;
int cache = 0;
start += 1.0;
if(start >360) {
start = 0;
}
glBegin(GL_LINES);
float angle = 0;
for(angle=start; ; angle+=1.0) {
if(angle>1020) {
break;
angle = 0.0;
}
float rad_angle = angle * 3.14 / 180;
x2 = x2+0.1;
y2 = radius * tan((double)rad_angle);
//cos_y = radius * tan((double)-rad_angle);
if (cache) {
glVertex2f(cx,cy);
glVertex2f(x2,y2);
//glVertex2f(cx,cache_cos_y);
//glVertex2f(x2,cos_y);
} else {
fx = x2;
fy = y2;
}
cache = 1;
cx = x2;
cy = y2;
cache_cos_y = cos_y;
}
glEnd();
}
void display(void) {
glClearColor (0.0,0.0,0.0,1.0);
glClear (GL_COLOR_BUFFER_BIT);
glLineWidth(10);
glLoadIdentity();
glTranslatef(-40,0,-30);
glColor3f(1,0,0);
drawSinWave();
glutSwapBuffers();
}
glutDisplayFunc (display);
glutIdleFunc (display);
glutReshapeFunc (reshape);
glutKeyboardFunc (keyboard);
glutMainLoop ();
return 0;
}
Screenshots: