コード例 #1
0
        public async Task Determinant(Case det, Canvas c, Commentaire comPrincipal, Canvas Algo)
        /*Méthode qui traite toutes sortes de déterminants (1x1, 2x2, 3x3 et gestion des erreurs)*/
        {
            if ((nbLignes == 1) && (nbColonnes == 1))   //Matrice 1x1
            {
                det.Valeur        = tab[0, 0].Valeur;   //Determinant = valeur de la case
                det.Height        = heightOfcase * 0.5; //Mise en forme de la case du déterminant
                det.Width         = widthOfcase * 2;
                det.CoordX        = coordX - widthOfcase / 2;
                det.CoordY        = coordY + (nbLignes + 0.5) * heightOfcase;
                det.Forme.Opacity = 0;
                det.afficher(c);
                Point[] tabPoint = new Point[1];
                tabPoint[0] = new Point(coordX - widthOfcase / 2, coordY + (nbLignes + 0.5) * heightOfcase);
                await det.appear(tabPoint, 1);

                await Task.Delay(50);

                det.Forme.Opacity = 1;
                det.clignoter(Brushes.LightSkyBlue, Brushes.White, 1, 2);
                comPrincipal.Text        = "Le déterminant de la matrice est " + det.Valeur;
                comPrincipal.CouleurFond = couleurComPrincipal;
                comPrincipal.apparaitre(0);
                await Task.Delay(TimeSpan.FromSeconds(Temps.time));
            }
            else if ((nbLignes == 2) && (nbColonnes == 2))
            {
                detMat2(det, c, comPrincipal, Algo);                                                //Cas matrice 2x2
            }
            else if ((nbLignes == 3) && (nbColonnes == 3))
            {
                sarus(det, c, comPrincipal, Algo);  //Cas matrice 3x3
            }
            else if (nbLignes != nbColonnes)        //cas de la matrice qui n'est pas carrée
            {
                comPrincipal.Text        = "Impossible de calculer le déterminant\nLa matrice n'est pas carrée";
                comPrincipal.CouleurFond = Brushes.Red;
                comPrincipal.apparaitre(0);
                await Task.Delay(TimeSpan.FromSeconds(Temps.time));
            }
            else            //Cas non raités précédemment
            {
                comPrincipal.Text        = "Impossible de calculer le déterminant\nL'ordre maximal est 3";
                comPrincipal.CouleurFond = Brushes.Red;
                comPrincipal.apparaitre(0);
                await Task.Delay(TimeSpan.FromSeconds(Temps.time));
            }
        }
