begin process at 2008 05 17 08:14:46
1 173 922 membres
53 nouveaux aujourd'hui
13 973 membres club

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é: 4 473 / 220

Note :
Aucune note

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


Description

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);
            }
        }
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

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 !

Sources en rapport avec celle ci

    Aucun commentaire pour le moment.

Ajouter un commentaire

Appels d'offres

Pub



CalendriCode

Mai 2008
LMMJVSD
   1234
567891011
12131415161718
19202122232425
262728293031 

VS Express FR Gratuit !

VS Express en français et 100% gratuit !

Téléchargements

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

Boutique

Boutique de goodies CodeS-SourceS