Vous ne trouvez pas de réponse à votre problème ? Alors posez la question dans le forum. Souvenez-vous qu'il n'y a jamais de question bête, mais rester dans l'ignorance parce que l'on n'ose pas poser une question, ça c'est une erreur !

FRACTAL DE MANDELBROT


Information sur la source

Catégorie :Maths & Algorithmes Source .NET ( DotNet ) Classé sous : fractal, mandelbrot, fractals, fractales, math graphique Niveau : Débutant Date de création : 11/02/2007 Date de mise à jour : 30/03/2008 11:21:56 Vu / téléchargé: 6 307 / 258

Note :
Aucune note

Commentaire sur cette source (0)
Ajouter un commentaire et/ou une note


Description

Cliquez pour voir la capture en taille normale
Le fractal de Mandelbrot est la visualisation d'un objet mathématique. Il s'agit en fait d'une matrice de nombres, où la valeur de chaque nombre est représentée par une couleur.
Chaque point de l'image est un nombre calculé par l'ordinateur selon une équation très simple: Zn+1 = Zn2 + C (pour plus d'informations, http://en.wikipedia.org/wiki/Mandelbrot_set).

Il y a deux méthodes pour dessiner le fractal dans le projet. Une fois avec une méthode qui utilise SetPixel (managé mais très lent) et une fois un bloc unsafe qui permet, via les pointeurs, d'avoir de bonnes performances.

 

Source

  • /// ------------------------------------------------------------------------
  • /// <summary>
  • /// Draw the fractal (with unmanaged code).
  • /// </summary>
  • /// ------------------------------------------------------------------------
  • public void DrawMandelBrotFractalUnmanaged()
  • {
  • int width = this.Width;
  • int height = this.Height;
  • int offset = width % 4;
  • int halfX = 2 * width;
  • int halfY = height / 2;
  • using (Graphics gfx = this.CreateGraphics())
  • {
  • this._bmpBuffer = new Bitmap(width, height, gfx);
  • BitmapData bmpData = this._bmpBuffer.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
  • unsafe
  • {
  • byte* newPixel = (byte*)(void*)bmpData.Scan0;
  • width *= 3;
  • for (int y = 0; y < height; ++y)
  • {
  • for (int x = 0; x < width; x += 3)
  • {
  • Complex complex = new Complex((x - halfX) / 450d, (y - halfY) / 150d);
  • Color color = this.GetColor(this.GetStep(complex));
  • newPixel[0] = color.B;
  • newPixel[1] = color.G;
  • newPixel[2] = color.R;
  • newPixel += 3;
  • }
  • newPixel += offset;
  • }
  • }
  • this._bmpBuffer.UnlockBits(bmpData);
  • Graphics.FromImage(this._bmpBuffer).DrawString("Mandelbrot's Fractal", this._font, this._fontBrush, Point.Empty);
  • gfx.DrawImage(this._bmpBuffer, Point.Empty);
  • }
  • }
       /// ------------------------------------------------------------------------
        /// <summary>
        /// Draw the fractal (with unmanaged code).
        /// </summary>
        /// ------------------------------------------------------------------------
        public void DrawMandelBrotFractalUnmanaged()
        {
            int width = this.Width;
            int height = this.Height;
            int offset = width % 4;

            int halfX = 2 * width;
            int halfY = height / 2;

            using (Graphics gfx = this.CreateGraphics())
            {
                this._bmpBuffer = new Bitmap(width, height, gfx);
                BitmapData bmpData = this._bmpBuffer.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);

                unsafe
                {
                    byte* newPixel = (byte*)(void*)bmpData.Scan0;
                    width *= 3;

                    for (int y = 0; y < height; ++y)
                    {
                        for (int x = 0; x < width; x += 3)
                        {
                            Complex complex = new Complex((x - halfX) / 450d, (y - halfY) / 150d);
                            Color color = this.GetColor(this.GetStep(complex));
                            newPixel[0] = color.B;
                            newPixel[1] = color.G;
                            newPixel[2] = color.R;
                            newPixel += 3;
                        }
                        newPixel += offset;
                    }
                }
                this._bmpBuffer.UnlockBits(bmpData);
                Graphics.FromImage(this._bmpBuffer).DrawString("Mandelbrot's Fractal", this._font, this._fontBrush, Point.Empty);
                gfx.DrawImage(this._bmpBuffer, Point.Empty);
            }
        }

Fichier Zip

Pour les "Membres Club", vous pouvez télécharger directement un fichier contenu dans le zip sans télécharger le zip en entier !

Télécharger le zip

Historique

11 février 2007 11:56:07 :
Modification description
11 février 2007 15:50:56 :
Merci à Lutinore qui m'a indiqué que GDI utilisait BGR et pas RGB !

Commentaires et avis

Aucun commentaire pour le moment.

Ajouter un commentaire



Nos sponsors

Sondage...

CalendriCode

Juillet 2009
LMMJVSD
  12345
6789101112
13141516171819
20212223242526
2728293031  

Consulter la suite du CalendriCode

Téléchargements

Logiciels à télécharger sur le même thème :

Comparez les prix Nouvelle version

Photothèque Nouveau !



Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés
Temps d'éxécution de la page : 0,452 sec

Google Coop CodeS-SourceS Google Coop CodeS-SourceS


Certaines images présentes sur le site (notament certains avatars) sont issues des collections IconShock, donc si vous souhaitez utiliser ces icons vous devez les acheter, ne les copiez pas et ne utilisez pas dans vos sites et applications sans les avoir commandé.