コード例 #2
0
        public async Task inserer(int valeur, Canvas c, Commentaire comPrincipal, Canvas Alg)
        //Insetion d'un nouvel élément dans le tableau //
        {
            int[]       tabInfo     = new int[2];
            Point[]     tab_point   = new Point[2];
            Commentaire comDecalage = new Commentaire("On décale les valeurs pour l'insertion ", Brushes.Black, this.coordX + 50, this.coordY - 50, 210, 30, Brushes.GreenYellow, Brushes.White);
            Algo        algo        = new Algo(6, coordX_Algo, coordY_Algo);
            Algo        algo1       = new Algo(27, coordX_Algo, coordY_Algo);
            int         pos;//Position d'insertion
            int         i = tailleTab;

            comPrincipal.disparaitre(0);
            if (i < tailleMaxTab)
            {
                Case nouvelleCase = new Case(valeur, coordX, this.coordY - 100, 1, heightOfcase, widthOfcase, couleurFondCase, couleurBordureCase, 1);
                if (tailleTab > 0)                                                //Si il exite au moins une case
                {
                    await recherche(valeur, tabInfo, c, true, comPrincipal, Alg); //Recherche Dichothomique de la valeur

                    comPrincipal.disparaitre(0);
                }
                if (tabInfo[0] == 0) //Si la valeur n'existe pas
                {
                    pos = tabInfo[1];
                    tabIndices[tailleTab].afficher(c); //Afficher le nouvel indice
                    nouvelleCase.afficher(c);          //Affichage de la nouvelle case crée
                    if (this.triee)
                    {
                        algo.afficher(Alg);
                        await algo.colorer(couleurAlgo, 0, 0.5 *Temps.time);

                        await algo.colorer(couleurAlgo, 1, Temps.time);

                        comDecalage.ajouterCanvas(c);          //Affichage du message d'insertion
                        for (i = this.tailleTab; i > pos; i--) //Décalage des cases pour insérer la nouvelle valeur
                        {
                            await algo.colorer(couleurAlgo, 2, Temps.time);

                            tab_point[0] = new Point(coordX + i * widthOfcase, coordY);
                            tab[i]       = tab[i - 1];         //Décalage interne des cases du tableau
                            tab[i - 1].deplacer(tab_point, 1); //Décalage graphique des cases du tableau
                            await algo.colorer(couleurAlgo, 3, Temps.time);

                            await Task.Delay(TimeSpan.FromSeconds(Temps.time));

                            await algo.colorer(couleurAlgo, 4, Temps.time);
                        }
                        await algo.colorer(couleurAlgo, 5, Temps.time);

                        comDecalage.enleverCanvas(c);
                        tab_point[0] = new Point(coordX + i * widthOfcase, coordY);
                        tab[i]       = nouvelleCase;
                        tab[i].deplacer(tab_point, 1);//Insértion graphique de la case
                        comPrincipal.Width       = 200;
                        comPrincipal.CouleurFond = couleurComPrincipal;
                        comPrincipal.Text        = "Insertion de la valeur ";
                        comPrincipal.apparaitre(0);
                        await algo.colorer(couleurAlgo, 6, Temps.time);

                        comPrincipal.disparaitre(0);
                        await algo.colorer(couleurAlgo, 7, Temps.time);

                        await algo.colorer(couleurAlgo, 8, 0.5 *Temps.time);

                        this.tailleTab++;//Incrémentation de la taille du tableau
                        algo.disparaitre(Alg);
                    }
                    else
                    {
                        algo1.afficher(Alg);
                        tab_point[0] = new Point(coordX + i * widthOfcase, coordY);
                        tab[i]       = nouvelleCase;
                        tab[i].deplacer(tab_point, 1);//Insértion graphique de la case
                        comPrincipal.Width       = 200;
                        comPrincipal.CouleurFond = couleurComPrincipal;
                        comPrincipal.Text        = "Insertion de la valeur ";
                        comPrincipal.apparaitre(0);
                        comPrincipal.disparaitre(0);
                        this.tailleTab++;//Incrémentation de la taille du tableau
                        algo1.disparaitre(Alg);
                    }
                }
                else
                {
                    comPrincipal.CouleurFond = couleurComPrincipal;
                    comPrincipal.Text        = "Insertion impossible , la valeur existe déja ";
                    comPrincipal.Width       = 320;
                    comPrincipal.apparaitre(0);
                    await Task.Delay(TimeSpan.FromSeconds(Temps.time + 1));

                    comPrincipal.disparaitre(0);
                }
            }
            else
            {
                comPrincipal.CouleurFond = couleurComPrincipal;
                comPrincipal.Text        = "Insertion impossible , taille du tableau maximum atteinte ";
                comPrincipal.Width       = 320;
                comPrincipal.apparaitre(0);
                await Task.Delay(TimeSpan.FromSeconds(Temps.time + 1));

                comPrincipal.disparaitre(0);
            }
        }
