DEL remove useless code
[powerfractal.git] / Src / Power_Colors.adb
1 ------------------------------------------------------------------------------------------------
2 -- Nom : Power_Colors / fait partie du programme Power Fractal --
3 -- --
4 -- Auteurs : Gregory Burri & Adrien Crivelli --
5 ------------------------------------------------------------------------------------------------
6 -- But : Outils servant a la gestion des couleurs et des degradés --
7 ------------------------------------------------------------------------------------------------
8
9
10 --Enfant de spider Pour gerer la couleur et le dessin
11 with Spider.Draw;
12
13 with Power_Types; use Power_Types;
14 with ada.integer_text_io; use ada.integer_text_io;
15 with ada.text_io; use ada.text_io;
16 with ada.float_text_io; use ada.float_text_io;
17 with power_draw;
18
19 package body Power_Colors is
20
21 ------------------------------------------------------------------------------------------------
22 -- Nom : Inverse_Couleur --
23 -- But : Inverser une couleur RGB --
24 -- --
25 -- Parametres ----------------------------------------------------------------------------------
26 -- In-out : * La couleur --
27 ------------------------------------------------------------------------------------------------
28 procedure Inverse_Couleur (Couleur : in out Spider.Draw.Tcolor) is
29 begin --Inverse_Couleur
30 Couleur.R := 255 - Couleur.R;
31 Couleur.G := 255 - Couleur.G;
32 Couleur.B := 255 - Couleur.B;
33 end Inverse_Couleur;
34
35 ------------------------------------------------------------------------------------------------
36 -- Nom : Creer_Degrade --
37 -- But : Creer un tableau de degrade de couleur en fonction de couleur determinee --
38 -- --
39 -- Parametres ----------------------------------------------------------------------------------
40 -- In : * La fractal --
41 -- * La longueur du degrade --
42 -- Out : * Le degrade de couleur --
43 ------------------------------------------------------------------------------------------------
44 -- procedure Creer_Degrade (Fractal : in Cara_Fractal;
45 -- Degrade : out T_Tab_Couleur; Longueur : in Integer) is
46 --
47 --
48 -- Pas_R : Float; -- Pour le pas de la couleur rouge
49 -- Pas_G : Float; -- Pour le pas de la couleur verte
50 -- Pas_B : Float; -- Pour le pas de la couleur bleue
51 --
52 -- -- Numero de la couleur courante des couleurs choisie
53 -- Coul_Frac_Courant : Natural := Fractal.Couleur'First;
54 -- -- Numero de la couleur courante du degrade
55 -- Coul_Deg_Courant : Natural := Degrade'First;
56 -- -- Nombre de couleur dans une partie du degrade
57 -- Nb_Coul_Partie : Natural := Longueur / (Fractal.Couleur'Length - 1);
58 --
59 -- begin -- Creer_Degrader
60 --
61 --
62 -- -- Tant que ca n'est pas la derniere partie du degrade
63 -- while Coul_Frac_Courant < Fractal.Couleur'Last loop
64 --
65 -- -- Definis le pas de la partie du degrade courante pour chaque composante
66 -- Pas_R := (Float(Fractal.Couleur(Coul_Frac_Courant + 1).R) -
67 -- Float(Fractal.Couleur(Coul_Frac_Courant).R)) / Float(Nb_Coul_Partie);
68 -- Pas_G := (Float(Fractal.Couleur(Coul_Frac_Courant + 1).G) -
69 -- Float(Fractal.Couleur(Coul_Frac_Courant).G)) / Float(Nb_Coul_Partie);
70 -- Pas_B := (Float(Fractal.Couleur(Coul_Frac_Courant + 1).B) -
71 -- Float(Fractal.Couleur(Coul_Frac_Courant).B)) / Float(Nb_Coul_Partie);
72 --
73 -- -- Parcours de toute les couleurs dans la partie courante
74 -- while Coul_Deg_Courant /= Nb_Coul_Partie * Coul_Frac_Courant loop
75 --
76 -- -- Attribution de la couleur a la couleur courante en fonction du Pas
77 -- Degrade(Coul_Deg_Courant).R :=
78 -- Limite(Integer(Fractal.Couleur(Coul_Frac_Courant).R) + Integer(
79 -- Pas_R * Float(Coul_Deg_Courant - (Coul_Frac_Courant - 1) * Nb_Coul_Partie - 1)));
80 --
81 -- Degrade(Coul_Deg_Courant).G :=
82 -- Limite(Integer(Fractal.Couleur(Coul_Frac_Courant).G) + Integer(
83 -- Pas_G * Float(Coul_Deg_Courant - (Coul_Frac_Courant - 1) * Nb_Coul_Partie - 1)));
84 --
85 -- Degrade(Coul_Deg_Courant).B :=
86 -- Limite(Integer(Fractal.Couleur(Coul_Frac_Courant).B) + Integer(
87 -- Pas_B * Float(Coul_Deg_Courant - (Coul_Frac_Courant - 1) * Nb_Coul_Partie - 1)));
88 --
89 -- Coul_Deg_Courant := Coul_Deg_Courant + 1; -- Couleur du degrade suivante
90 -- end loop;
91 --
92 -- Coul_Frac_Courant := Coul_Frac_Courant + 1; -- Partie du degrade suivante
93 -- end loop;
94 --
95 --
96 -- -- Attribue la couleur jusqu'a la fin du degrade
97 -- while Coul_Deg_Courant < Degrade'Last loop
98 --
99 -- -- Attribution de la couleur a la couleur courante en fonction du Pas
100 -- Degrade(Coul_Deg_Courant).R :=
101 -- Limite(Integer(Fractal.Couleur(Coul_Frac_Courant).R) + Integer(
102 -- Pas_R * Float(Coul_Deg_Courant - (Coul_Frac_Courant - 1) * Nb_Coul_Partie - 1)));
103 --
104 -- Degrade(Coul_Deg_Courant).G :=
105 -- Limite(Integer(Fractal.Couleur(Coul_Frac_Courant).G) + Integer(
106 -- Pas_G * Float(Coul_Deg_Courant - (Coul_Frac_Courant - 1) * Nb_Coul_Partie - 1)));
107 --
108 -- Degrade(Coul_Deg_Courant).B :=
109 -- Limite(Integer(Fractal.Couleur(Coul_Frac_Courant).B) + Integer(
110 -- Pas_B * Float(Coul_Deg_Courant - (Coul_Frac_Courant - 1) * Nb_Coul_Partie - 1)));
111 --
112 -- Coul_Deg_Courant := Coul_Deg_Courant + 1;
113 --
114 -- end loop;
115 --
116 -- Degrade(Degrade'Last) := (0, 0, 0);
117 -- end Creer_Degrade;
118
119
120 ------------------------------------------------------------------------------------------------
121 -- Nom : Affiche_Degrade --
122 -- But : Affiche le degrade sur la longueur demandé sur 5 pixels de hauteur --
123 -- --
124 -- Parametres ----------------------------------------------------------------------------------
125 -- In : * La fractal --
126 ------------------------------------------------------------------------------------------------
127 procedure Affiche_Degrade (Fractal : in Cara_Fractal) is
128 Degrade : T_Tab_Couleur(Matrice_Tampon_Ecran'range(1));
129 begin
130 -- Creer_Degrade(Fractal, Degrade, Largeur_Ecran);
131 for X in Degrade'range loop
132 for Y in 0 .. Hauteur_Degrade loop
133 Matrice_Tampon_Ecran(X, Y) := Degrade(X);
134 end loop;
135 end loop;
136
137 end Affiche_Degrade;
138
139
140 ------------------------------------------------------------------------------------------------
141 -- Nom : Conversion_Couleur --
142 -- But : Convertit une matrice d'iteration en une matrice de couleur --
143 -- --
144 -- Parametres ----------------------------------------------------------------------------------
145 -- In : * La matrice d'iteration --
146 -- : * Le degrade de couleur --
147 -- return : Une matrice de couleur --
148 ------------------------------------------------------------------------------------------------
149 function Conversion_Couleur (Matrice : in T_Matrice_Iteration;
150 fractal : in Cara_fractal)
151 return T_Matrice_Tampon is
152
153 ---------------------------------------------------------------------------------------------
154 -- Nom : Limite --
155 -- But : Empeche le depassement des limites fixées --
156 ---------------------------------------------------------------------------------------------
157 function Limite ( Nombre : in float) return Byte is
158 Limite_Min : constant := 0.0; -- Limite inferieure
159 Limite_Max : constant := 255.0;-- Limite superieure
160 begin -- Limite
161 if Nombre < Limite_Min then
162 return Byte(Limite_Min);
163 put("LIMITE ");
164 elsif Nombre > Limite_Max then
165 return Byte(Limite_Max);
166 put("LIMITE ");
167 else
168 return Byte(Nombre);
169 end if;
170 end Limite;
171
172
173 Matrice_Tampon : T_Matrice_Tampon (Matrice'range(1), Matrice'range(2));
174 partie : integer;
175 pourcentage : float;
176 tmp : float;
177 tmp_2 : float;
178 nb_coul_partie : float := float(fractal.nb_iteration_max) / float(fractal.nb_couleur - 1);
179 begin -- Conversion_Couleur
180
181 for X in Matrice'range(1) loop
182 for Y in Matrice'range(2) loop
183 Partie := 1;
184 --Matrice_Tampon(X, Y) := Degrade(integer(Matrice(X, Y)));
185
186
187 -- Trouve entre quelle couleur definie (partie) se trouve la couleur courante
188 while matrice(x, y) not in nb_coul_partie * float(partie - 1) .. nb_coul_partie * float(partie) loop
189 partie := partie + 1;
190 if partie = fractal.nb_couleur then
191 exit;
192 end if;
193 end loop;
194
195
196 pourcentage := (matrice(x, y) - (nb_coul_partie * float(partie - 1))) / nb_coul_partie;
197
198
199 tmp_2 := float(fractal.couleur(partie + 1).r) - float(fractal.couleur(partie).r);
200 tmp := tmp_2 * pourcentage + float(fractal.couleur(partie).r);
201 matrice_tampon(x, y).r := limite(tmp);
202
203 tmp_2 := float(fractal.couleur(partie + 1).g) - float(fractal.couleur(partie).g);
204 tmp := tmp_2 * pourcentage + float(fractal.couleur(partie).g);
205 matrice_tampon(x, y).g := limite(tmp);
206
207 tmp_2 := float(fractal.couleur(partie + 1).b) - float(fractal.couleur(partie).b);
208 tmp := tmp_2 * pourcentage + float(fractal.couleur(partie).b);
209 matrice_tampon(x, y).b := limite(tmp);
210
211 end loop;
212 end loop;
213 return Matrice_Tampon;
214 end Conversion_Couleur;
215
216 end Power_Colors;