Bonjour,
je dois en C et à l'aide de l'header "conio.h", tracer des droites à coefficients de direction positif, négatif. Voici comment je suis partie mais pour le moment cela ne marche pas.
Voici mon header personnalisé :
Voici mon code obj_graphique.c
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33 #ifndef OBJ_GRAPHIQUE_H_INCLUDED #define OBJ_GRAPHIQUE_H_INCLUDED typedef struct { unsigned int x, y; int couleur; }Point; void afficher_point (Point); void effacer_point (Point); typedef struct { Point ext1, ext2; int couleur; }Ligne; Ligne init_ligne (unsigned int x1, unsigned int x2,unsigned int y1,unsigned int y2); void afficher_ligne (Ligne); void effacer_ligne (Ligne); typedef struct { unsigned int x,y; int largeur; int hauteur; int couleur; }Rectangle; void afficher_rectangle (Rectangle); void effacer_rectangle (Rectangle);
et voici mon main :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73 #include <stdio.h> #include <stdlib.h> #include "conio2.h" #include "obj_graphique.h" #include <math.h> void afficher_point (Point p) { // p.couleur = 4; gotoxy (p.x = 5, p.y = 5); putchxy(p.x,p.y,'*'); } void effacer_point (Point p) { gotoxy (p.x = 5, p.y = 5); putchxy(p.x,p.y,' '); // dans ce cas nous affichons un espace à la place de * ce qui fait qu'on l'efface } Ligne init_ligne (unsigned int x1, unsigned int x2,unsigned int y1,unsigned int y2) { Ligne ligne; unsigned int x,y; // // if (x1>x2) // { // x = x1; // x2 = x1; // x1= x; // } // // if (y1>y2) // { // y = y1; // y2 = y1; // y1= y; // } ligne.ext1.x = x1; ligne.ext2.x = x2; ligne.ext1.y = y1; ligne.ext2.y = y2; return ligne; } void afficher_ligne(Ligne l) { float pente; float dx, dy; Point p; unsigned int x, y; dx = l.ext2.x-l.ext1.x; /* longueur x de la droite */ dy = l.ext2.y-l.ext1.y; /* longueur y de la droite */ pente = dy/dx; // printf ("\nLa pente de la ligne est de:\n%lf", pente); /********************************************************** // CAS N°1 : dx>dy **********************************************************/ for ( x = l.ext1.x ; x<l.ext2.x ; x++ ) { y = x*(dy/dx); printf("%d, %d\n",x,y); putchxy(x,y,'*'); } }
Pouvez vous m'aider ??
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 int main() { Point point; Ligne ligne; unsigned int x1 = 1; unsigned int x2 = 2; unsigned int y1 = 3; unsigned int y2 = 4; // afficher_point (point); // effacer_point (point); ligne = init_ligne (x1,x2,y1,y2); afficher_ligne(ligne); // effacer_ligne(ligne); }
Merci d'avance,
Olivier
Partager