Category : Printer + Display Graphics
Archive   : SPIN.ZIP
Filename : GALAXY.PAS

 
Output of file : GALAXY.PAS contained in archive : SPIN.ZIP
Program Galaxy;

(* This program generates an AcroSpin file called GALAXY.FIL that displays a *)
(* spiral galaxy. You can change the number of stars, the color of the stars *)
(* near the center of the galaxy, and the color of the stars in the arms, by *)
(* changing the following constants. *)
(* David B. Parker *)

(* Constants. *)

Const StarColor1 = 15; (* Color of stars near the center. *)
StarColor2 = 11; (* Color of stars in the arms. *)
NumberOfStars = 500; (* Number of stars. *)
Scale = 10000.0; (* Scale factor to use. *)

(* Types. *)

Type ColorArrayType = Array[0..1] Of Integer;

(* Array of colors to use for stars. *)

Const ColorArray: ColorArrayType = ( StarColor1,StarColor2 );

(* Variables. *)

Var I : Integer; (* Looping variable. *)
X, Y, Z : Real; (* Spherical coordinates. *)
NewX, NewY, NewZ: Real; (* Transformed coordinates. *)
Radius : Real; (* Radius from center. *)
CosAngle : Real; (* Cosine of angle. *)
SinAngle : Real; (* Sine of angle. *)
Output : Text; (* Output file. *)

(* Open the output file for writing. *)

Begin
Assign(Output,'GALAXY.FIL');
Rewrite(Output);

(* Generate a spherically symmetric distribution of stars. *)

Randomize;
For I := 1 To 10 Do Z := Random; (* Excercise the random number generator. *)
For I := 1 To NumberOfStars Do
Begin
Radius := 2.0;
While (Radius = 0.0) Or (Radius > 1.0) Do
Begin
X := 2.0*Random-1.0;
Y := 2.0*Random-1.0;
Z := 2.0*Random-1.0;
Radius := Sqrt(Sqr(X)+Sqr(Y)+Sqr(Z));
End;
X := X/Radius;
Y := Y/Radius;
Z := Z/Radius;

(* Squash it to an elliptical distribution. *)

Radius := Random;
NewX := Radius*X;
NewZ := Radius*Z/3.5;
NewY := Radius*Y*Exp(-40.0*(Sqr(NewX)+Sqr(NewZ)))/7.0;
Radius := Sqrt(Sqr(NewX)+Sqr(NewZ));

(* If the star is near the center, use a spherical distribution. *)

If Radius < 0.15 Then
Begin
Radius := Sqrt(Random)*0.15;
NewX := Radius*X;
NewZ := Radius*Z;
NewY := Radius*Y;
End;

(* To generate the arms, rotate the stars proportional to their distance from *)
(* the center of the galaxy. *)

SinAngle := Sin(Pi/4.0+2.0*Pi*Abs(Radius));
CosAngle := Cos(Pi/4.0+2.0*Pi*Abs(Radius));

(* Write out the endpoints for the stars. *)

Writeln(Output,'EndPoint X ',Round(Scale*(NewX*CosAngle-NewZ*SinAngle)),
' Y ',Round(Scale*NewY),
' Z ',Round(Scale*(NewX*SinAngle+NewZ*CosAngle)),
' Name P',I);
Writeln(Output,'Line From P',I,' To P',I,
' Color ',ColorArray[Round(Radius*1.49)]);
End;

(* Close the output file. *)

Close(Output);
End.


  3 Responses to “Category : Printer + Display Graphics
Archive   : SPIN.ZIP
Filename : GALAXY.PAS

  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/