コード例 #1
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);
        }
コード例 #2
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);
        }