December 03, 2020, 01:08:25 pm

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Ye Olde Mandelbrot example

Started by Ionic Wind Support Team, May 04, 2006, 02:32:00 pm

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Ionic Wind Support Team

Yes it is the same old mandelbrot example that was a point of contention long ago with the original IB. 

Still fun to play with.

Code Select

/*
a full screen mandelbrot example
For Aurora Alpha 3 or greater
*/


int i,y,px;
float Z_re2;
float Z_im2;
float Z_re;
float Z_im;
float c_re;
float c_im;

string start,finish;
#define ImageWidth 640
#define ImageHeight 480

global sub main()
{
C2DScreen s;
MinRe = -2.0f;
MaxRe = 1.0f;
MinIm = -1.2f;
MaxIm = MinIm+(MaxRe-MinRe)*ImageHeight/ImageWidth;
Re_factor = (MaxRe-MinRe)/(ImageWidth-1);
Im_factor = (MaxIm-MinIm)/(ImageHeight-1);

if(s.CreateFullScreen(ImageWidth,ImageHeight,32 ) < 0)
{
MessageBox( NULL,"Unable to create DirectX screen","Error");
return 0;
}
C2DSurface *backbuffer = s.GetBack();
C2DSurface *frontbuffer = s.GetFront();
frontbuffer->Fill(RGB(100,100,100));

start = FormatTime();
frontbuffer->Lock();
for( y = 0; y < ImageHeight; y++ )
{
c_im = MaxIm - y*Im_factor;
for( px=0; px < ImageWidth; px++)
{
c_re=MinRe+px*Re_factor;
Z_re=c_re;
Z_im=c_im;
for( i=1;i <= 50; i++)
{
Z_re2=Z_re*Z_re;
Z_im2=Z_im*Z_im;
if Z_re2+Z_im2>4
{
frontbuffer->PutPixelFast( px,y,rgb(255-(i+5),i*5,i) );
goto exloop;
}
Z_im=2*Z_re*Z_im+c_im;
Z_re=Z_re2-Z_im2+c_re;
}
exloop:
}
}
frontbuffer->Unlock();

finish = FormatTime();
//swap the buffers so we can draw text on the front surface
s.SetBack(frontbuffer);
s.FrontPen(RGB(255,255,255));
s.DrawMode(TRANSPARENT);
s.Setfont("Courier New",12,400);
s.WriteText(10,20,sprint("Start: ",start," Finish: ",finish));
s.WriteText(10,40,"Press ESC to close");
//restore the back buffer
s.SetBack(backbuffer);
While GetKeyState(0x1B) == 0;
s.CloseScreen();
}
Ionic Wind Support Team

Zen

SetBack reports an unknown method for some reason? Is that something in your version that isnt yet in ours?

Lewis

Parker

Works fine here... have the latest update?

Ionic Wind Support Team

May 04, 2006, 04:14:36 pm #3 Last Edit: May 04, 2006, 04:20:15 pm by Ionic Wizard
SetBack was added with Rev 1.  So either you didn't get a clean install, or something had dx2d.inc locked during the update.  Which is why I always recommend uninstalling first.

If you edit any of the files in the 'bin' directory the uninstaller won't remove them.  Something to watch for. 

You can always check the 'about' box as well for the current revision numbers.  Also the skeleton 2D help file was added to this update, if it is not on your help menu then you had a bad install.
Ionic Wind Support Team

Zen

Hmm i dont think i changed anything and i had no files in use but i guess ill try uninstalling Aurora first.

Lewis

Zen

Ha Ha. Doooohhh!!!! i only updated at work, not on my laptop. Always the simple things.

Lewis

Ionic Wind Support Team

lol.  Glad you figured it out ;)
Ionic Wind Support Team

Zen

Yeh i downloaded it here but i think i must of had to nip out and when i came back i must of seen the zip on the desktio and thought i had already installed it. When infact i only installed it at work.

I guess its just been one of those days.

Lewis

Rock Ridge Farm (Larry)

I get an error - unable to load directx screen.
Do I need to download something?
It compiles fine - just will not execute.

Zen

Hmm. what os and directX version are you using Larry?

Lewis

Rock Ridge Farm (Larry)


Zen

DirectX? The error is obviously being caused because directX cant create the screen. Im not sure why because i dont know enough. It could be something in the code or it could be the machine.

Lewis

Ionic Wind Support Team

Probably doesn't support full screen DX at 32 BPP.

Change this line:

if(s.CreateFullScreen(ImageWidth,ImageHeight,32 ) < 0)

To:

if(s.CreateFullScreen(ImageWidth,ImageHeight,16 ) < 0)

Or play with the width and height defines.  Some laptops only have one resolution to work with, like 1024x768

Ionic Wind Support Team

Rock Ridge Farm (Larry)


Doc

QuoteYes it is the same old mandelbrot example that was a point of contention long ago with the original IB. 


...there's dang sure no point of contention with this one. It flat out blazes.
Heh, I got a new computer and by the time the time it changes into full screen DX mode it's already finished The first time I ran it, it didn't even roll over the odometer.  Start time and elapesd time showed exactly the same. :o

-Doc-

Ionic Wind Support Team

;).  I'll see if I can modify it a bit to do zooming.  Fletchie did that once with the IB one but the code was misplaced over the years.
Ionic Wind Support Team

Zen

Quote from: docmann on May 04, 2006, 09:28:24 pm
by the time the time it changes into full screen DX mode it's already finished The first time I ran it, it didn't even roll over the odometer.  Start time and elapesd time showed exactly the same. :o


Yeah same here. Even my laptop that i bought over a year ago shows the same times :D

Lewis