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
;
15 package body Power_Colors
is
17 ------------------------------------------------------------------------------------------------
18 -- Nom : Inverse_Couleur --
19 -- But : Inverser une couleur RGB --
21 -- Parametres ----------------------------------------------------------------------------------
22 -- In-out : * La couleur --
23 ------------------------------------------------------------------------------------------------
24 procedure Inverse_Couleur (Couleur
: in out Spider
.Draw
.Tcolor
) is
25 begin --Inverse_Couleur
26 Couleur
.R
:= 255 - Couleur
.R
;
27 Couleur
.G
:= 255 - Couleur
.G
;
28 Couleur
.B
:= 255 - Couleur
.B
;
31 ------------------------------------------------------------------------------------------------
32 -- Nom : Creer_Degrade --
33 -- But : Creer un tableau de degrade de couleur en fonction de couleur determinee --
35 -- Parametres ----------------------------------------------------------------------------------
36 -- In : * La fractal --
37 -- * La longueur du degrade --
38 -- Out : * Le degrade de couleur --
39 ------------------------------------------------------------------------------------------------
40 procedure Creer_Degrade (Fractal
: in Cara_Fractal
;
41 Degrade
: out T_Tab_Couleur
; Longueur
: in Integer) is
43 ---------------------------------------------------------------------------------------------
45 -- But : Empeche le depassement des limites fixées --
46 ---------------------------------------------------------------------------------------------
47 function Limite ( Nombre
: in Integer) return Byte
is
48 Limite_Min
: constant := 0; -- Limite inferieure
49 Limite_Max
: constant := 255;-- Limite superieure
51 if Nombre
< Limite_Min
then
52 return Byte(Limite_Min
);
53 elsif Nombre
> Limite_Max
then
54 return Byte(Limite_Max
);
60 Pas_R
: Float; -- Pour le pas de la couleur rouge
61 Pas_G
: Float; -- Pour le pas de la couleur verte
62 Pas_B
: Float; -- Pour le pas de la couleur bleue
64 -- Numero de la couleur courante des couleurs choisie
65 Coul_Frac_Courant
: Natural := Fractal
.Couleur
'First;
66 -- Numero de la couleur courante du degrade
67 Coul_Deg_Courant
: Natural := Degrade
'First;
68 -- Nombre de couleur dans une partie du degrade
69 Nb_Coul_Partie
: Natural := Longueur
/ (Fractal
.Couleur
'Length - 1);
71 begin -- Creer_Degrader
74 -- Tant que ca n'est pas la derniere partie du degrade
75 while Coul_Frac_Courant
< Fractal
.Couleur
'Last loop
77 -- Definis le pas de la partie du degrade courante pour chaque composante
78 Pas_R
:= (Float(Fractal
.Couleur(Coul_Frac_Courant
+ 1).R
) -
79 Float(Fractal
.Couleur(Coul_Frac_Courant
).R
)) / Float(Nb_Coul_Partie
);
80 Pas_G
:= (Float(Fractal
.Couleur(Coul_Frac_Courant
+ 1).G
) -
81 Float(Fractal
.Couleur(Coul_Frac_Courant
).G
)) / Float(Nb_Coul_Partie
);
82 Pas_B
:= (Float(Fractal
.Couleur(Coul_Frac_Courant
+ 1).B
) -
83 Float(Fractal
.Couleur(Coul_Frac_Courant
).B
)) / Float(Nb_Coul_Partie
);
85 -- Parcours de toute les couleurs dans la partie courante
86 while Coul_Deg_Courant
/= Nb_Coul_Partie
* Coul_Frac_Courant
loop
88 -- Attribution de la couleur a la couleur courante en fonction du Pas
89 Degrade(Coul_Deg_Courant
).R
:=
90 Limite(Integer(Fractal
.Couleur(Coul_Frac_Courant
).R
) + Integer(
91 Pas_R
* Float(Coul_Deg_Courant
- (Coul_Frac_Courant
- 1) * Nb_Coul_Partie
- 1)));
93 Degrade(Coul_Deg_Courant
).G
:=
94 Limite(Integer(Fractal
.Couleur(Coul_Frac_Courant
).G
) + Integer(
95 Pas_G
* Float(Coul_Deg_Courant
- (Coul_Frac_Courant
- 1) * Nb_Coul_Partie
- 1)));
97 Degrade(Coul_Deg_Courant
).B
:=
98 Limite(Integer(Fractal
.Couleur(Coul_Frac_Courant
).B
) + Integer(
99 Pas_B
* Float(Coul_Deg_Courant
- (Coul_Frac_Courant
- 1) * Nb_Coul_Partie
- 1)));
101 Coul_Deg_Courant
:= Coul_Deg_Courant
+ 1; -- Couleur du degrade suivante
104 Coul_Frac_Courant
:= Coul_Frac_Courant
+ 1; -- Partie du degrade suivante
108 -- Attribue la couleur jusqu'a la fin du degrade
109 while Coul_Deg_Courant
< Degrade
'Last loop
111 -- Attribution de la couleur a la couleur courante en fonction du Pas
112 Degrade(Coul_Deg_Courant
).R
:=
113 Limite(Integer(Fractal
.Couleur(Coul_Frac_Courant
).R
) + Integer(
114 Pas_R
* Float(Coul_Deg_Courant
- (Coul_Frac_Courant
- 1) * Nb_Coul_Partie
- 1)));
116 Degrade(Coul_Deg_Courant
).G
:=
117 Limite(Integer(Fractal
.Couleur(Coul_Frac_Courant
).G
) + Integer(
118 Pas_G
* Float(Coul_Deg_Courant
- (Coul_Frac_Courant
- 1) * Nb_Coul_Partie
- 1)));
120 Degrade(Coul_Deg_Courant
).B
:=
121 Limite(Integer(Fractal
.Couleur(Coul_Frac_Courant
).B
) + Integer(
122 Pas_B
* Float(Coul_Deg_Courant
- (Coul_Frac_Courant
- 1) * Nb_Coul_Partie
- 1)));
124 Coul_Deg_Courant
:= Coul_Deg_Courant
+ 1;
128 Degrade(Degrade
'Last) := (0, 0, 0);
132 ------------------------------------------------------------------------------------------------
133 -- Nom : Affiche_Degrade --
134 -- But : Affiche le degrade sur la longueur demandé sur 5 pixels de hauteur --
136 -- Parametres ----------------------------------------------------------------------------------
137 -- In : * La fractal --
138 ------------------------------------------------------------------------------------------------
139 procedure Affiche_Degrade (Fractal
: in Cara_Fractal
) is
140 Degrade
: T_Tab_Couleur(Matrice_Tampon_Ecran
'range(1));
142 Creer_Degrade(Fractal
, Degrade
, Largeur_Ecran
);
143 for X
in Degrade
'range loop
144 for Y
in 0 .. Hauteur_Degrade
loop
145 Matrice_Tampon_Ecran(X
, Y
) := Degrade(X
);
152 ------------------------------------------------------------------------------------------------
153 -- Nom : Conversion_Couleur --
154 -- But : Convertit une matrice d'iteration en une matrice de couleur --
156 -- Parametres ----------------------------------------------------------------------------------
157 -- In : * La matrice d'iteration --
158 -- : * Le degrade de couleur --
159 -- return : Une matrice de couleur --
160 ------------------------------------------------------------------------------------------------
161 function Conversion_Couleur (Matrice
: in T_Matrice_Iteration
;
162 Degrade
: in T_Tab_Couleur
)
163 return T_Matrice_Tampon
is
165 Matrice_Tampon
: T_Matrice_Tampon (Matrice
'range(1), Matrice
'range(2));
166 begin -- Conversion_Couleur
167 for X
in Matrice
'range(1) loop
168 for Y
in Matrice
'range(2) loop
169 Matrice_Tampon(X
, Y
) := Degrade(Matrice(X
, Y
));
172 return Matrice_Tampon
;
173 end Conversion_Couleur
;