|
|
DataMuseum.dkPresents historical artifacts from the history of: DKUUG/EUUG Conference tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about DKUUG/EUUG Conference tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - downloadIndex: T x
Length: 2666 (0xa6a)
Types: TextFile
Names: »xmandel.c«
└─⟦b20c6495f⟧ Bits:30007238 EUUGD18: Wien-båndet, efterår 1987
└─⟦this⟧ »EUUGD18/X/Xmandel/xmandel.c«
#include <stdio.h>
#include <signal.h>
#include <math.h>
#include <string.h>
#include <ctype.h>
#define NMAX 200
#define LINE 80
#define SCFAC 5
typedef struct complx{
double re;
double im;
} Cmplx;
char *argv0;
int rsiz0 = 12;
double xin0 = 0;
double yin0 = 0;
double scale0 = 1;
char *display0 = NULL;
char *malloc();
double xo,yo;
FILE *fp = stderr;
FILE *fpin = stdin;
main(argc,argv)
int argc;
char **argv;
{
int nmand(), length;
void exithandler();
argv0 = argv[0];
again:
if (argc > 2 && strcmp(argv[1], "-display") == 0) {
argv++;
argc--;
length = strlen(argv[1]);
display0 = malloc(length + 5);
strcpy(display0,argv[1]);
if ((length < 4) || (argv[1][length - 4] != ':'))
strcat(display0,":0.0");
argv++;
argc--;
goto again;
}
if (argc > 2 && strcmp(argv[1], "-x") == 0) {
argv++;
argc--;
if (sscanf(argv[1], "%F", &xin0) !=1)
usage();
argv++;
argc--;
goto again;
}
if (argc > 2 && strcmp(argv[1], "-y") == 0) {
argv++;
argc--;
if (sscanf(argv[1], "%F", &yin0) !=1)
usage();
argv++;
argc--;
goto again;
}
if (argc > 2 && strcmp(argv[1], "-s") == 0) {
argv++;
argc--;
if (sscanf(argv[1], "%F", &scale0) !=1)
usage();
argv++;
argc--;
goto again;
}
if (argc > 2 && strcmp(argv[1], "-r") == 0) {
argv++;
argc--;
if (sscanf(argv[1], "%d", &rsiz0) !=1)
usage();
argv++;
argc--;
goto again;
}
if (argc > 1) usage();
on_exit(exithandler);
graphics(display0,xin0,yin0,scale0,rsiz0,nmand,NMAX);
}
int nmand(x,y)
double x,y;
{
Cmplx map(),z;
int n;
n = 1;
xo = z.re = x;
yo = z.im = y;
for(;z.re*z.re+z.im*z.im < 4;z = map(z))
if (++n>=NMAX) break;
return NMAX - n;
}
Cmplx map(z)
Cmplx z;
{
Cmplx t;
t.re = z.re*z.re - z.im*z.im + xo;
t.im = 2*z.re*z.im + yo;
return t;
}
usage()
{
fprintf(stderr,
"usage: %s [-display host] [-x x0] [-y y0] [-s scale]\n",argv0);
fprintf(stderr," [-r resolution]\n");
exit(1);
}
void exithandler(status)
int status;
{
int wtf,nmand();
if (status != SIGINT) exit(0);
wtf = lgetd("Write to file",0);
if (wtf == 0) exit(0);
writeman(nmand);
}
lgetd(mesg,deflt)
char *mesg;
int deflt;
{
char s[LINE], *sptr;
for(;;) {
fprintf(fp,"*%s [%c]: ",mesg,(deflt ? 'y' : 'n'));
fflush(fp);
sptr = fgets(s,LINE,fpin);
if (!sptr) exit(-1);
while(isspace(*sptr)) sptr++;
if(*sptr=='\0') return(deflt);
if(isupper(*sptr)) *sptr = tolower(*sptr);
if(*sptr == 'y')
return(1);
else if(*sptr == 'n')
return(0);
else
fprintf(fp," Say what? Enter y or n.\n");
}
}