Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Post code

Name: Anonymous 2011-10-06 9:06

Any code you work with right now, and we'll criticize it(or not).

Name: Anonymous 2011-10-06 17:35

Currently working on a mandelbrot set renderer and putting it into a screen saver.


No idea if this will actually format it correctly.
<paste code>
void Mandelbrot::Draw(Graphics* graphics)
{
    double minRe;
    double maxRe;
    double minIm;
    double maxIm;

    switch(_centerPosition)
    {
        // the image center effects where the image is zoomed into.
    case 6:
        // top left
         minRe = _x;
         maxRe = _x + _width;
         minIm = _y - _height;//_y + (_width-_x) * _imageBounds->Height / _imageBounds->Width;
         maxIm = minIm +(maxRe-minRe)*_imageBounds->Height / _imageBounds->Width;
        break;
    case 7:
        // top middle
         minRe = _x - _width * 0.5;
         maxRe = _x + _width * 0.5;
         minIm = _y - _height;
         maxIm = minIm +(maxRe-minRe)*_imageBounds->Height / _imageBounds->Width;
        break;
    case 8:
        // top right
         minRe = _x - _width;
         maxRe = _x;
         minIm = _y - _height;
         maxIm = minIm +(maxRe-minRe)*_imageBounds->Height / _imageBounds->Width;
        break;
    case 3:
        // middle left
         minRe = _x;
         maxRe = _x + _width;
         minIm = _y - _height * 0.5;
         maxIm = minIm +(maxRe-minRe)*_imageBounds->Height / _imageBounds->Width;
        break;
    case 4:
        // middle middle
         minRe = _x - _width * 0.5;
         maxRe = _x + _width * 0.5;
         minIm = _y - _height * 0.5;
         maxIm = minIm +(maxRe-minRe)*_imageBounds->Height / _imageBounds->Width;
        break;
    case 5:
        // middle right
         minRe = _x - _width;
         maxRe = _x;
         minIm = _y - _height * 0.5;
         maxIm = minIm +(maxRe-minRe)*_imageBounds->Height / _imageBounds->Width;
        break;
    case 0:
        // bottom left
         minRe = _x;
         maxRe = _x + _width;
         minIm = _y;
         maxIm = minIm +(maxRe-minRe)*_imageBounds->Height / _imageBounds->Width;
        break;
    case 1:
        // bottom middle
         minRe = _x - _width * 0.5;
         maxRe = _x + _width * 0.5;
         minIm = _y;
         maxIm = minIm +(maxRe-minRe)*_imageBounds->Height / _imageBounds->Width;
        break;
   
    default:
        // bottem right
         minRe = _x - _width;
         maxRe = _x;
         minIm = _y;
         maxIm = minIm +(maxRe-minRe)*_imageBounds->Height / _imageBounds->Width;
        break;
    }

    // local position data
    int imageHeight = (int)_imageBounds->Height;
    int imageWidth  = (int)_imageBounds->Width;
    unsigned maxIterations = GetIterations();
   
    BitmapData bitmapData;
    Bitmap bitmap(imageWidth, imageHeight);
    bitmap.LockBits(&Rect(0, 0, imageWidth, imageHeight), ImageLockModeWrite, PixelFormat32bppARGB, &bitmapData);
    UINT* pixel = (UINT*)bitmapData.Scan0;
    int stride = bitmapData.Stride / 4;

    double Re_factor = (maxRe-minRe)/(imageWidth-1);
    double Im_factor = (maxIm-minIm)/(imageHeight-1);

#pragma omp parallel for
    for(int y = 0; y < imageHeight; ++y)
    {
        double c_im = maxIm - y*Im_factor;

        for(int x=0; x < imageWidth; ++x)
        {
            double c_re = minRe + x*Re_factor;
            double Z_re = c_re, Z_im = c_im;
           
            double Z_re2 = Z_re * Z_re;
            double Z_im2 = Z_im * Z_im;
            unsigned n;
            for(n = 0; n < maxIterations; ++n)
            {
                Z_re2 = Z_re * Z_re;
                Z_im2 = Z_im * Z_im;

                if(Z_re2 + Z_im2 > 4)
                {
                    break;
                }

                Z_im = 2 * Z_re * Z_im + c_im;
                Z_re = Z_re2 - Z_im2 + c_re;
            }
           
            //if(c_re > 0)
                pixel[y * stride + x] = Color(n % 256, (byte)(255*((float)n / (float)maxIterations)),0).ToCOLORREF() + 0xff000000;
            //else
            //    pixel[y * stride + x] = 0xfffffffff;
           
            //if(n == maxIterations)
            //    pixel[y * stride + x] = 0xfffffffff;
        }
    }

    bitmap.UnlockBits(&bitmapData);
    graphics->DrawImage(&bitmap, *_imageBounds);
   
   
   
    std::wstringstream text;
    text << "Iterations: " << _maxIterations << " Current Iterations: " << _currentIterations
        << "\nX: " << _x << "\nY: " << _y  << "\nWidth: " << _width << " Height: "
        << _height <<"\nDtime: " << _outputText;
   
    std::wstring wstr = text.str();
    DrawString(graphics, wstr.c_str(), PointF(10,10));
}

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List