b0c105182a8a5de1b642983a35feb618a2dac0db
1 ------------------------------------------------------------------------------------------------
2 -- Nom : Power_Colors / fait partie du programme Power Fractal --
4 -- Auteurs : Gregory Burri & Adrien Crivelli --
5 ------------------------------------------------------------------------------------------------
6 -- But : Outils servant a la gestion des couleurs et des degradés --
7 ------------------------------------------------------------------------------------------------
10 --Enfant de spider Pour gerer la couleur et le dessin
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
;
19 package body Power_Colors
is
21 ------------------------------------------------------------------------------------------------
22 -- Nom : Inverse_Couleur --
23 -- But : Inverser une couleur RGB --
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
;
35 ------------------------------------------------------------------------------------------------
36 -- Nom : Creer_Degrade --
37 -- But : Creer un tableau de degrade de couleur en fonction de couleur determinee --
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
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
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);
59 -- begin -- Creer_Degrader
62 -- -- Tant que ca n'est pas la derniere partie du degrade
63 -- while Coul_Frac_Courant < Fractal.Couleur'Last loop
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);
73 -- -- Parcours de toute les couleurs dans la partie courante
74 -- while Coul_Deg_Courant /= Nb_Coul_Partie * Coul_Frac_Courant loop
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)));
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)));
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)));
89 -- Coul_Deg_Courant := Coul_Deg_Courant + 1; -- Couleur du degrade suivante
92 -- Coul_Frac_Courant := Coul_Frac_Courant + 1; -- Partie du degrade suivante
96 -- -- Attribue la couleur jusqu'a la fin du degrade
97 -- while Coul_Deg_Courant < Degrade'Last loop
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)));
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)));
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)));
112 -- Coul_Deg_Courant := Coul_Deg_Courant + 1;
116 -- Degrade(Degrade'Last) := (0, 0, 0);
117 -- end Creer_Degrade;
120 ------------------------------------------------------------------------------------------------
121 -- Nom : Affiche_Degrade --
122 -- But : Affiche le degrade sur la longueur demandé sur 5 pixels de hauteur --
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));
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
);
140 ------------------------------------------------------------------------------------------------
141 -- Nom : Conversion_Couleur --
142 -- But : Convertit une matrice d'iteration en une matrice de couleur --
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
153 ---------------------------------------------------------------------------------------------
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
161 if Nombre
< Limite_Min
then
162 return Byte(Limite_Min
);
164 elsif Nombre
> Limite_Max
then
165 return Byte(Limite_Max
);
173 Matrice_Tampon
: T_Matrice_Tampon (Matrice
'range(1), Matrice
'range(2));
178 nb_coul_partie
: float := float(fractal
.nb_iteration_max
) / float(fractal
.nb_couleur
- 1);
179 begin -- Conversion_Couleur
181 for X
in Matrice
'range(1) loop
182 for Y
in Matrice
'range(2) loop
184 --Matrice_Tampon(X, Y) := Degrade(integer(Matrice(X, Y)));
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
196 pourcentage
:= (matrice(x
, y
) - (nb_coul_partie
* float(partie
- 1))) / nb_coul_partie
;
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
);
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
);
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
);
213 -- put(integer(partie), 0);
215 -- put(pourcentage, 0, 2, 0);
217 -- put(matrice(x, y), 8, 2, 0);
218 -- put(integer(matrice_tampon(x, y).r));
230 return Matrice_Tampon
;
231 end Conversion_Couleur
;