Accueil > > > TRACER UNE DROITE AVEC BRENSENHAM
TRACER UNE DROITE AVEC BRENSENHAM
Information sur la source
Description
Implémentation de l'algo de Brensenham qui permet à partir de deux points donnés de tracer la la droite qui relie ces 2 points en dessinant la droite point par point.
Source
- #include <stdio.h>
- #include <stdlib.h>
- #include <X11/Xlib.h>
-
- #define xc_min 20 // on definit un carre en donnant 2 points
- #define xc_max 140 // le coin superieure a gauche
- #define yc_min 20 // et le coin inferieure a droite
- #define yc_max 70
-
- /*
- Info.Graphique(Infographie) Brensenham : tracer des droites
- http://www.Software-DS.com
-
- Fonctionne sous Linux
- Compilation : (Fonctionne sur MacOSX si vous avez installe X11)
- gcc -o brensenham brensenham.c -L/usr/X11R6/lib -lX11
- */
-
- /* prototypes */
- void contact_serveur();
- void Creat_fenetre(void);
- void gerer_evenement();
- void Brensenham(int xa, int ya, int xb, int yb, int couleur);
-
- /* variables globales */
- GC gc;
- Display *display;
- int screen;
- Window win,root;
- int win_larg,win_haut;
- unsigned long white_pixel, black_pixel;
-
- /* ******************************************************************** */
-
- void contact_serveur(){
- if ((display = XOpenDisplay("")) == NULL) {
- fprintf(stderr, "Can't open Display\n");
- exit(1);
- }
- } /* contact_serveur */
-
- /* ******************************************************************** */
-
- void Creat_fenetre(void) {
- short border_width;
-
- screen = DefaultScreen(display);
- root = RootWindow(display,screen);
-
- white_pixel= WhitePixel(display,screen);
- black_pixel= BlackPixel(display,screen);
-
- border_width = 3;
-
- win_larg = DisplayWidth(display,screen)/4;
- win_haut = DisplayHeight(display,screen)/4;
-
- win = XCreateSimpleWindow(display,root,0,0,win_larg,win_haut,
- border_width,black_pixel,white_pixel);
- gc=DefaultGC(display,screen);
-
- XStoreName(display,win,"Brensenham - DS");
-
- XMapWindow(display,win);
- } /* Creat_fenetre */
-
- /* ******************************************************************** */
-
- void gerer_evenement() {
- char *str1="http://www.Software-DS.com";
- int i,a,b,c,d;
-
- XSelectInput(display,win,ExposureMask | KeyPressMask);
-
- for(;;) {
- XEvent ev;
- XNextEvent(display,&ev);
-
- switch(ev.type){
- case Expose :
- /* On va afficher des dessins ;) */
-
- /* on dessine un carre ou rectangle */
- Brensenham(xc_min, yc_min, xc_min, yc_max,0);
- Brensenham(xc_max, yc_max, xc_min, yc_max,0);
- Brensenham(xc_max, yc_max, xc_max, yc_min,0);
- Brensenham(xc_min, yc_min, xc_max, yc_min,0);
-
- /* on relie les diagonales */
- Brensenham(xc_min, yc_min, xc_max, yc_max,0);
- Brensenham(xc_min, yc_max, xc_max, yc_min,0);
- break;
-
- case KeyPress : // on appuie sur une touche pour quitter
- XClearWindow(display,win);
- XDrawString(display,win,gc,win_larg/5,win_haut*2/5,str1,strlen(str1));
- XFlush(display);
- sleep(4); // petite pause avant de fermer
- XDestroyWindow(display,win);
- XCloseDisplay(display);
- exit(0);
- break;
-
- default :
- fprintf(stderr,"J'ai recu un evt : %d\n",ev.type);
- break;
- } /* switch */
- } /* for */
- } /* gerer_evts */
-
- /* ******************************************************************** */
-
- void Brensenham(int xa, int ya, int xb, int yb, int couleur) {
- /* pour tracer une droite a partir de 2 points : (xa,ya) et (xb,yb) */
- int x,y,dx,dy,incrmX,incrmY,dp,NE,SE;
-
- dx = xb-xa;
- dy = yb-ya;
-
- if (dx>0)
- incrmX = 1;
- else {
- incrmX = -1;
- dx *= -1;
- }
-
- if (dy>0)
- incrmY = 1;
- else {
- incrmY = -1;
- dy *= -1;
- }
-
-
- if (dx>=dy) {
- dp=2*dy-dx;
- SE=2*dy;
- NE=2*(dy-dx);
-
- y=ya;
- for(x=xa;x!=xb;x+=incrmX) {
- /* affichePixel(x,y,couleur) */
- XDrawPoint(display,win,gc,x, y);
-
- if (dp<=0) /* on choisit le pixel E */
- dp += SE;
- else {
- dp += NE;
- y+=incrmY;
- }
- }
- }
- else if (dx<dy) {
- dp=2*dx-dy;
- SE=2*dx;
- NE=2*(dx-dy);
-
- x=xa;
- for(y=ya;y!=yb;y+=incrmY) {
- /* affichePixel(x,y,couleur) */
- XDrawPoint(display,win,gc,x, y);
-
- if (dp<=0) /* on choisit le pixel E */
- dp += SE;
- else {
- dp += NE;
- x+=incrmX;
- }
- }
- }
- } /* Brensenham */
-
-
- /* ******************************************************************** */
-
- int main() {
- contact_serveur();
- Creat_fenetre();
- gerer_evenement();
-
- return 0;
- }
#include <stdio.h>
#include <stdlib.h>
#include <X11/Xlib.h>
#define xc_min 20 // on definit un carre en donnant 2 points
#define xc_max 140 // le coin superieure a gauche
#define yc_min 20 // et le coin inferieure a droite
#define yc_max 70
/*
Info.Graphique(Infographie) Brensenham : tracer des droites
http://www.Software-DS.com
Fonctionne sous Linux
Compilation : (Fonctionne sur MacOSX si vous avez installe X11)
gcc -o brensenham brensenham.c -L/usr/X11R6/lib -lX11
*/
/* prototypes */
void contact_serveur();
void Creat_fenetre(void);
void gerer_evenement();
void Brensenham(int xa, int ya, int xb, int yb, int couleur);
/* variables globales */
GC gc;
Display *display;
int screen;
Window win,root;
int win_larg,win_haut;
unsigned long white_pixel, black_pixel;
/* ******************************************************************** */
void contact_serveur(){
if ((display = XOpenDisplay("")) == NULL) {
fprintf(stderr, "Can't open Display\n");
exit(1);
}
} /* contact_serveur */
/* ******************************************************************** */
void Creat_fenetre(void) {
short border_width;
screen = DefaultScreen(display);
root = RootWindow(display,screen);
white_pixel= WhitePixel(display,screen);
black_pixel= BlackPixel(display,screen);
border_width = 3;
win_larg = DisplayWidth(display,screen)/4;
win_haut = DisplayHeight(display,screen)/4;
win = XCreateSimpleWindow(display,root,0,0,win_larg,win_haut,
border_width,black_pixel,white_pixel);
gc=DefaultGC(display,screen);
XStoreName(display,win,"Brensenham - DS");
XMapWindow(display,win);
} /* Creat_fenetre */
/* ******************************************************************** */
void gerer_evenement() {
char *str1="http://www.Software-DS.com";
int i,a,b,c,d;
XSelectInput(display,win,ExposureMask | KeyPressMask);
for(;;) {
XEvent ev;
XNextEvent(display,&ev);
switch(ev.type){
case Expose :
/* On va afficher des dessins ;) */
/* on dessine un carre ou rectangle */
Brensenham(xc_min, yc_min, xc_min, yc_max,0);
Brensenham(xc_max, yc_max, xc_min, yc_max,0);
Brensenham(xc_max, yc_max, xc_max, yc_min,0);
Brensenham(xc_min, yc_min, xc_max, yc_min,0);
/* on relie les diagonales */
Brensenham(xc_min, yc_min, xc_max, yc_max,0);
Brensenham(xc_min, yc_max, xc_max, yc_min,0);
break;
case KeyPress : // on appuie sur une touche pour quitter
XClearWindow(display,win);
XDrawString(display,win,gc,win_larg/5,win_haut*2/5,str1,strlen(str1));
XFlush(display);
sleep(4); // petite pause avant de fermer
XDestroyWindow(display,win);
XCloseDisplay(display);
exit(0);
break;
default :
fprintf(stderr,"J'ai recu un evt : %d\n",ev.type);
break;
} /* switch */
} /* for */
} /* gerer_evts */
/* ******************************************************************** */
void Brensenham(int xa, int ya, int xb, int yb, int couleur) {
/* pour tracer une droite a partir de 2 points : (xa,ya) et (xb,yb) */
int x,y,dx,dy,incrmX,incrmY,dp,NE,SE;
dx = xb-xa;
dy = yb-ya;
if (dx>0)
incrmX = 1;
else {
incrmX = -1;
dx *= -1;
}
if (dy>0)
incrmY = 1;
else {
incrmY = -1;
dy *= -1;
}
if (dx>=dy) {
dp=2*dy-dx;
SE=2*dy;
NE=2*(dy-dx);
y=ya;
for(x=xa;x!=xb;x+=incrmX) {
/* affichePixel(x,y,couleur) */
XDrawPoint(display,win,gc,x, y);
if (dp<=0) /* on choisit le pixel E */
dp += SE;
else {
dp += NE;
y+=incrmY;
}
}
}
else if (dx<dy) {
dp=2*dx-dy;
SE=2*dx;
NE=2*(dx-dy);
x=xa;
for(y=ya;y!=yb;y+=incrmY) {
/* affichePixel(x,y,couleur) */
XDrawPoint(display,win,gc,x, y);
if (dp<=0) /* on choisit le pixel E */
dp += SE;
else {
dp += NE;
x+=incrmX;
}
}
}
} /* Brensenham */
/* ******************************************************************** */
int main() {
contact_serveur();
Creat_fenetre();
gerer_evenement();
return 0;
}
Sources du même auteur
Sources de la même categorie
Commentaires et avis
|
Derniers Blogs
IMAGINE CUP 2012, MAKE A SIGN EN FINALEIMAGINE CUP 2012, MAKE A SIGN EN FINALE par junarnoalg
Voilà qui est fait, la nouvelle est officielle ! L'équipe belge "Make a Sign" va au pays des kangourous défendre son projet dans la catégorie Software Design. http://www.imaginecup.com/CompetitionsContent/Competition/WorldwideFinalists.aspx V...
Cliquez pour lire la suite de l'article par junarnoalg KINECT 1.5 IS OUT !KINECT 1.5 IS OUT ! par Vko
La version 1.5 du Kinect For Microsoft vient tout juste de sortir ! Plein de nouveautés: Tracking de squelette en Near Mode Détection en position assise Détection faciale avec un SDK dédié Documentation et des guideline (enfin) Un out...
Cliquez pour lire la suite de l'article par Vko LES ACTUALITéS DE LA SEMAINE SUR C2I.FR (14 MAI - 20 MAI) LES ACTUALITéS DE LA SEMAINE SUR C2I.FR (14 MAI - 20 MAI) par richardc
Mise à jour des Web API du 14 Mai
Réservez dès maintenant votre journée du 20 juin pour le Windows Azure Dev Camp 2012 à Paris
Mise à jour de Team Foundation Service
MechCommander 2 sur Windows 8
Entity Framework 5 Release Candidate e...
Cliquez pour lire la suite de l'article par richardc REACTIVE EXTENSIONS : CONSOMMER DES SERVICES AVEC RX PARTIE 3, LES PIèGES à éVITERREACTIVE EXTENSIONS : CONSOMMER DES SERVICES AVEC RX PARTIE 3, LES PIèGES à éVITER par Groc
Une mauvaise utilisation de rx lors de l'écriture d'une couche d'accès à des services peut conduire à des cas embarassants avec des erreurs mal gérées, des appels qui ne partent lorsqu'ils le devraient, et même des résultats incorrects . le tout nuis...
Cliquez pour lire la suite de l'article par Groc SHAREPOINT BLOG SITE, PROBLèME D'ARCHIVESSHAREPOINT BLOG SITE, PROBLèME D'ARCHIVES par junarnoalg
Dernièrement, nous avons migré le site
myTIC
vers un nouveau serveur SharePoint 2010. Dans les contenus que nous vouloins récupérer, nous avions un certain nombre de blogs.
Nous avons utilisé les commandes Power...
Cliquez pour lire la suite de l'article par junarnoalg
Forum
RE : SAC A DOS RE : SAC A DOS par hadjkaddour
Cliquez pour lire la suite par hadjkaddour
Logiciels
sDEVIS-FACTURES vlPRO (8.1.0.3)SDEVIS-FACTURES VLPRO (8.1.0.3)sDEVIS-FACTURES vlPRO a été mis au point pour les particuliers, créateurs, entrepreneurs, artisa... Cliquez pour télécharger sDEVIS-FACTURES vlPRO 974 Application Server (12.2.4.6)974 APPLICATION SERVER (12.2.4.6)Développez de puissantes applications dans un environnement de 'cloud computing', clusterisé, séc... Cliquez pour télécharger 974 Application Server vPicture (1.4.2.1)VPICTURE (1.4.2.1)Avec vPicture, hébergez vos images facilement et rapidement.
vPicture est un utilitaire simple, ... Cliquez pour télécharger vPicture Easy-Planning (2.2.1.6)EASY-PLANNING (2.2.1.6)Easy-Planning permet de créer des plannings sous la représentation de diagrammes et est adapté au... Cliquez pour télécharger Easy-Planning COM-BACKUP (2.0)COM-BACKUP (2.0)
COM-BACKUP est un logiciel de sauvegarde qui permet de planifier les sauvegardes de vos dossiers ...
Cliquez pour télécharger COM-BACKUP
|