jueves, 12 de abril de 2007

REPORTE PRACTICA 6

//Segun la numeracion esta seria el reporte de la practica 5
//Programa que dibuja lineas, triangulos, y cuadros, se limpia la ventana cada 30 segundos
#include string.h
#include GL/glut.h
#include stdarg.h
#include windows.h
#include stdio.h
#include malloc.h


void pinta(void);
int opcion;
float r,b,g;
float x1,y1,z1;
char string[]="00:00:00";
x0=24;
opcion=1;

void init(void)
{
glClear(GL_COLOR_BUFFER_BIT);
}

void pinta(void){

int xe,ze;
float x2,y2;

if(opcion==1)
{

if(r>=1 b>=1 g>=1){
r=0;
b=0;
g=0;

}
r= r+.1;
b= b+.2;
g= g+.3;
glColor3f(r,b,g);
x1= rand()%500;
y1= rand()%500;
z1= rand()%500;
glBegin(GL_LINES);
glVertex3f(x1,y1,0);
x1= rand()%500;
y1= rand()%500;
z1= rand()%500;
glVertex3f(x1,y1,0);
glEnd();
}

if(opcion==3)
{
if(r>=1 b>=1 g>=1){
r=0;
b=0;
g=0;

}
r= r+.3;
b= b+.1;
g= g+.2;
glColor3f(r,b,g);
y1= rand()%12;
z1= rand()%12;
x2= rand()%500;
y2= rand()%500;

glPushMatrix();
glTranslatef(x2,y2,0);
glScalef(z1,y1,0);

glBegin(GL_LINES);
glVertex3f(10,2,0);
glVertex3f(20,2,0);
glEnd();

glBegin(GL_LINES);
glVertex3f(10,2,0);
glVertex3f(10,12,0);
glEnd();

glBegin(GL_LINES);
glVertex3f(20,2,0);
glVertex3f(20,12,0);
glEnd();

glBegin(GL_LINES);
glVertex3f(10,12,0);
glVertex3f(20,12,0);
glEnd();
glPopMatrix();
}

if(opcion==2)
{
if(r>=1 b>=1 g>=1){
r=0;
b=0;
g=0;

}
r= r+.2;
b= b+.3;
g= g+.1;
glColor3f(r,b,g);
x1= rand()%15;
y1= rand()%15;
x2= rand()%500;
y2= rand()%500;
glPushMatrix();
glTranslatef(x2,y2,0);
glScalef(x1,y1,0);
glBegin(GL_LINES);
glVertex3f(-10,1,0);
glVertex3f(10,1,0);
glEnd();

glBegin(GL_LINES);
glVertex3f(0,20,0);
glVertex3f(-10,1,0);
glEnd();

glBegin(GL_LINES);
glVertex3f(0,20,0);
glVertex3f(10,1,0);
glEnd();

glPopMatrix();
}
}

void display(void)
{
pinta();
glFlush();
}

void reshape(int w, int h)
{
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0, w, h, 0);
glMatrixMode(GL_MODELVIEW);
}
//MANEJO DEL RETARDO
void TimerFunction()
{
glutPostRedisplay();
glutTimerFunc(3000, TimerFunction, 1);
}
void TimerFunction2()
{
glutPostRedisplay();
glClear(GL_COLOR_BUFFER_BIT);
glutTimerFunc(30000, TimerFunction2, 2);

}


//ACCIONES DEL MOUSE
void onMouse(int button, int state, int x, int y) {

if ( (button == GLUT_RIGHT_BUTTON) & (state == GLUT_DOWN) ) {
if(opcion==1)
opcion=1;
if(opcion==2)
opcion=1;
if(opcion==3)
opcion=2;
TimerFunction();
}

if ( (button == GLUT_LEFT_BUTTON) & (state == GLUT_DOWN) ) {
if(opcion==3)
opcion=3;
if(opcion==2)
opcion=3;
if(opcion==1)
opcion=2;
TimerFunction();
}
}



int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE GLUT_RGB);
glutInitWindowSize(500, 500);
glutCreateWindow("Reporte Practica 6");
glClearColor(0.0, 0.0, 0.0, 1.0);
init ();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMouseFunc(onMouse);
glutTimerFunc(3000, TimerFunction, 1);
glutTimerFunc(30000, TimerFunction2, 2);
glutMouseFunc(onMouse);
glutMainLoop();
return 0;
}

No hay comentarios: