Premier commit
[powerfractal.git] / CD / Src / Power_Draw.adb
1 ------------------------------------------------------------------------------------------------
2 -- Nom : Power_Draw / fait partie du programme Power Fractal --
3 -- --
4 -- Auteurs : Gregory Burri & Adrien Crivelli --
5 ------------------------------------------------------------------------------------------------
6 -- But : Outils de bas niveau pour le dessin a l'ecran. --
7 -- Comme dessiner un carre, une partie du tampon etc.. --
8 ------------------------------------------------------------------------------------------------
9
10 with Spider; use Spider;
11 with Spider.Draw; use Spider.Draw; --Enfant de spider Pour gerer la couleur et le dessin
12 with Power_Types; use Power_Types;
13 with Power_Colors;
14
15 package body Power_Draw is
16
17 ------------------------------------------------------------------------------------------------
18 -- Nom : Dessin_Point_Fractal --
19 -- But : Dessiner un point de la fractal a l'ecran depuis la Matrice Tampon --
20 -- Parametres ----------------------------------------------------------------------------------
21 -- In : * les coordonnees x et y du point --
22 ------------------------------------------------------------------------------------------------
23 procedure Dessin_Point_Fractal(X, Y : Natural) is
24 Color_Back : Spider.Draw.Tcolor; --La couleur au format spider
25 begin -- Dessin_Point_Fractal
26
27 --Copie les composantes RGB du point dans la variable au format spider
28 Color_Back.R := Integer(Matrice_Tampon_Ecran(X, Y).R);
29 Color_Back.G := Integer(Matrice_Tampon_Ecran(X, Y).G);
30 Color_Back.B := Integer(Matrice_Tampon_Ecran(X, Y).B);
31 --
32
33 Set_Color_Pen(Color_Back); --Defini la couleur du pinceau
34 Move_To(X,Y); --Se deplace au coordonnees du point
35 Put_Pixel; --Affiche une pixel
36
37 end Dessin_Point_Fractal;
38
39
40 ------------------------------------------------------------------------------------------------
41 -- Nom : Boite --
42 -- But : dessiner un rectangle vide a l'ecran --
43 -- --
44 -- Parametres ----------------------------------------------------------------------------------
45 -- In : * les coordonnees du point superieur gauche : X1, Y1 --
46 -- * les coordonnees du point inferieur droit : X2, Y2 --
47 -- --
48 ------------------------------------------------------------------------------------------------
49 procedure Boite (X1, Y1, X2, Y2 : Natural; Couleur : Spider.Draw.Tcolor) is
50
51 begin --Boite
52
53
54 Spider.Draw.Set_Color_Pen(Couleur);
55 --Dessine quatre traits pour former le rectangle
56 Line_To(X1, Y1, X2, Y1);
57 Line_To(X1, Y2, X2, Y2);
58
59
60 Line_To(X1, Y1, X1, Y2);
61 Line_To(X2, Y1, X2, Y2);
62 --
63
64 end Boite;
65
66
67 ------------------------------------------------------------------------------------------------
68 -- Nom : Ligne_Matrice_Hori --
69 -- But : rafraichire une ligne horizontale de l'ecran depuis le tampon --
70 -- --
71 -- Parametres ----------------------------------------------------------------------------------
72 -- In : * La coordonnee de depart : X1 --
73 -- * La coordonnee de la fin : X2 --
74 -- * La coordonnee de positionement en Y : Y --
75 -- --
76 ------------------------------------------------------------------------------------------------
77 procedure Ligne_Matrice_Hori (X1, X2, Y : Natural) is
78
79 --Variable temporaire
80 X1_Tmp : Natural := X1;
81 X2_Tmp : Natural := X2;
82 --
83
84 Tmp : Natural; --Pour le swap de valeurs
85
86 begin --Ligne_Matrice_hori
87
88 --Si X1 est plus grand que X2 alors permute leur valeur
89 if X1_Tmp > X2_Tmp then
90 Tmp := X1_Tmp;
91 X1_Tmp := X2_Tmp;
92 X2_Tmp := Tmp;
93 end if;
94
95 --Boucle pour chaque point a dessiner
96 for I in X1_Tmp..X2_Tmp loop
97 Dessin_Point_Fractal(I, Y); --Affiche le point
98 end loop;
99
100 end Ligne_Matrice_Hori;
101
102
103 ------------------------------------------------------------------------------------------------
104 -- Nom : Ligne_Matrice_Vert --
105 -- But : rafraichire une ligne verticale de l'ecran depuis le tampon --
106 -- --
107 -- Parametres ----------------------------------------------------------------------------------
108 -- In : * La coordonnee de depart : Y1 --
109 -- * La coordonnee de la fin : Y2 --
110 -- * La coordonnee de positionement en X : X --
111 -- --
112 ------------------------------------------------------------------------------------------------
113 procedure Ligne_Matrice_Vert (Y1, Y2, X : Natural) is
114
115 --Variable temporaire
116 Y1_Tmp : Natural := Y1;
117 Y2_Tmp : Natural := Y2;
118 Tmp : Natural; --Pour le swap de valeurs
119 --
120
121 begin --Ligne_Matrice_hori
122
123 --Si Y1 est plus grand que Y2 alors permute leur valeur
124 if Y1_Tmp > Y2_Tmp then
125 Tmp := Y1_Tmp;
126 Y1_Tmp := Y2_Tmp;
127 Y2_Tmp := Tmp;
128 end if;
129
130 --Boucle pour chaque point a dessiner
131 for I in Y1_Tmp..Y2_Tmp loop
132 Dessin_Point_Fractal(X, I);
133 end loop;
134
135 end Ligne_Matrice_Vert;
136
137
138
139 ------------------------------------------------------------------------------------------------
140 -- Nom : Dessin_Croix --
141 -- But : dessiner une petite croix sur l'ecran --
142 -- --
143 -- Parametres ----------------------------------------------------------------------------------
144 -- In : Les coordonnees de la croix : X et Y --
145 -- --
146 ------------------------------------------------------------------------------------------------
147 procedure Dessin_Croix (X, Y : Natural) is
148 Color_Back : Spider.Draw.Tcolor; --La couleur au format spider
149 begin --Dessin_croix
150
151 --Si la croix peut-etre dessine (il faut tenir compte de son rayon : Rayon_Ext_Croix)
152 if X in 0 + Rayon_Ext_Croix..Largeur_Ecran - Rayon_Ext_Croix
153 and Y in 0 + Rayon_Ext_Croix ..Hauteur_Ecran - Rayon_Ext_Croix then
154
155 --Copie les composantes RGB du point dans la variable au format spider
156 Color_Back.R := Integer(Matrice_Tampon_Ecran(X, Y).R);
157 Color_Back.G := Integer(Matrice_Tampon_Ecran(X, Y).G);
158 Color_Back.B := Integer(Matrice_Tampon_Ecran(X, Y).B);
159 --
160
161 Power_Colors.Inverse_Couleur(Color_Back); --Inverse la couleur
162
163 Set_Color_Pen(Color_Back); --Defini la couleur du pinceau
164
165 --Trace la croix en fonction de la constante du rayon interne : Rayon_Int_Croix
166 --et de la constante du rayon interne : Rayon_Int_Croix
167 Line_To(X - Rayon_Ext_Croix ,Y , X - Rayon_Int_Croix , Y);
168 Line_To(X + Rayon_Ext_Croix ,Y , X + Rayon_Int_Croix , Y);
169 Line_To(X ,Y - Rayon_Ext_Croix , X , Y - Rayon_Int_Croix);
170 Line_To(X ,Y + Rayon_Ext_Croix , X , Y + Rayon_Int_Croix);
171 --
172 end if;
173
174 end Dessin_Croix;
175
176 ------------------------------------------------------------------------------------------------
177 -- Nom : Efface_Croix --
178 -- But : Effacer la croix qui a au paravant ete dessine en X, Y --
179 -- --
180 -- Parametres ----------------------------------------------------------------------------------
181 -- In : * Les coordonnees de la croix a effacer : X, Y --
182 -- --
183 ------------------------------------------------------------------------------------------------
184 procedure Efface_Croix (X, Y : Natural) is
185 begin -- Efface_Croix
186
187 --Si le point xy est un point ou une croix a put etre dessine
188 if X in 0 + Rayon_Ext_Croix..Largeur_Ecran - Rayon_Ext_Croix and Y in 0
189 + Rayon_Ext_Croix ..Hauteur_Ecran - Rayon_Ext_Croix then
190
191 --Efface la croix, en dessinant par dessus une nouvelle croix mais par rapport au tampon
192 Ligne_Matrice_Hori(X - Rayon_Ext_Croix, X - Rayon_Int_Croix, Y);
193 Ligne_Matrice_Hori(X + Rayon_Ext_Croix, X + Rayon_Int_Croix, Y);
194 Ligne_Matrice_Vert(Y - Rayon_Ext_Croix, Y - Rayon_Int_Croix, X);
195 Ligne_Matrice_Vert(Y + Rayon_Ext_Croix, Y + Rayon_Int_Croix, X);
196 --
197
198 end if;
199 end Efface_Croix;
200
201 end Power_Draw;