------------------------------------------------------------------------------------------------ -- Nom : Power_Colors / fait partie du programme Power Fractal -- -- -- -- Auteurs : Gregory Burri & Adrien Crivelli -- ------------------------------------------------------------------------------------------------ -- But : Outils servant a la gestion des couleurs et des degradés -- ------------------------------------------------------------------------------------------------ --Enfant de spider Pour gerer la couleur et le dessin with Spider.Draw; with Power_Types; use Power_Types; package body Power_Colors is ------------------------------------------------------------------------------------------------ -- Nom : Inverse_Couleur -- -- But : Inverser une couleur RGB -- -- -- -- Parametres ---------------------------------------------------------------------------------- -- In-out : * La couleur -- ------------------------------------------------------------------------------------------------ procedure Inverse_Couleur (Couleur : in out Spider.Draw.Tcolor) is begin --Inverse_Couleur Couleur.R := 255 - Couleur.R; Couleur.G := 255 - Couleur.G; Couleur.B := 255 - Couleur.B; end Inverse_Couleur; ------------------------------------------------------------------------------------------------ -- Nom : Creer_Degrade -- -- But : Creer un tableau de degrade de couleur en fonction de couleur determinee -- -- -- -- Parametres ---------------------------------------------------------------------------------- -- In : * La fractal -- -- * La longueur du degrade -- -- Out : * Le degrade de couleur -- ------------------------------------------------------------------------------------------------ procedure Creer_Degrade (Fractal : in Cara_Fractal; Degrade : out T_Tab_Couleur; Longueur : in Integer) is --------------------------------------------------------------------------------------------- -- Nom : Limite -- -- But : Empeche le depassement des limites fixées -- --------------------------------------------------------------------------------------------- function Limite ( Nombre : in Integer) return Byte is Limite_Min : constant := 0; -- Limite inferieure Limite_Max : constant := 255;-- Limite superieure begin -- Limite if Nombre < Limite_Min then return Byte(Limite_Min); elsif Nombre > Limite_Max then return Byte(Limite_Max); else return Byte(Nombre); end if; end Limite; Pas_R : Float; -- Pour le pas de la couleur rouge Pas_G : Float; -- Pour le pas de la couleur verte Pas_B : Float; -- Pour le pas de la couleur bleue -- Numero de la couleur courante des couleurs choisie Coul_Frac_Courant : Natural := Fractal.Couleur'First; -- Numero de la couleur courante du degrade Coul_Deg_Courant : Natural := Degrade'First; -- Nombre de couleur dans une partie du degrade Nb_Coul_Partie : Natural := Longueur / (Fractal.Couleur'Length - 1); begin -- Creer_Degrader -- Tant que ca n'est pas la derniere partie du degrade while Coul_Frac_Courant < Fractal.Couleur'Last loop -- Definis le pas de la partie du degrade courante pour chaque composante Pas_R := (Float(Fractal.Couleur(Coul_Frac_Courant + 1).R) - Float(Fractal.Couleur(Coul_Frac_Courant).R)) / Float(Nb_Coul_Partie); Pas_G := (Float(Fractal.Couleur(Coul_Frac_Courant + 1).G) - Float(Fractal.Couleur(Coul_Frac_Courant).G)) / Float(Nb_Coul_Partie); Pas_B := (Float(Fractal.Couleur(Coul_Frac_Courant + 1).B) - Float(Fractal.Couleur(Coul_Frac_Courant).B)) / Float(Nb_Coul_Partie); -- Parcours de toute les couleurs dans la partie courante while Coul_Deg_Courant /= Nb_Coul_Partie * Coul_Frac_Courant loop -- Attribution de la couleur a la couleur courante en fonction du Pas Degrade(Coul_Deg_Courant).R := Limite(Integer(Fractal.Couleur(Coul_Frac_Courant).R) + Integer( Pas_R * Float(Coul_Deg_Courant - (Coul_Frac_Courant - 1) * Nb_Coul_Partie - 1))); Degrade(Coul_Deg_Courant).G := Limite(Integer(Fractal.Couleur(Coul_Frac_Courant).G) + Integer( Pas_G * Float(Coul_Deg_Courant - (Coul_Frac_Courant - 1) * Nb_Coul_Partie - 1))); Degrade(Coul_Deg_Courant).B := Limite(Integer(Fractal.Couleur(Coul_Frac_Courant).B) + Integer( Pas_B * Float(Coul_Deg_Courant - (Coul_Frac_Courant - 1) * Nb_Coul_Partie - 1))); Coul_Deg_Courant := Coul_Deg_Courant + 1; -- Couleur du degrade suivante end loop; Coul_Frac_Courant := Coul_Frac_Courant + 1; -- Partie du degrade suivante end loop; -- Attribue la couleur jusqu'a la fin du degrade while Coul_Deg_Courant < Degrade'Last loop -- Attribution de la couleur a la couleur courante en fonction du Pas Degrade(Coul_Deg_Courant).R := Limite(Integer(Fractal.Couleur(Coul_Frac_Courant).R) + Integer( Pas_R * Float(Coul_Deg_Courant - (Coul_Frac_Courant - 1) * Nb_Coul_Partie - 1))); Degrade(Coul_Deg_Courant).G := Limite(Integer(Fractal.Couleur(Coul_Frac_Courant).G) + Integer( Pas_G * Float(Coul_Deg_Courant - (Coul_Frac_Courant - 1) * Nb_Coul_Partie - 1))); Degrade(Coul_Deg_Courant).B := Limite(Integer(Fractal.Couleur(Coul_Frac_Courant).B) + Integer( Pas_B * Float(Coul_Deg_Courant - (Coul_Frac_Courant - 1) * Nb_Coul_Partie - 1))); Coul_Deg_Courant := Coul_Deg_Courant + 1; end loop; Degrade(Degrade'Last) := (0, 0, 0); end Creer_Degrade; ------------------------------------------------------------------------------------------------ -- Nom : Affiche_Degrade -- -- But : Affiche le degrade sur la longueur demandé sur 5 pixels de hauteur -- -- -- -- Parametres ---------------------------------------------------------------------------------- -- In : * La fractal -- ------------------------------------------------------------------------------------------------ procedure Affiche_Degrade (Fractal : in Cara_Fractal) is Degrade : T_Tab_Couleur(Matrice_Tampon_Ecran'range(1)); begin Creer_Degrade(Fractal, Degrade, Largeur_Ecran); for X in Degrade'range loop for Y in 0 .. Hauteur_Degrade loop Matrice_Tampon_Ecran(X, Y) := Degrade(X); end loop; end loop; end Affiche_Degrade; ------------------------------------------------------------------------------------------------ -- Nom : Conversion_Couleur -- -- But : Convertit une matrice d'iteration en une matrice de couleur -- -- -- -- Parametres ---------------------------------------------------------------------------------- -- In : * La matrice d'iteration -- -- : * Le degrade de couleur -- -- return : Une matrice de couleur -- ------------------------------------------------------------------------------------------------ function Conversion_Couleur (Matrice : in T_Matrice_Iteration; Degrade : in T_Tab_Couleur) return T_Matrice_Tampon is Matrice_Tampon : T_Matrice_Tampon (Matrice'range(1), Matrice'range(2)); begin -- Conversion_Couleur for X in Matrice'range(1) loop for Y in Matrice'range(2) loop Matrice_Tampon(X, Y) := Degrade(Matrice(X, Y)); end loop; end loop; return Matrice_Tampon; end Conversion_Couleur; end Power_Colors;