Lisaju
-- Sebastian Pawlak
Pobierz plik lisaju.zip
Kod źródłowy pliku "lisaju.c":
/* Sebastian Pawlak * Lisaju z efektem plazmy * kompilator: DJGPP */ #include <stdio.h> #include <sys/nearptr.h> #include <sys/movedata.h> #include <go32.h> #include <dos.h> #include <math.h> #define GRAPHICS 0x013 #define TEXT 0x03 char bufor [320*200]; char pal [256*3]; void SetRGBblock(unsigned char *pal, unsigned char od_kol, unsigned short int ilosc) { int i; outportb (0x03c8,od_kol); for (i = 0; i < ilosc; i++) { outportb (0x03c9, *pal++); outportb (0x03c9, *pal++); outportb (0x03c9, *pal++); } } void loadpalette(void) { int counter; FILE *palfile; if ((palfile = fopen("palette.pal", "rb")) == NULL) { fprintf(stderr,"Error opening PALETTE.PAL!\n"); exit(1); } // outportb(0x3C8,0); /* 0x3C8 = VGA DAC, initial color index */ for (counter = 0; counter < 768; counter++) { pal[counter] = fgetc(palfile); } fclose(palfile); } void InitGraph(int mode) { union REGS regs; regs.x.ax = mode; int86(0x10, ®s, ®s); } int main(void) { short x1 = 100, y1 = 80, x2 = 320 - 100, y2 = 120; float vx1 = 0, vy1 = 0, vx2 = 0,vy2 = 0; short i, j; char c; unsigned short offs; /* usuwam wszystkie zabezpieczenia pamieci */ __djgpp_nearptr_enable(); /* wlacza tryb graficzny 320x200 256 kolorow */ InitGraph(GRAPHICS); loadpalette (); SetRGBblock (pal,0,256); while (!kbhit()) { x1 += (int)vx1; y1 += (int)vy1; x2 += (int)vx2; y2 += (int)vy2; vx1 += (x2 - x1) / 40.0; vy1 += (y2 - y1) / 10.0; vx2 += (x1 - x2) / 60.0; vy2 += (y1 - y2) / 50.0; offs = 0; for (j = 0; j < 200; j++) for (i = 0; i < 320; i++) { c = (char) (sqrt(sqrt((float) ((x1-i)*(x1-i)+(y1-j)*(y1-j))* ((x2-i)*(x2-i)+(y2-j)*(y2-j))))); bufor[offs++] = c; } movedata (_my_ds(),(int)bufor,_dos_ds,(int)0xa0000,320*200); } /* wlacz tryb tekstowy */ InitGraph(TEXT); /* przywraca poprzednie zabezpieczenia pamieci */ __djgpp_nearptr_disable(); return 0; }