/**********************************************/ /* file: apfelm.c */ /* author: Ing. Wilhelm Brezovits */ /* street: Dr. Ignaz Weber-Gasse 7 */ /* city: 2353 Guntramsdorf */ /* version: X1 */ /* date: 20.08.1991 */ /* update: 03.11.1991 */ /* OS: MS-DOS 5.0 */ /* Copyright: Created using Borland C++ */ /**********************************************/ #include #include #include #include #include #include #include #include #include #include #define MAXX 639.0 //VGA: 639.0 EGA: 639 #define MAXY 479.0 //VGA: 479.0 EGA: 349 #define MAXC 15 //number of colours #define MAXP 10 //number of maximum saved pictures (without 0) #define MAXD 100000000000.0 //maximum double range #define MIND -100000000000.0 //minimum double range // -------------------------------------------------------- prototype ------ void disk(void); void calculate(double xmin,double xmax,double ymin,double ymax,int tiefemax,char save,int file_nr); void values_in(void); int which_file(void); void get_file(void); void put_file(int farbe,char painting,int file_nr,char ready,char user_break,char save); void wait(void); void message(char inform); void compress(int farbe,char *farbe_c); // ------------------------------------------------------------------------- //extern unsigned _heaplen=1024; // Heaplaenge heruntersetzen, damit // Platz fuer system() ist // only small memory model !!! /**************************************************************************/ int main(void) { char select; //user's selection of main selection int exit=0; //quit while for ever disk(); //if disk is not B ... assign B = current disk fflush(stdin); while (1) { //............................................................. clrscr(); fflush(stdin); textmode(C80); normvideo(); textcolor(YELLOW); cprintf("\n\n\r"); cprintf("**********************************************************\n\r"); cprintf("* main selection *\n\r"); cprintf("* ============== *\n\r"); cprintf("* *\n\r"); cprintf("* 0 ...paint (possibility: save picture) *\n\r"); cprintf("* 1 ...load picture *\n\r"); cprintf("* *\n\r"); cprintf("* 9 ...exit program *\n\r"); cprintf("* *\n\r"); cprintf("**********************************************************\n\n\r"); highvideo(); textcolor(LIGHTRED+BLINK); gotoxy(1,15); cprintf(" your choice: "); normvideo(); textcolor(YELLOW); fflush(stdin); select=getche(); if ( (select!='0') && (select!='1') && (select!='9') ) continue; wait(); switch (select) { case '0': values_in(); break; case '1': get_file(); break; case '9': exit=4711; break; default: ; } if (exit==4711) break; } //while for ever.......................................................... spawnl(P_WAIT,"C:\\dos\\ASSIGN.COM","assign.com",NULL); return 0; } /*main*/ /**************************************************************************/ /**************************************************************************/ void calculate(double xmin,double xmax,double ymin,double ymax,int tiefemax, char save, int file_nr) //calculate and paint picture, call put_file { int karte, modus; double dx,dy,cx,cy,xwert,ywert,xquad,yquad; int farbe,zeile,spalte,tiefe; char painting='N'; // N...no painting Y...painting in progress char ready='N'; // picture ready??? Y...close filepointer char user_break='N'; // break by user??? Y...close filepointer detectgraph(&karte,&modus); initgraph(&karte,&modus,"b:\\bgi"); fflush(stdin); while (!(kbhit())) { dx=(xmax-xmin)/MAXX; dy=(ymax-ymin)/MAXY; cx=xmin; cy=ymin; for (zeile=0; zeile<=MAXY; ++zeile) { for (spalte=0; spalte<=MAXX; ++spalte) { tiefe=0; xwert=0; ywert=0; xquad=0; yquad=0; cx=xmin+spalte*dx; cy=ymin+zeile*dy; do { ywert=(2*xwert*ywert)+cy; xwert=(xquad-yquad)-cx; xquad=xwert*xwert; yquad=ywert*ywert; ++tiefe; } while ((tiefe=tiefemax) { farbe=0; } putpixel(spalte,zeile,farbe); if (save == 'Y') { if ( (zeile==MAXY) && (spalte==MAXX) ) ready='Y'; // close filepointer put_file(farbe,painting,file_nr,ready,user_break,save); } painting='Y'; } if ((kbhit())) { user_break='Y'; put_file(farbe,painting,file_nr,ready,user_break,save); break; } } break; } closegraph(); }/*calculate*/ /**************************************************************************/ /**************************************************************************/ void values_in(void) { int lf=0; char save='N'; // save picture yes or no char inform; char tm_string[5]; double xmi,xma,ymi,yma; char xmi_string[40], xma_string[40]; char ymi_string[40], yma_string[40]; char sign='n'; int file_nr=0; // save picture in file number 1,2,..,10 int tm=0; xmi=xma=ymi=yma=0.0; clrscr(); fflush(stdin); textmode(C80); normvideo(); textcolor(YELLOW); cprintf("\n\n\r"); cprintf("**********************************************************\n\r"); cprintf("* paint: values selection *\n\r"); cprintf("* ======================= *\n\r"); cprintf("* *\n\r"); cprintf("**********************************************************\n\n\r"); //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ inform='Y'; message(inform); for (;;) { highvideo(); textcolor(LIGHTRED+BLINK); //xmin xmi gotoxy(1,10); cprintf("your choice for xmin: "); normvideo(); textcolor(YELLOW); for (lf=0; lf<=30; ++lf) { cscanf("%1c",&sign); xmi_string[lf]=sign; if ( (sign=='b') || (sign=='\n') ) break; } ++lf; xmi_string[lf]='\0'; xmi=atof(xmi_string); if ( (xmi<=MAXD) && (xmi>=MIND) ) break; } cprintf("\r your choice for xmin: "); cprintf("%30.15lf",xmi); //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ for (;;) { highvideo(); textcolor(LIGHTRED+BLINK); //xmax xma gotoxy(1,12); cprintf("your choice for xmax: "); normvideo(); textcolor(YELLOW); for (lf=0; lf<=30; ++lf) { cscanf("%1c",&sign); xma_string[lf]=sign; if ( (sign=='b') || (sign=='\n') ) break; } ++lf; xma_string[lf]='\0'; xma=atof(xma_string); if ( (xma<=MAXD) && (xma>=MIND) ) break; } cprintf("\r your choice for xmax: "); cprintf("%30.15lf",xma); //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ for (;;) { highvideo(); textcolor(LIGHTRED+BLINK); //ymin ymi gotoxy(1,14); cprintf("your choice for ymin: "); normvideo(); textcolor(YELLOW); for (lf=0; lf<=30; ++lf) { cscanf("%1c",&sign); ymi_string[lf]=sign; if ( (sign=='b') || (sign=='\n') ) break; } ++lf; ymi_string[lf]='\0'; ymi=atof(ymi_string); if ( (ymi<=MAXD) && (ymi>=MIND) ) break; } cprintf("\r your choice for ymin: "); cprintf("%30.15lf",ymi); //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ for (;;) { highvideo(); textcolor(LIGHTRED+BLINK); //ymax yma gotoxy(1,16); cprintf("your choice for ymax: "); normvideo(); textcolor(YELLOW); for (lf=0; lf<=30; ++lf) { cscanf("%1c",&sign); yma_string[lf]=sign; if ( (sign=='b') || (sign=='\n') ) break; } ++lf; yma_string[lf]='\0'; yma=atof(yma_string); if ( (yma<=MAXD) && (yma>=MIND) ) break; } cprintf("\r your choice for ymax: "); cprintf("%30.15lf",yma); inform='N'; message(inform); //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ inform='9'; message(inform); do { highvideo(); textcolor(LIGHTRED+BLINK); //tiefemax tm gotoxy(1,18); cprintf("your choice for tiefemax: "); normvideo(); textcolor(YELLOW); cscanf("%4c",&tm_string); tm=atoi(tm_string); } while ( (tm>9999) || (tm<=0) ); cprintf("\r your choice for tiefemax: "); cprintf("%10d",tm); inform='N'; message(inform); for (;;) { highvideo(); textcolor(LIGHTRED+BLINK); //save picture J/N gotoxy(1,20); cprintf("\r save picture Y/N: "); normvideo(); textcolor(YELLOW); fflush(stdin); save=toupper(getche()); if ( (save=='Y') || (save=='N') ) break; } if (save == 'Y') { file_nr=which_file(); } calculate(xmi,xma,ymi,yma,tm,save,file_nr); }/*values_in*/ /***************************************************************************/ /***************************************************************************/ int which_file() { int err; int file_nr=0; char file_nr_string[4]; // 0,1,2,...,9,10 char *p; for (;;) { clrscr(); fflush(stdin); textmode(C80); normvideo(); textcolor(YELLOW); cprintf("\n\n\r"); cprintf("**********************************************************\n\r"); cprintf("* file number selection for save/load picture: *\n\r"); cprintf("* ============================================ *\n\r"); cprintf("**********************************************************\n\n\r"); window(1,8,80,24); textbackground(GREEN); clrscr(); err = system("dir b:\\pictures\\*.pic"); if(err) puts("Fehler beim Ausfuehren des DOS-Befehls !"); window(1,1,80,25); textbackground(0); gotoxy(1,25); cprintf(" input possibility: (01,02,...,10 or 1?,2?,...,10) * and RETURN"); highvideo(); textcolor(LIGHTRED+BLINK); //file number gotoxy(1,7); cprintf("file number for saving/loading picture: "); normvideo(); textcolor(YELLOW); scanf("%3c",&file_nr_string); file_nr=atoi(file_nr_string); if ( (file_nr<=MAXP) && (file_nr>0) ) break; } return file_nr; }/*which_file*/ /***************************************************************************/ /***************************************************************************/ void get_file(void) { int file_number; int karte, modus; int farbe,zeile,spalte; int error=0; char farbe_c; // compress file output char ready='N'; FILE *fp; char *dateiname="z:\\wilhelm.zzz\\apple01.zzz"; char *dateiname01="b:\\pictures\\apple01.pic"; char *dateiname02="b:\\pictures\\apple02.pic"; char *dateiname03="b:\\pictures\\apple03.pic"; char *dateiname04="b:\\pictures\\apple04.pic"; char *dateiname05="b:\\pictures\\apple05.pic"; char *dateiname06="b:\\pictures\\apple06.pic"; char *dateiname07="b:\\pictures\\apple07.pic"; char *dateiname08="b:\\pictures\\apple08.pic"; char *dateiname09="b:\\pictures\\apple09.pic"; char *dateiname10="b:\\pictures\\apple10.pic"; file_number=which_file(); detectgraph(&karte,&modus); initgraph(&karte,&modus,"b:\\bgi"); switch(file_number) { case 1: strcpy(dateiname,dateiname01); break; case 2: strcpy(dateiname,dateiname02); break; case 3: strcpy(dateiname,dateiname03); break; case 4: strcpy(dateiname,dateiname04); break; case 5: strcpy(dateiname,dateiname05); break; case 6: strcpy(dateiname,dateiname06); break; case 7: strcpy(dateiname,dateiname07); break; case 8: strcpy(dateiname,dateiname08); break; case 9: strcpy(dateiname,dateiname09); break; case 10: strcpy(dateiname,dateiname10); break; } if ((fp=fopen(dateiname,"rb"))==NULL) { puts("an error occur (file is not present)!!! \007 \007 \007"); wait(); error=4711; } if (!error) { fflush(stdin); while ( !(kbhit()) && (ready=='N') ) { for (zeile=0;zeile<=479;++zeile) { if (kbhit()) break; for (spalte=0;spalte<=639;++spalte) { if (kbhit()) break; fread(&farbe_c,sizeof(char),1,fp); fflush(fp); switch(farbe_c) { case 'A': farbe=0; break; case 'B': farbe=1; break; case 'C': farbe=2; break; case 'D': farbe=3; break; case 'E': farbe=4; break; case 'F': farbe=5; break; case 'G': farbe=6; break; case 'H': farbe=7; break; case 'I': farbe=8; break; case 'J': farbe=9; break; case 'K': farbe=10; break; case 'L': farbe=11; break; case 'M': farbe=12; break; case 'N': farbe=13; break; case 'O': farbe=14; break; case 'P': farbe=MAXC; break; } putpixel(spalte,zeile,farbe); } } ready='Y'; } fclose(fp); } getch(); fflush(stdin); closegraph(); }/*get_file*/ /***************************************************************************/ /***************************************************************************/ void put_file(int farbe,char painting,int file_nr,char ready,char user_break,char save) { char farbe_c; //compress file input static char *dateiname="z:\\wilhelm.zzz\\apple01.zzz"; // 31 char *dateiname01="b:\\pictures\\apple01.pic"; char *dateiname02="b:\\pictures\\apple02.pic"; char *dateiname03="b:\\pictures\\apple03.pic"; char *dateiname04="b:\\pictures\\apple04.pic"; char *dateiname05="b:\\pictures\\apple05.pic"; char *dateiname06="b:\\pictures\\apple06.pic"; char *dateiname07="b:\\pictures\\apple07.pic"; char *dateiname08="b:\\pictures\\apple08.pic"; char *dateiname09="b:\\pictures\\apple09.pic"; char *dateiname10="b:\\pictures\\apple10.pic"; static FILE *fp; if ( (painting == 'N') && (user_break == 'N') ) { switch(file_nr) { case 1: strcpy(dateiname,dateiname01); break; case 2: strcpy(dateiname,dateiname02); break; case 3: strcpy(dateiname,dateiname03); break; case 4: strcpy(dateiname,dateiname04); break; case 5: strcpy(dateiname,dateiname05); break; case 6: strcpy(dateiname,dateiname06); break; case 7: strcpy(dateiname,dateiname07); break; case 8: strcpy(dateiname,dateiname08); break; case 9: strcpy(dateiname,dateiname09); break; case 10: strcpy(dateiname,dateiname10); break; } printf("FILE_NR: %10d\n",file_nr); if ((fp=fopen(dateiname,"wb"))==NULL) { puts("an error occur !!! \007 \007 \007"); getch(); } compress(farbe,&farbe_c); fwrite(&farbe_c,sizeof(char),1,fp); fflush(fp); } if ( (painting == 'Y') && (user_break == 'N') ) { compress(farbe,&farbe_c); fwrite(&farbe_c,sizeof(char),1,fp); fflush(fp); } if ( (ready == 'Y') && (user_break == 'N') ) { fclose(fp); } if ( (user_break == 'Y') && (save == 'Y') ) { fclose(fp); } }/*put_file*/ /***************************************************************************/ /***************************************************************************/ void wait(void) { int x,y; x=wherex(); y=wherey(); gotoxy(50,25); fflush(stdin); printf("go on ...press any key"); getch(); fflush(stdin); gotoxy(50,25); printf(" "); gotoxy(x,y); }/*wait*/ /***************************************************************************/ /***************************************************************************/ void message(char inform) { int x,y; x=wherex(); y=wherey(); gotoxy(35,25); if (inform=='Y') printf("use letter >>> b <<< for finish input"); if (inform=='N') printf(" "); if (inform=='9') printf("input range: 0001 ... 9999"); gotoxy(x,y); }/*message*/ /***************************************************************************/ /***************************************************************************/ void compress(int farbe,char *farbe_c) { switch(farbe) { case 0: *farbe_c='A'; break; case 1: *farbe_c='B'; break; case 2: *farbe_c='C'; break; case 3: *farbe_c='D'; break; case 4: *farbe_c='E'; break; case 5: *farbe_c='F'; break; case 6: *farbe_c='G'; break; case 7: *farbe_c='H'; break; case 8: *farbe_c='I'; break; case 9: *farbe_c='J'; break; case 10: *farbe_c='K'; break; case 11: *farbe_c='L'; break; case 12: *farbe_c='M'; break; case 13: *farbe_c='N'; break; case 14: *farbe_c='O'; break; case 15: *farbe_c='P'; break; } }/*compress*/ /***************************************************************************/ /***************************************************************************/ void disk(void) { char disk_c; //disk_current int result=0; disk_c=bdos(0x19,0,0)+'A'; //........................................................................... if (disk_c=='C') { result=spawnl(P_WAIT,"C:\\dos\\ASSIGN.COM","assign.com","B=C",NULL); if (result == -1) { perror("ERROR from spawnl"); } } //........................................................................... if (disk_c=='A') { result=spawnl(P_WAIT,"C:\\dos\\ASSIGN.COM","assign.com","B=A",NULL); if (result == -1) { perror("ERROR from spawnl"); } } //........................................................................... }/*disk*/ /***************************************************************************/