home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
AmigActive 6
/
AACD06.ISO
/
AACD
/
Programming
/
ImageManager
/
Examples
/
Fractal.c
< prev
next >
Wrap
C/C++ Source or Header
|
1999-10-12
|
2KB
|
70 lines
#include <proto/exec.h>
#include <proto/imagemanager.h>
#include <proto/intuition.h>
struct Library *ImageManagerBase;
#define WIDTH 320
#define HEIGHT 240
VOID DrawMandelbrot (Object *obj, ULONG sigmask)
{
static ULONG Buffer[WIDTH];
for(LONG y = 0; y < HEIGHT; y++)
{
ULONG *buf = Buffer, *end = &Buffer[WIDTH];
FLOAT sy = ((FLOAT)y - HEIGHT/2.0) / (((FLOAT)HEIGHT)/2.4);
FLOAT x = -2.1, x_step = 3.0 / WIDTH, rx, ry;
while(buf < end)
{
rx = ry = 0.0;
FLOAT y2 = ry*ry;
for(ULONG i = 0; i < 20; i++)
{
FLOAT rx2 = rx*rx - y2 + x;
ry = rx*ry * 2.0 + sy;
if(rx2*rx2 + (y2 = ry*ry) > 3.0)
break;
rx = rx2;
}
*buf++ = (i % 20) * 0x0D000600;
x += x_step;
}
if(!DoMethod(obj, IMM_ReceiveData, IMV_ReceiveData_Type_Pixels, Buffer, WIDTH, y, 1, 0L, NULL) || SetSignal(0L, 0L) & sigmask)
break;
}
}
VOID main ()
{
if(ImageManagerBase = OpenLibrary("ImageManager.library", 1))
{
struct Window *win = OpenWindowTags(NULL, WA_Activate, TRUE, WA_IDCMP, IDCMP_CLOSEWINDOW, WA_CloseGadget, TRUE, WA_DragBar, TRUE, WA_DepthGadget, TRUE, WA_InnerWidth, WIDTH, WA_InnerHeight, HEIGHT, TAG_DONE);
Object *container, *raster;
if(raster = IM_NewObject("Raster", IMA_Raster_RastPort, win->RPort, IMA_Raster_OffsetX, win->BorderLeft, IMA_Raster_OffsetY, win->BorderTop, TAG_DONE))
{
if(container = IM_NewObject("Container", IMA_Next, raster, IMA_Container_Screen, win->WScreen, TAG_DONE))
{
if(DoMethod(container, IMM_NewFrame, WIDTH, HEIGHT, NULL))
{
DrawMandelbrot(container, 1 << win->UserPort->mp_SigBit);
DoMethod(container, IMM_EndFrame, WIDTH, HEIGHT);
}
WaitPort(win->UserPort);
IM_DisposeObject(container);
}
IM_DisposeObject(raster);
}
CloseWindow(win);
CloseLibrary(ImageManagerBase);
}
}