Le source: QuatreHuitConnexite.cpp
/* Auteur: Nicolas JANEY */
/* nicolas.janey@univ-fcomte.fr */
/* Mars 2002 */
/* 4-Connexite et 8-Connexite */
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <GL/glut.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include "ModuleCouleurs.h"
#include "ModuleMenus.h"
#include "ModuleReshape.h"
#include "ModuleFleche.h"
struct coord2D {
double x;
double y; } ;
struct segment {
coord2D pi;
coord2D pf; } ;
int aff = 0;
static segment seg = { { 5,3 },{ 35,16 } };
void pixel(int x,int y,float *c) {
glColor4fv(c);
glBegin(GL_QUADS) ;
glVertex2i(x,y) ;
glVertex2i(x+1,y) ;
glVertex2i(x+1,y+1) ;
glVertex2i(x,y+1) ;
glEnd() ;
glColor4fv(couleurNoir());
glBegin(GL_LINE_LOOP) ;
glVertex2i(x,y) ;
glVertex2i(x+1,y) ;
glVertex2i(x+1,y+1) ;
glVertex2i(x,y+1) ;
glEnd() ;
}
void dessine8Connexite() {
int i,j;
glColor4fv(couleurBleu()) ;
glBegin(GL_LINES);
for ( i = 1 ; i < 7 ; i++ ) {
glVertex2d(1.0,i);
glVertex2d(9.0,i); }
for ( i = 1 ; i < 10 ; i++ ) {
glVertex2d(i,1.0);
glVertex2d(i,6.0); }
glEnd() ;
for ( i = 3 ; i < 6 ; i++ )
for ( j = 2 ; j < 5 ; j++ )
pixel(i,j,couleurVertFonce());
pixel(4,3,couleurRouge());
glColor4fv(couleurJaune());
glPushMatrix();
glTranslatef(4.5F,3.75F,0.0F);
flecheEnVolume(0.0F,1.0F,0.0F,0.35F,0.6F,0.12F);
glPopMatrix();
glPushMatrix();
glTranslatef(4.5F,3.25F,0.0F);
flecheEnVolume(0.0F,-1.0F,0.0F,0.35F,0.6F,0.12F);
glPopMatrix();
glPushMatrix();
glTranslatef(4.25F,3.5F,0.0F);
flecheEnVolume(-1.0F,0.0F,0.0F,0.35F,0.6F,0.12F);
glPopMatrix();
glPushMatrix();
glTranslatef(4.75F,3.5F,0.0F);
flecheEnVolume(1.0F,0.0F,0.0F,0.35F,0.6F,0.12F);
glPopMatrix();
glPushMatrix();
glTranslatef(4.75F,3.75F,0.0F);
flecheEnVolume(0.8F,0.8F,0.0F,0.35F,0.6F,0.12F);
glPopMatrix();
glPushMatrix();
glTranslatef(4.25F,3.75F,0.0F);
flecheEnVolume(-0.8F,0.8F,0.0F,0.35F,0.6F,0.12F);
glPopMatrix();
glPushMatrix();
glTranslatef(4.25F,3.25F,0.0F);
flecheEnVolume(-0.8F,-0.8F,0.0F,0.35F,0.6F,0.12F);
glPopMatrix();
glPushMatrix();
glTranslatef(4.75F,3.25F,0.0F);
flecheEnVolume(0.8F,-0.8F,0.0F,0.35F,0.6F,0.12F);
glPopMatrix();
}
void dessine4Connexite() {
int i;
glColor4fv(couleurBleu()) ;
glBegin(GL_LINES);
for ( i = 1 ; i < 7 ; i++ ) {
glVertex2d(1.0,i);
glVertex2d(9.0,i); }
for ( i = 1 ; i < 10 ; i++ ) {
glVertex2d(i,1.0);
glVertex2d(i,6.0); }
glEnd() ;
pixel(4,3,couleurRouge());
pixel(5,3,couleurVertFonce());
pixel(3,3,couleurVertFonce());
pixel(4,2,couleurVertFonce());
pixel(4,4,couleurVertFonce());
glColor4fv(couleurJaune());
glPushMatrix();
glTranslatef(4.5F,3.75F,0.0F);
flecheEnVolume(0.0F,1.0F,0.0F,0.35F,0.6F,0.12F);
glPopMatrix();
glPushMatrix();
glTranslatef(4.5F,3.25F,0.0F);
flecheEnVolume(0.0F,-1.0F,0.0F,0.35F,0.6F,0.12F);
glPopMatrix();
glPushMatrix();
glTranslatef(4.25F,3.5F,0.0F);
flecheEnVolume(-1.0F,0.0F,0.0F,0.35F,0.6F,0.12F);
glPopMatrix();
glPushMatrix();
glTranslatef(4.75F,3.5F,0.0F);
flecheEnVolume(1.0F,0.0F,0.0F,0.35F,0.6F,0.12F);
glPopMatrix();
}
void display() {
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glPushMatrix();
switch (aff) {
case 0 : dessine4Connexite() ;
break ;
case 1 : dessine8Connexite() ;
break ; }
glPopMatrix();
glFlush();
glutSwapBuffers() ;
}
void key(unsigned char key,int x,int y) {
switch ( key ) {
case 0x1B : exit(0);
break;
case 0x0D : aff = (aff+1)%2;
glutPostRedisplay();
break; }
}
void myinit() {
glClearColor(0.8F,0.8F,0.8F,1.0F);
}
int main(int argc,char **argv) {
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_RGBA|GLUT_DEPTH|GLUT_DOUBLE);
glutInitWindowSize(210,130);
glutInitWindowPosition(50,50);
glutCreateWindow("4/8 Connexité");
myinit();
creationMenuBasique();
setParametresOrthoBasique(0.35,5.85,0.75,6.25,-50.0,50.0);
glutReshapeFunc(reshapeOrthoBasique);
glutKeyboardFunc(key);
glutDisplayFunc(display);
glutMainLoop();
return(0);
}