Professional Documents
Culture Documents
Algoritmo Figura Poligonal
Algoritmo Figura Poligonal
h>
#include <GL/glut.h>
#include <math.h>
#include <iostream>
using namespace std;
int ancho = 490, alto = 490, color;
bool click = false;
double xini, xfin, yini, yfin;
float t = 0, u = 1;
float k = 0, l = 1;
int xpin, ypin;
double dx, dy, m, b, col;
int n[2][1];
int coordenadas[2][257]
={ {44,67,77,44,85,101,44,104,127,44,110,102,110,127,104,110,102,110,111,116,194,167
,127,110,111,116,108,102,103,116,124,124,116,194,158,148,142,124,116,124,142,148,158
,156,224,194,158,156,143,236,224,156,143,171,236,143,150,145,110,171,143,171,159,117
,102,99 ,110,171,159,117,102,110,109,100,90 ,99 ,
102,117,159,171,255,245,236,171,179,187,199,255,171,179,176,167,164,155,169,183,187,
179,187,183,169,167,161,162,159,140,141,155,169,183,187,199,255,263,292,245,255,263,
278,296,287,288,292,292,263,278,278,269,282,296,278,278,269,262,257,273,282,269,278,
278,263,292,331,245,292,339,331,292,339,353,365,348,331,339,353,364,371,385,367,365,
353,364,371,390,399,392,385,371,364,353,365,348,331,340,345,381,389,340,345,381,386,
428,412,413,381,386,406,420,432,428,386,428,444,438,444,438,432,428,412,413,403,392,
402,400,394,389,381,389,374,359,342,327,389,327,389,327,311,331,340,389,327,311,290,
245,331,311,290,245,236,224,223,215,223,194,224,194,211,197,194,180,170,194,170,175,
165,166,160,127,167,194,167,127,126,134,160},
{75,95,96,75,111,111,75,128,128,75,134,140,144,128,128,134,140,144,149,153,155,131,1
28,144,149,153,178,183,198,201,197,191,153,155,186,171,183,191,153,191,183,171,186,2
11,203,155,186,211,236,207,203,211,236,287,207,236,264,267,267,287,236,287,294,279,3
16,296,267,287,294,279,316,322,333,340,308,296,316,279,294,287,301,215,207,287,304,3
36,305,301,287,304,326,344,368,389,374,354,336,304,336,354,374,388,395,405,411,411,4
05,389,374,354,336,305,301,322,287,215,301,322,355,354,327,303,296,287,322,355,369,3
99,392,354,355,369,399,402,413,413,392,399,369,355,322,287,240,215,287,320,240,287,3
20,345,326,305,240,320,345,357,383,383,349,326,345,357,383,409,400,383,383,383,357,3
45,326,305,240,245,262,285,235,242,262,285,303,293,283,265,285,303,315,311,310,294,3
03,294,284,300,318,335,311,294,283,265,252,244,239,225,235,235,285,235,210,204,210,2
23,235,223,235,223,215,239,242,235,223,215,211,215,239,215,211,215,207,203,170,161,1
52,155,203,155,153,140,131,124,123,155,123,116,108,116,121,128,131,155,131,128,111,1
19,121} };
void display() {
glFlush();
}
void pintaPixel(int x, int y, int color) {
glPointSize(1);
if (t < 1 ) {glColor3f(1, 0, t);}
if (t >= 1 ) {glColor3f(u+1, 0, 1);}
if (t >= 2 ) {glColor3f(0, t - 2, 1);}
if (t >= 3 ) {glColor3f(0, 1, u + 3);}
if (t >= 4) { glColor3f(t - 4, 1, 0); }
if (t >= 5) { glColor3f(1, u + 5, 0); }
if (t >= 5) { t = 0; u = 1; }
glColor3f(1, 0, 1);
glBegin(GL_POINTS);
glVertex2f(x, y);
glEnd();
glutSwapBuffers();
}
void DDA(int x1, int x2, int yuno, int y2,int color) {
int k;
double x, y, dx, dy, otro;
if (abs(x2 - x1) >= abs(y2 - yuno)) {
otro = abs(x2 - x1);
} else {
otro = abs(y2 - yuno);
}
dx = (x2 - x1) / otro;
dy = (y2 - yuno) / otro;
k = 1;
x = (double)x1;
y = (double)yuno;
while (k <= otro) {
pintaPixel(roundf(x), roundf(y), color);
x = x + dx;
y = y + dy;
k++;
}
glFlush();
}
void pintarellena(int x1, int x2, int yuno, int y2) {
int k;
double x, y, dx, dy, otro;
if (abs(x2 - x1) >= abs(y2 - yuno))
{
otro = abs(x2 - x1);
}
else {
otro = abs(y2 - yuno);
}
dx = (x2 - x1) / otro;
dy = (y2 - yuno) / otro;
k = 1;
x = (double)x1;
y = (double)yuno;
while (k <= otro) {
//pintaPixel(x, y, 1);
x = x + dx;
y = y + dy;
k++;
t = t + 0.005;
u = u - 0.005;
}
}
}
void abstract(int btn, int state, int x, int y) {// parametros de botón, estado,
coordenadas
}
}*/
t=t+0.1;
u=u-0.1;
glFlush();
}
return 0;
}