Premier commit
[powerfractal.git] / CD / 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
15 package body Power_Colors is
16
17 ------------------------------------------------------------------------------------------------
18 -- Nom : Inverse_Couleur --
19 -- But : Inverser une couleur RGB --
20 -- --
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;
29 end Inverse_Couleur;
30
31 ------------------------------------------------------------------------------------------------
32 -- Nom : Creer_Degrade --
33 -- But : Creer un tableau de degrade de couleur en fonction de couleur determinee --
34 -- --
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
42
43 ---------------------------------------------------------------------------------------------
44 -- Nom : Limite --
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
50 begin -- Limite
51 if Nombre < Limite_Min then
52 return Byte(Limite_Min);
53 elsif Nombre > Limite_Max then
54 return Byte(Limite_Max);
55 else
56 return Byte(Nombre);
57 end if;
58 end Limite;
59
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
63
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);
70
71 begin -- Creer_Degrader
72
73
74 -- Tant que ca n'est pas la derniere partie du degrade
75 while Coul_Frac_Courant < Fractal.Couleur'Last loop
76
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);
84
85 -- Parcours de toute les couleurs dans la partie courante
86 while Coul_Deg_Courant /= Nb_Coul_Partie * Coul_Frac_Courant loop
87
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)));
92
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)));
96
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)));
100
101 Coul_Deg_Courant := Coul_Deg_Courant + 1; -- Couleur du degrade suivante
102 end loop;
103
104 Coul_Frac_Courant := Coul_Frac_Courant + 1; -- Partie du degrade suivante
105 end loop;
106
107
108 -- Attribue la couleur jusqu'a la fin du degrade
109 while Coul_Deg_Courant < Degrade'Last loop
110
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)));
115
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)));
119
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)));
123
124 Coul_Deg_Courant := Coul_Deg_Courant + 1;
125
126 end loop;
127
128 Degrade(Degrade'Last) := (0, 0, 0);
129 end Creer_Degrade;
130
131
132 ------------------------------------------------------------------------------------------------
133 -- Nom : Affiche_Degrade --
134 -- But : Affiche le degrade sur la longueur demandé sur 5 pixels de hauteur --
135 -- --
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));
141 begin
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);
146 end loop;
147 end loop;
148
149 end Affiche_Degrade;
150
151
152 ------------------------------------------------------------------------------------------------
153 -- Nom : Conversion_Couleur --
154 -- But : Convertit une matrice d'iteration en une matrice de couleur --
155 -- --
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
164
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));
170 end loop;
171 end loop;
172 return Matrice_Tampon;
173 end Conversion_Couleur;
174
175 end Power_Colors;