TAREA 4: Tablero de Ajedrez
Por: Juan Angel Ortiz Contreras
#include <windows.h>
#include <C:\GLUT\include\GL\glut.h>
#include <stdlib.h>
#include <math.h>
float nx,ny,r,g,b,dx,dy,pi=3.141592653;
float radio=90,a1,a2,px = 0.5,py = 0.5, pz= 0.0;
int puntos=0, ancho=600,alto=600,tam_px=1;
int tx=0,ty=0;
void circulo(float cx,float cy,float radio,float r,float g,float b,float a1,float a2)
{
glBegin(GL_POLYGON);
glColor3f(r,g,b);
glVertex2f(cx, cy);
for (float i=a1; i<a2; i+=0.01)
{
dx=radio*cos(i)+cx;
dy=radio*sin(i)+cy;
glVertex2f(dx, dy);
}
glEnd();
}
void dibujar(){
int cx=0;int cy=0;
circulo(cx,cy,5,0.858,0.196,0.211,0.7854,2.7);
circulo(cx,cy,5,0.956,0.76,0.05,2.65,3.65);
circulo(cx,cy,5,0.235,0.73,0.33,3.65,5.49);
circulo(cx,cy,5,0.282,0.52,0.93,5.48,2*3.22);
circulo(cx,cy,3,1,1,1,0,2*3.1416);
glColor3f(0.282,0.52,0.93);
//Rectangulo de la G
glBegin(GL_TRIANGLE_FAN);
glVertex2f(0+cx,0.8+cy);glVertex2f(4.98+cx,0.8+cy);
glVertex2f(4.93+cx,-1+cy);glVertex2f(0+cx,-1+cy);
glEnd();
}
void tablero()
{
glPointSize(5);
int x=0,y=0,contador = 0,con = 0,var = 0,vary = 0,n;
while(con < 8)
{
if(con % 2 == 0)
{
while(contador < 8)
{
if(contador % 2 == 0)
{
glBegin(GL_TRIANGLE_STRIP);
glColor3f(0.0,0.0,0.0);
x = var;
y = vary;
glVertex2f(x,y);
x = var + 1;
y = vary;
glVertex2f(x,y);
x = var + 1;
y = vary + 1;
glVertex2f(x,y);
x = var;
y = vary + 1;
glVertex2f(x,y);
x = var;
y = vary;
glVertex2f(x,y);
glEnd();
}
else
{
glBegin(GL_TRIANGLE_STRIP);
glColor3f(255.0,255.0,255.0);
x = var;
y = vary;
glVertex2f(x,y);
x = var + 1;
y = vary;
glVertex2f(x,y);
x = var + 1;
y = vary + 1;
glVertex2f(x,y);
x = var;
y = vary + 1;
glVertex2f(x,y);
x = var;
y = vary;
glVertex2f(x,y);
glEnd();
}
contador++;
var = var + 1;
}
}
else
{
while(contador < 8)
{
if(contador % 2 == 0)
{
glBegin(GL_TRIANGLE_STRIP);
glColor3f(255.0,255.0,255.0);
x = var;
y = vary;
glVertex2f(x,y);
x = var + 1;
y = vary;
glVertex2f(x,y);
x = var + 1;
y = vary + 1;
glVertex2f(x,y);
x = var;
y = vary + 1;
glVertex2f(x,y);
x = var;
y = vary;
glVertex2f(x,y);
glEnd();
}
else
{
glBegin(GL_TRIANGLE_STRIP);
glColor3f(0.0,0.0,0.0);
x = var;
y = vary;
glVertex2f(x,y);
x = var + 1;
y = vary;
glVertex2f(x,y);
x = var + 1;
y = vary + 1;
glVertex2f(x,y);
x = var;
y = vary + 1;
glVertex2f(x,y);
x = var;
y = vary;
glVertex2f(x,y);
glEnd();
}
contador++;
var = var + 1;
}
}
con++;
contador = 0;
vary = vary + 1;
var = 0;
}
glEnd();
glFlush();
}
void display(void){
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();
tablero();
glPopMatrix();
glPushMatrix();
glTranslatef(px,py,pz);
glScalef(0.05,0.05,0.05);
dibujar();
glPopMatrix();
glFlush();
}
void key(unsigned char c, int x, int y)
{
switch(c){
case 27:
exit(0);
break;
case 'w':
if(py < 7){
py += 1;
}
break;
case 's':
if(py > 1){
py -= 1;
}
break;
case 'a':
if(px > 1){
px -= 1;
}
break;
case 'd':
if(px < 7){
px += 1;
}
break;
}
display();
}
void miInicializacion()
{ glClearColor(1.0,1.0,1.0,0);
gluOrtho2D(0,8,0,8);
glPointSize(tam_px);
glEnable(GL_POINT_SMOOTH);
}
int main(int argc, char **argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowPosition(100,100);
glutInitWindowSize(ancho,alto);
glutCreateWindow("TABLERO G");
miInicializacion();s
glutDisplayFunc(display);
glutKeyboardFunc(key);
glutMainLoop();
return 0;
}
No hay comentarios:
Publicar un comentario