This post has been edited 1 times, last edit by "Johannes" (Aug 28th 2010, 7:51pm)
|
|
C/C++ Quellcode |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
/* * 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 <stdio.h> #include <conio.h> // #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 int 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; } |
This post has been edited 2 times, last edit by "bcc-fan" (Aug 29th 2010, 8:19pm)
This post has been edited 1 times, last edit by "bcc-fan" (Aug 31st 2010, 8:39am)