/* Fractal na tela */ #include "us.h" #define NTLINHAS 786 // n£mero de linhas na tela #define NTCOLUNAS 1024 // n£mero de colunas na tela #define NFLINHAS 480 // n£mero de linhas no fractal #define NFCOLUNAS 640 // n£mero de colunas no fractal typedef byte tela[NTLINHAS][NTCOLUNAS]; // variaveis float xini,yini; // coordenadas do ponto dentro do fractal dword xpix,ypix; // posi‡„o do pixel na tela do video // prototypes void desenhar_fractal(); // A primeira rotina deve ser o main void main() { desenhar_fractal(); terminate(); } void desenhar_fractal() { /* Calculation of Julia set ------------------------ Written by Kiselev Y. 1994 Definitions of complex numbers: z = x + i*y screen coordinates xini <= x < xini+1024*xstep u = s + i*t parameter \ yini <= y < yini+768*ystep Equation used: f(z) = z^2 - u Iteration: f(z), f(f(z)), f(f(f(z))), ... until |f(...)| > 2 or max_it iterations Result: pixel value at (x,y) is the number of iterations. */ tela far *video = VIDEO_FP(0); byte pix; // valor do pixel for(yini=-1.15, ypix=120; ypix<120+NFLINHAS; yini+=0.005, ypix++) { if(ypix==120+NFLINHAS/2) carrega('b'); for(xini=-1.55, xpix=250; xpix<250+NFCOLUNAS; xini+=0.005, xpix++) { float x,x2,y,y2,xy; x=xini; y=yini; for(pix=0; pix<255; pix++) { // max_it=255 x2=x*x; y2=y*y; if(x2+y2>4.0) break; // |z|=sqrt(x^2+y^2) < 2 xy = x*y; x = x2-y2-0.76; // -s y = xy+xy-0.09; // -t } if (pix>2) (*video)[ypix][xpix] = pix; // for(i=1; i<100; i++); } } }