------------------------------------------------------------------------------------------------ -- 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; with ada.integer_text_io; use ada.integer_text_io; with ada.text_io; use ada.text_io; with ada.float_text_io; use ada.float_text_io; with power_draw; 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 -- -- -- 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; fractal : in Cara_fractal) return T_Matrice_Tampon is --------------------------------------------------------------------------------------------- -- Nom : Limite -- -- But : Empeche le depassement des limites fixées -- --------------------------------------------------------------------------------------------- function Limite ( Nombre : in float) return Byte is Limite_Min : constant := 0.0; -- Limite inferieure Limite_Max : constant := 255.0;-- Limite superieure begin -- Limite if Nombre < Limite_Min then return Byte(Limite_Min); put("LIMITE "); elsif Nombre > Limite_Max then return Byte(Limite_Max); put("LIMITE "); else return Byte(Nombre); end if; end Limite; Matrice_Tampon : T_Matrice_Tampon (Matrice'range(1), Matrice'range(2)); partie : integer; pourcentage : float; tmp : float; tmp_2 : float; nb_coul_partie : float := float(fractal.nb_iteration_max) / float(fractal.nb_couleur - 1); begin -- Conversion_Couleur for X in Matrice'range(1) loop for Y in Matrice'range(2) loop Partie := 1; --Matrice_Tampon(X, Y) := Degrade(integer(Matrice(X, Y))); -- Trouve entre quelle couleur definie (partie) se trouve la couleur courante while matrice(x, y) not in nb_coul_partie * float(partie - 1) .. nb_coul_partie * float(partie) loop partie := partie + 1; if partie = fractal.nb_couleur then exit; end if; end loop; pourcentage := (matrice(x, y) - (nb_coul_partie * float(partie - 1))) / nb_coul_partie; tmp_2 := float(fractal.couleur(partie + 1).r) - float(fractal.couleur(partie).r); tmp := tmp_2 * pourcentage + float(fractal.couleur(partie).r); matrice_tampon(x, y).r := limite(tmp); tmp_2 := float(fractal.couleur(partie + 1).g) - float(fractal.couleur(partie).g); tmp := tmp_2 * pourcentage + float(fractal.couleur(partie).g); matrice_tampon(x, y).g := limite(tmp); tmp_2 := float(fractal.couleur(partie + 1).b) - float(fractal.couleur(partie).b); tmp := tmp_2 * pourcentage + float(fractal.couleur(partie).b); matrice_tampon(x, y).b := limite(tmp); end loop; end loop; return Matrice_Tampon; end Conversion_Couleur; end Power_Colors;