   generating the mandelbrot set
  hi, i wrote a very simple program to generate a mandelbrot set and save it on a 512*512 bitmap, but the image i get is somewhat different from what it should be.. i'll se if i can post an image, heres my algo for now:unsigned char Pixel[512][512][3];for(int i=0;i<512;i++)//rows{for(int j=0;j<512;j++)//pixels{CComplex Z;Z.Set(0.0f,0.0f);for(int n=0;n<100;n++){Z.Multiply(Z);Z.Add(((float)j-256.0f)/128.0f,((float)i-256.0f)/128.0f);if(Z.Modulus()>=2.0f)//the point is outside{NumOutside++;//set some n-based colorPixel[i][j][0]=60+n;//bPixel[i][j][1]=20+n;//gPixel[i][j][2]=n;//rbreak;}if(n==99)//the point is inside!{NumInside++;Pixel[i][j][0]=0;Pixel[i][j][1]=0;Pixel[i][j][2]=0;break;}}}}it should be right isnt it? what am i doing wrong?try here for the image:http://members.fortunecity.com/arcibaldwearlot/Mandelbrot.JPG[edited by - Arcibald Wearlot on February 5, 2004 4:46:39 AM][edited by - Arcibald Wearlot on February 5, 2004 4:47:03 AM]
  would have to look at your other code (classes) aswell but think about moving the pixel testing bit into a function.make sure u do tests on your Complex class to make sure it is working properly.  ;  Hmm... Your function inexplicably generated an advertisement.  I don''t think your host supports direct linking to images. ;  yeah i could encapsulate it in a function, but this was just supposed to be a very simple program.. i just wanted to test what i read on the mandelbrot set and to see if it worked.. and it doesnt seem to heres the complex class code: //Complex.hclass CComplex{public:CComplex();~CComplex();void Set(float Re,float Im);void Add(CComplex Number);void Add(float Re,float Im);void Multiply(CComplex Number);void Multiply(float Re,float Im);float Modulus();float GetReal();float GetImaginary();private:float m_Re,m_Im;};//----------------------------------//complex.cpp#include "complex.h"#include <math.h>CComplex::CComplex(){m_Re=0.0f;m_Im=0.0f;}CComplex::~CComplex() {}void CComplex::Set(float Re,float Im){m_Re=Re;m_Im=Im;}void CComplex::Add(CComplex Number){m_Re=m_Re+Number.GetReal();m_Im=m_Im+Number.GetImaginary();}void CComplex::Add(float Re,float Im){m_Re+=Re;m_Im+=Im;}void CComplex::Multiply(CComplex Number){m_Re=((m_Re*Number.GetReal())-(m_Im*Number.GetImaginary()));m_Im=((m_Im*Number.GetReal())+(m_Re*Number.GetImaginary()));}void CComplex::Multiply(float Re,float Im){m_Re=((m_Re*Re)-(m_Im*Im));m_Im=((m_Im*Re)+(m_Re*Im));}float CComplex::Modulus(){return (float)sqrt((m_Re*m_Re)+(m_Im*m_Im));}float CComplex::GetReal(){return m_Re;}float CComplex::GetImaginary(){return m_Im;}there isnt really much other code. i just write the pixels with the following code. i know the image would be upside-down this way (because of the way data is stored into a bmp) but this shouldnt be a problem..   unsigned char g_BmpFileHeader[54]={    0x42, 0x4D, 0x36, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x00, 0x28, 0x00,0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x01, 0x00, 0x18, 0x00, 0x00, 0x00,0x00, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, };fwrite(&g_BmpFileHeader,sizeof(g_BmpFileHeader),1,BmpFile);for(i=0;i<512;i++){for(int j=0;j<512;j++){fwrite(&Pixel[i][j],sizeof(unsigned char)*3,1,BmpFile);}}hmm.. and for the image i'll try to find another host [edited by - Arcibald Wearlot on February 5, 2004 5:40:59 AM];  quote:void CComplex::Multiply(CComplex Number){m_Re=((m_Re*Number.GetReal())-(m_Im*Number.GetImaginary()));m_Im=((m_Im*Number.GetReal())+(m_Re*Number.GetImaginary()));}end of quoteYou have to use the old value of m_Re when calculating the imaginary part. But you are using the New one!;  oh yeah thats the error!!and now it works great!! :D thank you ^^ ;  In case you didn''t notice, the same problem exists in void CComplex::Multiply(float Re,float Im), you''re using the new value for the real component.Also, you can make your code look a lot better by defining operators for your class, like CComplex::operator* or CComplex::operator+.   "Baby-killer is a bad word though. Notice how as soon as you say it, you think negative things." - Peon;  Use std::complex next time... ;quote:Original post by Anonymous Poster  Use std::complex next time...   You mean, I went through all the work of making a complex number class in my fractal drawer, when there was already one?  Dammit..Anyway, Arcibald Wearlot:  now that you''ve gotten the Mandelbrot set down, do some Julia sets if you haven''t already, those are the coolest ever ;Clicky for some mandelbrots I made some time ago.  