コード例 #3
0
        private async void detMat2(Case det, Canvas c, Commentaire comPrincipal, Canvas Algo)       //Déterminant d'une matrice 2x2
        {
            Algo algo = new Algo(31, coordX_Algo, coordY_Algo);

            algo.afficher(Algo);
            comPrincipal.Text        = "Calcul de déterminant d'une matrice 2x2...";
            comPrincipal.CouleurFond = couleurComPrincipal;
            comPrincipal.apparaitre(0);
            await algo.colorer(couleurAlgo, 0, Temps.time);

            await Task.Delay(TimeSpan.FromSeconds(Temps.time));

            TextBlock textBlock = new TextBlock();

            textBlock.FontFamily = new FontFamily("Poiret One");
            textBlock.Foreground = Brushes.Blue;
            textBlock.FontSize   = 15;
            Canvas.SetLeft(textBlock, coordX);
            Canvas.SetTop(textBlock, coordY + (nbLignes + 0.5) * heightOfcase);
            c.Children.Add(textBlock);


            await algo.colorer(couleurAlgo, 1, Temps.time);     //Clignottement des valeurs de la diagonale (sens positif)

            tab[0, 0].BackgroundColor = couleurSelection;       //et calcul du déterminant avec illustration dans le textblock
            tab[1, 1].BackgroundColor = couleurSelection;
            await Task.Delay(TimeSpan.FromSeconds(Temps.time));

            tab[0, 0].clignoter(couleurClignottement, couleurBordureCase, 1, 2);
            textBlock.Text = "(" + tab[0, 0].Valeur;
            await Task.Delay(TimeSpan.FromSeconds(Temps.time));

            tab[0, 0].BackgroundColor = couleurSelection;
            await Task.Delay(50);

            tab[1, 1].clignoter(couleurClignottement, couleurBordureCase, 1, 2);
            textBlock.Text           += " x " + tab[1, 1].Valeur + ")";
            tab[1, 1].BackgroundColor = couleurSelection;
            await Task.Delay(TimeSpan.FromSeconds(Temps.time));

            tab[0, 0].BackgroundColor = couleurFondCase;
            tab[1, 1].BackgroundColor = couleurFondCase;
            textBlock.Text           += " - (";

            tab[0, 1].BackgroundColor = couleurSelection;       //Clignottement des valeurs de la diagonale (sens négatif)
            tab[1, 0].BackgroundColor = couleurSelection;       //et calcul du déterminant avec illustration dans le textblock
            await Task.Delay(TimeSpan.FromSeconds(Temps.time));

            tab[0, 1].clignoter(couleurClignottement, couleurBordureCase, 1, 2);
            textBlock.Text += tab[0, 1].Valeur;
            await Task.Delay(TimeSpan.FromSeconds(Temps.time));

            tab[0, 1].BackgroundColor = couleurSelection;
            await Task.Delay(50);

            tab[1, 0].clignoter(couleurClignottement, couleurBordureCase, 1, 2);
            textBlock.Text           += " x " + tab[1, 0].Valeur + ")";
            tab[1, 0].BackgroundColor = couleurSelection;
            await Task.Delay(TimeSpan.FromSeconds(Temps.time));

            tab[0, 1].BackgroundColor = couleurFondCase;
            tab[1, 0].BackgroundColor = couleurFondCase;

            det.Valeur        = tab[0, 0].Valeur * tab[1, 1].Valeur - tab[1, 0].Valeur * tab[0, 1].Valeur; //Mise en forme de la case contenant le determinant
            det.Height        = heightOfcase * 0.5;
            det.Width         = widthOfcase * 2;
            det.CoordX        = coordX;
            det.CoordY        = coordY + (nbLignes + 0.5) * heightOfcase;
            det.Forme.Opacity = 0;
            det.afficher(c);
            textBlock.Text = "";
            Point[] tabPoint = new Point[1];
            tabPoint[0] = new Point(coordX, coordY + (nbLignes + 0.5) * heightOfcase);
            await det.appear(tabPoint, 1);      //Déplacement du déterminant sous la matrice

            await Task.Delay(50);

            det.Forme.Opacity = 1;
            det.clignoter(Brushes.LightSkyBlue, Brushes.White, 1, 2);      //Clignottement du résultat
            comPrincipal.Text = "Le déterminant de la matrice est " + det.Valeur;
            await algo.colorer(couleurAlgo, 2, Temps.time);

            algo.disparaitre(Algo);
        }
