Множество
Мандельброта
(Lenik Terenin)
--
/*
* File: MANDEL.C
*
* Mandelbrot set generator.
* Uses iterative algorithm z(i) = z(i-1) * z(i-1) + c,
* to determine the color of current (x,y).
*
* DO NOT try to compile this using WCL386 !
* Use "WCL -3" or Borland/C++ instead.
*
* (c) Lenik Terenin, 1995
*/
#include
#include
#include
#define LIMIT 100 // Increase LIMIT to get more exact picture
#ifdef __BORLANDC__
void SetVmode( short mode )
{
asm {
mov ax, [mode]
push bp
int 10h
pop bp
}
}
#define PutPixel13(x,y,c) pokeb( 0xA000, (x) + (y) * 320, (c))
#else
#ifdef __386__
#error Can't run in 32-bit mode, sorry...
#endif
void SetVmode(short);
#pragma aux SetVmode = \
"push bp" \
"int 10h" \
"pop bp" \
parm [ax]
void PutPixel13( short x, short y, short c);
#pragma aux PutPixel13 = \
"push ax" \
"mov ax, 0a000h" \
"mov es, ax"\
"pop ax" \
"shl bx,6" \
"add di,bx" \
"shl bx,2" \
"add di,bx" \
"stosb" \
parm [di] [bx] [ax] modify [es] nomemory
#endif
main()
{
int i, j, k;
double z_i, z_r, c_i, c_r, tmp;
double module;
SetVmode( 0x13 );
for( i=-160; i<160; i++) {
c_i = ((double) i) / 100.0;
for( j=-160; j<40; j++) {
c_r = ((double) j) / 80.0;
z_i = z_r = 0.0;
for( k=0; k<LIMIT; k++) {
tmp = z_r * z_r - z_i * z_i;
z_i = 2 * z_r * z_i + c_i; // z = z * z + c
z_r = tmp + c_r;
module = z_r * z_r + z_i * z_i; // is |z| large enough?
if( module > 1.0E16 ) break;
}
if( k<LIMIT) {
PutPixel13( i+160, j+160, (k/15)*2+20);
}
else PutPixel13( i+160, j+160, 16);
}
if( kbhit() ) break;
}
getch(); SetVmode(3);
return 0;
}
|