## Star Field

I thought someone might like this starfield I created.
It has 3 planes, with different amounts of stars, and the acceleration of
the stars is set in a variable, or rather a constant.  It is the best one
I have done.

uses
CRT, Graph;

TYPE
XA1 = ARRAY[0..200] OF INTEGER;
XA2 = ARRAY[0..120] OF INTEGER;
XA3 = ARRAY[0..40] OF INTEGER;
YA1 = ARRAY[0..200] OF INTEGER;
YA2 = ARRAY[0..120] OF INTEGER;
YA3 = ARRAY[0..40] OF INTEGER;

PROCEDURE PLACESTARS(VAR X1:XA1;
X2:XA2;
X3:XA3;
Y1:YA1;
Y2:YA2;
Y3:YA3);
VAR
COUNT:INTEGER;
X,Y:REAL;

BEGIN
RANDOMIZE;
FOR COUNT:=0 TO 200 DO
BEGIN
X:=RANDOM(640);
Y:=RANDOM(480);
X1[COUNT]:=ROUND(X);
Y1[COUNT]:=ROUND(Y);
END;

FOR COUNT:=0 TO 120 DO
BEGIN
X:=RANDOM(640);
Y:=RANDOM(480);
X2[COUNT]:=TRUNC(X);
Y2[COUNT]:=TRUNC(Y);
END;

FOR COUNT:=0 TO 40 DO
BEGIN
X:=RANDOM(640);
Y:=RANDOM(480);
X3[COUNT]:=TRUNC(X);
Y3[COUNT]:=TRUNC(Y);
END;
END;

PROCEDURE MOVESTARS;

VAR
X1:XA1;
X2:XA2;
X3:XA3;
Y1:YA1;
Y2:YA2;
Y3:YA3;
RATEX1,RATEX2,RATEX3:INTEGER;
ACCELX,ACCELY,COUNT:INTEGER;

BEGIN
ACCELX:=10;
ACCELY:=40;
RATEX1:=3;
RATEX2:=2;
RATEX3:=1;
REPEAT
FOR COUNT:=0 TO 200 DO
BEGIN
PUTPIXEL(X1[COUNT],Y1[COUNT],0);
IF X1[COUNT]<=320 THEN X1[COUNT]:=X1[COUNT]-((320-X1[COUNT]) DIV ACCELX)-RATEX1;
IF X1[COUNT]>320 THEN X1[COUNT]:=X1[COUNT]+((X1[COUNT]-320) DIV ACCELX)+RATEX1;
IF X1[COUNT]<0 THEN X1[COUNT]:=TRUNC(RANDOM(640));
IF X1[COUNT]>640 THEN X1[COUNT]:=TRUNC(RANDOM(640));
IF Y1[COUNT]>240 THEN Y1[COUNT]:=Y1[COUNT]+((Y1[COUNT]-240) DIV ACCELY)+RATEX1;
IF Y1[COUNT]<=240 THEN Y1[COUNT]:=Y1[COUNT]-((240-Y1[COUNT]) DIV ACCELY)-RATEX1;
IF Y1[COUNT]<0 THEN Y1[COUNT]:=TRUNC(RANDOM(480));
IF Y1[COUNT]>480 THEN Y1[COUNT]:=TRUNC(RANDOM(480));
PUTPIXEL(X1[COUNT],Y1[COUNT],15);
END;
FOR COUNT:=0 TO 120 DO
BEGIN
PUTPIXEL(X2[COUNT],Y2[COUNT],0);
IF X2[COUNT]<=320 THEN X2[COUNT]:=X2[COUNT]-((320-X2[COUNT]) DIV ACCELX)-RATEX2;
IF X2[COUNT]>320 THEN X2[COUNT]:=X2[COUNT]+((X2[COUNT]-320) DIV ACCELX)+RATEX2;
IF X2[COUNT]<0 THEN X2[COUNT]:=TRUNC(RANDOM(640));
IF X2[COUNT]>640 THEN X2[COUNT]:=TRUNC(RANDOM(640));
IF Y2[COUNT]>240 THEN Y2[COUNT]:=Y2[COUNT]+((Y2[COUNT]-240) DIV ACCELY)+RATEX2;
IF Y2[COUNT]<=240 THEN Y2[COUNT]:=Y2[COUNT]-((240-Y2[COUNT]) DIV ACCELY)-RATEX2;
IF Y2[COUNT]<0 THEN Y2[COUNT]:=TRUNC(RANDOM(480));
IF Y2[COUNT]>480 THEN Y2[COUNT]:=TRUNC(RANDOM(480));
PUTPIXEL(X2[COUNT],Y2[COUNT],7);
END;
FOR COUNT:=0 TO 40 DO
BEGIN
PUTPIXEL(X3[COUNT],Y3[COUNT],0);
IF X3[COUNT]<=320 THEN X3[COUNT]:=X3[COUNT]-((320-X3[COUNT]) DIV ACCELX)-RATEX3;
IF X3[COUNT]>320 THEN X3[COUNT]:=X3[COUNT]+((X3[COUNT]-320) DIV ACCELX)+RATEX3;
IF X3[COUNT]<0 THEN X3[COUNT]:=TRUNC(RANDOM(640));
IF X3[COUNT]>640 THEN X3[COUNT]:=TRUNC(RANDOM(640));
IF Y3[COUNT]>240 THEN Y3[COUNT]:=Y3[COUNT]+((Y3[COUNT]-240) DIV ACCELY)+RATEX3;
IF Y3[COUNT]<=240 THEN Y3[COUNT]:=Y3[COUNT]-((240-Y3[COUNT]) DIV ACCELY)-RATEX3;
IF Y3[COUNT]<0 THEN Y3[COUNT]:=TRUNC(RANDOM(480));
IF Y3[COUNT]>480 THEN Y3[COUNT]:=TRUNC(RANDOM(480));
PUTPIXEL(X3[COUNT],Y3[COUNT],8);
END;
UNTIL KEYPRESSED;
END;

PROCEDURE GRAPHINIT;

var
grDriver : Integer;
grMode   : Integer;
ErrCode  : Integer;
begin
grDriver := Detect;
InitGraph(grDriver,grMode,'M:\DOSAPPS\TP6.0\BGI');
ErrCode := GraphResult;
if ErrCode <> grOk then
WriteLn('Graphics error:',
GraphErrorMsg(ErrCode));
end;

VAR
X1:XA1;
X2:XA2;
X3:XA3;
Y1:YA1;
Y2:YA2;
Y3:YA3;
CH:CHAR;

BEGIN
GRAPHINIT;
PLACESTARS(X1,X2,X3,Y1,Y2,Y3);
MOVESTARS;
CLOSEGRAPH
END.

*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*
{    /^\    ****    /^\                                      }
{   |   |**/____\**|   |                                     }
{  /                    \   In a world of constant change    }
{ |   (-)         (-)    |  Only one thing remains the same; }
{  \__                __/   Fortunately, it's not the fox.   }
{  ----\-*        *-/----                                    }
{    ----\-*    *-/----      Tsw...@lonestar.jpl.utsa.edu    }
{          \____/                                            }
{            **                      F O X M A N             }
*<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*