コード例 #4
0
        private async void sarus(Case det, Canvas c, Commentaire comPrincipal, Canvas Algo) //Déterminant par la méthode de Sarus
        {
            Algo algo = new Algo(30, coordX_Algo, coordY_Algo);                             //Affichage de l'étape en cours dans l'algo

            algo.afficher(Algo);
            comPrincipal.Text        = "Calcul de déterminant d'une matrice 3x3\npar la méthode de Sarus...";
            comPrincipal.CouleurFond = couleurComPrincipal;
            comPrincipal.apparaitre(0);
            Commentaire[] com = new Commentaire[8];
            await algo.colorer(couleurAlgo, 0, Temps.time);

            for (int i = 0; i < 3; i++)     //Affichage des commentaires d'illustration
            {
                com[i] = new Commentaire("c" + (i + 1), Brushes.Black, coordX + (i + 0.25) * widthOfcase, coordY - 30, 25, 25, couleurCom, couleurCom);
                com[i].ajouterCanvas(c);
                com[i].apparaitre(Temps.time);
                await Task.Delay(TimeSpan.FromSeconds(Temps.time));
            }
            Matrice plus = new Matrice(nbLignes, nbColonnes + 2, coordX + (nbColonnes + 1) * widthOfcase, coordY); //Création d'une matrice 3x5 contentant

            for (int i = 0; i < plus.nbLignes; i++)                                                                //les colonnes c1, c2, c3, c1, c2
            {
                for (int j = 0; j < nbColonnes + 2; j++)
                {
                    plus.tab[i, j] = new Case(tab[i, j % nbColonnes].Valeur, plus.coordX + j * widthOfcase, plus.coordY + i * heightOfcase, 1, heightOfcase, widthOfcase, couleurFondCase, couleurBordureCase, 1);
                }
            }
            plus.afficher(c);
            await Task.Delay(TimeSpan.FromSeconds(Temps.time)); //Affichage des commentaires d'illustration

            for (int i = 0; i < 3; i++)
            {
                com[i + 3] = new Commentaire("c" + (i + 1), Brushes.Black, plus.coordX + (i + 0.25) * widthOfcase, plus.coordY - 30, 25, 25, couleurCom, couleurCom);
                com[i + 3].ajouterCanvas(c);
                com[i + 3].apparaitre(Temps.time);
                await Task.Delay(TimeSpan.FromSeconds(Temps.time));
            }
            for (int i = 0; i < 2; i++)
            {
                com[i + 6] = new Commentaire("c" + (i + 1), Brushes.Black, plus.coordX + (i + 3 + 0.25) * widthOfcase, plus.coordY - 30, 25, 25, Brushes.LightPink, Brushes.White);
                com[i + 6].ajouterCanvas(c);
                com[i + 6].apparaitre(Temps.time);
                await Task.Delay(TimeSpan.FromSeconds(Temps.time));
            }
            TextBlock textBlock = new TextBlock();      //Textblock pour affichier l'opération en cours

            textBlock.FontFamily = new FontFamily("Poiret One");
            textBlock.Foreground = Brushes.Blue;
            Canvas.SetLeft(textBlock, coordX);
            Canvas.SetTop(textBlock, plus.coordY + (nbLignes + 1) * heightOfcase);
            c.Children.Add(textBlock);
            await Task.Delay(TimeSpan.FromSeconds(Temps.time));

            int b = 1;

            for (int i = 0; i < 3; i++)     //Parcours des diagonales de gauche à droite (sens positif)
            {
                int j;
                b = 1;
                await algo.colorer(couleurAlgo, 1, 0.5 *Temps.time);        //Affichage de l'étape en cours dans l'algo

                await algo.colorer(couleurAlgo, 2, 0.5 *Temps.time);

                for (j = 0; j < 3; j++)
                {
                    plus.tab[j, j + i].BackgroundColor = couleurSelection;
                }
                await Task.Delay(TimeSpan.FromSeconds(Temps.time));

                for (j = 0; j < 3; j++)     //Cases de la diagonale
                {
                    await algo.colorer(couleurAlgo, 3, 0.5 *Temps.time);

                    plus.tab[j, j + i].clignoter(couleurClignottement, plus.couleurBordureCase, plus.tab[j, j + i].BorderThick, 2); //clignottement de la case
                    textBlock.FontSize = 15;                                                                                        //Et affichage de l'opération dans le textBlock
                    if (j != 0 && j != 2)
                    {
                        textBlock.Text += " x " + plus.tab[j, j + i].Valeur.ToString();
                    }
                    else if (j != 0 && j == 2)
                    {
                        textBlock.Text += " x " + plus.tab[j, j + i].Valeur.ToString() + ")";
                    }
                    else if (i != 0)
                    {
                        textBlock.Text += plus.tab[j, j + i].Valeur.ToString();
                    }
                    else if (i == 0)
                    {
                        textBlock.Text = "(" + plus.tab[j, j + i].Valeur.ToString();
                    }
                    await algo.colorer(couleurAlgo, 4, Temps.time);     //étape en cours dans l'algo

                    if (i != 2 && j == 2)
                    {
                        textBlock.Text += " + (";
                    }
                    plus.tab[j, j + i].colorChamp(couleurSelection, plus.couleurBordureCase, 1);
                    b = b * plus.tab[j, j + i].Valeur;
                    await algo.colorer(couleurAlgo, 5, 0.5 *Temps.time);
                }
                for (j = 0; j < 3; j++)
                {
                    plus.tab[j, j + i].BackgroundColor = couleurFondCase;
                }
                await algo.colorer(couleurAlgo, 6, 0.5 *Temps.time);

                det.Valeur += b;
                await algo.colorer(couleurAlgo, 7, 0.5 *Temps.time);
            }
            for (int i = 4; i > 1; i--)                              //Parcours des diagonales de droite à gauche (sens négatif)
            {
                await algo.colorer(couleurAlgo, 8, 0.5 *Temps.time); //Étapes de l'algo en cours

                await algo.colorer(couleurAlgo, 9, 0.5 *Temps.time);

                int j;
                b = 1;
                for (j = 0; j < 3; j++)
                {
                    plus.tab[j, i - j].BackgroundColor = couleurSelection;      //illustration avec couleurs
                }
                textBlock.Text += " - (";
                await Task.Delay(TimeSpan.FromSeconds(Temps.time));

                for (j = 0; j < 3; j++)                                   //Parcours des cases de la diagonale
                {
                    await algo.colorer(couleurAlgo, 10, 0.5 *Temps.time); //Affichage de l'étape en cours dans l'algo

                    plus.tab[j, i - j].clignoter(couleurClignottement, plus.couleurBordureCase, plus.tab[j, i - j].BorderThick, 2);
                    textBlock.FontSize = 15;
                    if (j != 0 && j != 2)
                    {
                        textBlock.Text += " x " + plus.tab[j, i - j].Valeur.ToString();
                    }
                    else if (j != 0 && j == 2)
                    {
                        textBlock.Text += " x " + plus.tab[j, i - j].Valeur.ToString() + ")";
                    }
                    else
                    {
                        textBlock.Text += /*" - (" +*/ plus.tab[j, i - j].Valeur.ToString();
                    }
                    await algo.colorer(couleurAlgo, 11, Temps.time);

                    plus.tab[j, i - j].colorChamp(couleurSelection, plus.couleurBordureCase, 1);
                    b = b * plus.tab[j, i - j].Valeur;
                    await algo.colorer(couleurAlgo, 12, 0.5 *Temps.time);
                }
                for (j = 0; j < 3; j++)
                {
                    plus.tab[j, i - j].BackgroundColor = couleurFondCase;
                }
                await algo.colorer(couleurAlgo, 13, 0.5 *Temps.time);

                await algo.colorer(couleurAlgo, 14, 0.5 *Temps.time);

                det.Valeur -= b;
            }
            det.Height        = heightOfcase * 0.5; //Mise en forme de la case contenant le déterminant
            det.Width         = widthOfcase * 2;
            det.CoordX        = coordX + 3 * widthOfcase;
            det.CoordY        = plus.coordY + (nbLignes + 1) * heightOfcase;
            det.Forme.Opacity = 0;
            det.afficher(c);
            textBlock.Text = "";
            Point[] tabPoint = new Point[1];
            tabPoint[0] = new Point(coordX + widthOfcase / 2, coordY + (nbLignes + 0.5) * heightOfcase);
            await det.appear(tabPoint, 1);          //Affichage du déterminant sous la matrice

            await Task.Delay(50);

            det.Forme.Opacity = 1;
            det.clignoter(Brushes.LightSkyBlue, Brushes.White, 1, 2);
            for (int i = 0; i < 8; i++)
            {
                com[i].disparaitre(Temps.time);
            }
            await Task.Delay(TimeSpan.FromSeconds(Temps.time));

            for (int i = 0; i < 8; i++)
            {
                com[i].enleverCanvas(c);
            }
            comPrincipal.Text = "Le déterminant de la matrice est " + det.Valeur;
            await Task.Delay(TimeSpan.FromSeconds(Temps.time));

            plus.masquer(c);
            await algo.colorer(couleurAlgo, 15, 0.5 *Temps.time);

            algo.disparaitre(Algo);
        }