home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga MA Magazine 1997 #3
/
amigamamagazinepolishissue03-1
/
ma_1995
/
09
/
ami936a.txt
< prev
next >
Wrap
Text File
|
1997-04-07
|
3KB
|
215 lines
<l>
/***********************************************************/
/* Program rysuje zbiory Mandelbrota dla wielomianu z=z^2+c */
/* Napisane dla Magazynu Amiga (c) 1995 by BsZ */
/***********************************************************/
#include <ctype.h>
#include <fctype.h>
#include <functions.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <exec/types.h>
#include <intuition/intuition.h>
#define DEPTH 4
#define COLORS 16
#define WIDTH 640
#define HEIGHT 512
#define da (a_max-a_min)/WIDTH
#define db (b_max-b_min)/HEIGHT
struct Screen *scr;
struct IntuitionBase *IntuitionBase;
struct GfxBase *GfxBase;
struct NewScreen scr_data={
0,0,WIDTH,HEIGHT,DEPTH,1,1,HIRES|LACE,CUSTOMSCREEN,0,
(UBYTE *)"Fraktal1",0,0};
void niedobrze(void)
{
if (scr) CloseScreen(scr);
if (GfxBase) CloseLibrary((struct Library *)GfxBase);
if (IntuitionBase) CloseLibrary((struct Library *)IntuitionBase);
exit(0);
}
void OpenAllLibraries(void)
{
IntuitionBase=(struct IntuitionBase *)OldOpenLibrary("intuition.library");
if (!IntuitionBase) exit(100);
GfxBase=(struct GfxBase *)OldOpenLibrary("graphics.library");
if (!GfxBase) exit(100);
}
void paleta(void)
{
ULONG i;
for(i=0;i<COLORS;i++)
SetRGB4(&scr->ViewPort, i, i, i, i);
}
void main(int argc,char *argv[])
{
int kolor;
long int i,j; /* wsp. graficzne */
double x,y; /* wspóîrzëdne punktu z */
double tempx;
double a,b; /* wspóîrzëdne punktu c */
double a_min,a_max,b_min,b_max; /* zakresy zmian parametru c*/
long int N; /* iloôê iteracji */
long int L; /* licznik punktów zawartych w kole o promieniu 2 */
if(argc!=6)
{
printf("Argumenty:a_min a_max b_min b_max N\n");
exit(0);
}
a_min = atof(argv[1]);
a_max = atof(argv[2]);
b_min = atof(argv[3]);
b_max = atof(argv[4]);
N = atol(argv[5]);
OpenAllLibraries();
if(!(scr=OpenScreen(&scr_data))) niedobrze();
paleta();
SetRast(&scr->RastPort,15);
b=b_max;
for(j=0;j<HEIGHT;j++)
{
if(scr->MouseX<2 && scr->MouseY<2)
{
niedobrze();
break;
}
a=a_min;
for(i=0;i<WIDTH;i++)
{
x=0;
y=0;
for(L=1;L<=N;L++)
{
tempx = x * x - y * y + a;
y = 2 * x * y + b;
x=tempx;
if( (x * x + y * y) < 2) L++;
else break;
}
kolor = (int)( 15.0*(1.0 - L/(double)N) );
SetAPen(&scr->RastPort,kolor);
WritePixel(&scr->RastPort,i,j);
a+=da;
}
b-=db;
}
for(;;)
{
if(scr->MouseX<2 && scr->MouseY<2)
{
niedobrze();
break;
}
Delay(50);
printf("Najedú myszkâ na lewy górny róg ekranu...\n");
}
}