Informations sur: Correction du prog de DMF

Publié par Francesco le 01/03/2008

Description

Correction apporté au programme de DMF : - Réécriture de la fonction de calcul d'angle, qui était totalement buggé - Inversion des angles de début et de fin lors du tracage des cercles - Abandon de l'utilisation de WINDOW pour la mise à l'échelle et utilisation de facteur d'échelle (xscale et yscale)

Code source (langage non précisé)

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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
DECLARE FUNCTION AngleHorizontal! (X!, Y!, CX!, CY!)
DIM xscale AS SINGLE
DIM yscale AS SINGLE

CLEAR
'************* ajustement taille ecran ***************
CLS
OPEN "lignes.txt" FOR INPUT AS #1
max = 0
may = 0
DO WHILE NOT EOF(1)
           INPUT #1, A$, b, c, d, e, f, g, h, i$
                'c=Xdepart d=Ydepart e=Xfin f=Yfin

        IF c > max THEN max = c
        IF e > max THEN max = e
        IF d > may THEN may = d
        IF f > may THEN may = f
LOOP
        Xmax$ = STR$(max): Xmax$ = LTRIM$(RTRIM$(Xmax$))
        Ymax$ = STR$(may): Ymax$ = LTRIM$(RTRIM$(Ymax$))
        xwin = CLNG(VAL(Xmax$))
        ywin = CLNG(VAL(Ymax$))
CLOSE
xscale = 640 / xwin
yscale = 480 / ywin

'******************************** dessin *************

SCREEN 12: 'WINDOW (-1, ywin + 2)-(xwin + 2, -1): CLS

    DEFSTR A-Z
   PI! = 3.141593

OPEN "lignes.txt" FOR INPUT AS #1
DO WHILE NOT EOF(1)
               INPUT #1, A$, b!, c!, d!, e!, f!, g!, h!, i$
                c! = c! * xscale
                d! = d! * yscale
                e! = e! * xscale
                f! = f! * yscale
                g! = g! * xscale
                h! = h! * yscale
' (A$=A ou L )(b!=pointage)
' (c!=X depart)(d!=Y depart)(e!=X arrivee)(f!=Y arrivee)
' (g!=X centre rayon)(h!=Y centre rayon)(i$= sens du rayon)

Xdepart! = c!: Ydepart! = d!: Xarrivee! = e!: Yarrivee! = f!
Xcentre! = g!: Ycentre! = h!

'''attribution des couleurs au pointage'''
        IF b! = 1 THEN     'SENS FIBRES TETE 1
         coul! = 14       'couleur jaune
        END IF
        IF b! = 2 THEN     'SENS TRAVERS TETE 2
         coul! = 10       'couleur vert clair
        END IF
        IF b! = 3 THEN     'SENS 120 degres TETE 3
         coul! = 9       'couleur bleu clair
        END IF
        IF b! = 4 THEN     'SENS trous centrage TETE 4
         coul! = 12       'couleur rouge clair
        END IF
        IF b! = 5 THEN     'SENS 160 degres TETE 5
         coul! = 11       'couleur cyan clair
        END IF

'envoi ecran
    IF A$ = "L" THEN
       LINE (c!, d!)-(e!, f!), coul!
    END IF
 
    IF A$ = "A" THEN
     R! = SQR((Xcentre! - Xarrivee!) ^ 2 + (Ycentre! - Yarrivee!) ^ 2)  'calcul rayon
     Angledebut! = AngleHorizontal!(c!, d!, g!, h!)
     Anglefin! = AngleHorizontal!(e!, f!, g!, h!)
     IF Angledebut! = Anglefin! THEN  'controle si un cercle
     CIRCLE (g!, h!), R!, coul!
     ELSE
     CIRCLE (g!, h!), R!, coul!, Anglefin!, Angledebut!
     END IF
    END IF
    LOOP
CLOSE
DO
LOOP WHILE INKEY$ = ""

END

DEFSNG A-Z
FUNCTION AngleHorizontal! (X!, Y!, CX!, CY!)
CONST PI = 3.14159
DIM DX AS SINGLE
DIM DY AS SINGLE
DIM Angle AS SINGLE

DX = X! - CX!
DY = -(Y! - CY!) ' Il y a un signe - car les coordonn‚es en Y sont invers‚es!
                 ' Le coin sup‚rieur gauche est de coordonn‚es (0, 0)
                 ' Tandis que le coins inf‚rieur gauche a pour coordonn‚es
                 ' (0, 640)

SELECT CASE DX
CASE IS = 0
        IF DY > 0 THEN
                Angle = PI / 2
        ELSE
                Angle = -PI / 2
        END IF
CASE IS > 0
        IF DY > 0 THEN
                Angle = ATN(DY / DX)
        ELSE
                Angle = 2 * PI + ATN(DY / DX)
        END IF
CASE IS < 0
        Angle = PI - ATN(DY / -DX)
END SELECT

AngleHorizontal! = Angle

END FUNCTION

v6 © Computaid SPRL 2005-2008 - Tous droits réservés - Hébergé par eTigris - Page générée en 0,026 s - Crédits - Stats
1 connecté