Category : Printer + Display Graphics
Archive   : AI32BT.ZIP
Filename : STAR.C

 
Output of file : STAR.C contained in archive : AI32BT.ZIP
#include
#include
#include
#include
#include
#include
#include "xbit.h"

void far CalcNextStar(void);

double OffsetX = -0.5, OffsetY = 0.0, Scale = 0.35;
union _FIXED32BIT it, jt, iInit, jInit;
union _FIXED32BIT OffsetX32Bit, OffsetY32Bit, AspectX32Bit, AspectY32Bit;
double AspectX, AspectY;
int LastPeriod, NumRep, CheckEvery, Periodicity, RequiredRep = 5;
int Lastx, Lasty, Midx, Midy, x, y, n;

unsigned long ClockTick(void) {
union REGS Regs;

Regs.h.ah = 0;
int86(0x1a, &Regs, &Regs);
return((unsigned long)Regs.x.cx * Regs.x.dx);
}

void ResetAI(void) {
Lastx = Lasty = NumRep = 0;
Periodicity = LastPeriod = 1; /* First assume a periodicity of 1 */
CheckEvery = 3; /* Look for small patterns first */
}
void ResetAI(void);

int Check(void) {
/* Convert 'i' & 'j' to screen coord */
x = (int)(((it.L - OffsetX32Bit.L) / AspectX32Bit.L));
y = (int)(((jt.L - OffsetY32Bit.L) / AspectY32Bit.L));

/* Check for overflow */
if((x > 1000) || (x < -1000) || (y > 1000) || (y < -1000))
return(n);

/* XOR pixel to screen */
if(x || y) {
_setcolor(_getpixel(x, y) ^ 15);
_setpixel(x, y);
}

/* Is this point the same as the one I sampled earlier? */
if((x == Lastx) && (y == Lasty)) {

/* Is the number of iterations between now and when I last
saw this point the same as the time before? */
if(LastPeriod == Periodicity) {

/* Has this pattern repeated itself 'RequiredRep' times? */
if(NumRep++ == RequiredRep)
return(Periodicity); /* Yep, return the periodicity */
}

/* Nope, keep looking - maybe is will settle out */
else {
LastPeriod = Periodicity;
Periodicity = 1;
}
}

/* Time to pick a new sample point? */
else {
if(Periodicity++ >= CheckEvery) {
CheckEvery *= 1414; /* Look for larger patterns */
CheckEvery /= 1000;
Periodicity = 1;
Lastx = x;
Lasty = y;
NumRep = 0;
}
}
return(0);
}
int Check(void);

int ChkPoint(void) {
int Ret;

it = iInit;
jt = jInit;
ResetAI();
for(n = 1; n < 2000; n++) {
CalcNextStar();
Ret = Check();
if(Ret)
return(Ret);
}
return(14);
}
int ChkPoint(void);

void PlotPoint(int x, int y) {
DoubleToXBit((AspectX * x) + OffsetX, iInit.C);
DoubleToXBit((AspectY * y) + OffsetY, jInit.C);
ChkPoint();
n = ChkPoint();
if(n > 14)
n = 14;
_setcolor(n);
_setpixel(x, y);
}

void main(void) {
long ltime;
int Done = 0, Count;
struct videoconfig Vid;
union REGS Regs;

if(!_setvideomode(_VRES16COLOR)) {
if(!_setvideomode(_ERESCOLOR)) {
printf("Sorry, EGA or VGA required\n");
exit(1);
}
}

_getvideoconfig(&Vid);
Midx = Vid.numxpixels / 2;
Midy = Vid.numypixels / 2;
_setlogorg(Midx, Midy);

/* Set the integer bit conversions for 4 bytes with 15 integer bits.
This sets up a 32 bit number with a high word as the integer, i.e
one sign bit, 15 integer bits, and a 16 bit fraction
'(low word) / (2**16)'. */
SetXBit(4, 15);

/* Use low order word of clock byte as random seed */
Regs.h.ah = 0;
int86(0x1a, &Regs, &Regs);
srand(Regs.x.dx);

AspectX = (Scale * 10.0) / Vid.numxpixels;
AspectY = (Scale * 7.0) / Vid.numypixels;

OffsetX += 1.0 / Vid.numxpixels;
OffsetY += 1.0 / Vid.numypixels;

/* Convert aspects and offsets to 32 bit integer format */
DoubleToXBit(AspectX, AspectX32Bit.C);
DoubleToXBit(AspectY, AspectY32Bit.C);

DoubleToXBit(OffsetX, OffsetX32Bit.C);
DoubleToXBit(OffsetY, OffsetY32Bit.C);

while(!Done) {
x = (int)((((long)rand() * Vid.numxpixels) / 32767) - Midx);
y = (int)((((long)rand() * Vid.numxpixels) / 32767) - Midy);
if(!_getpixel(x, y))
PlotPoint(x, y);
if(kbhit())
Done = (getch() == 27);
}

_setvideomode(_DEFAULTMODE);
}



  3 Responses to “Category : Printer + Display Graphics
Archive   : AI32BT.ZIP
Filename : STAR.C

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/