home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
AMOS PD CD
/
amospdcd.iso
/
sourcecode
/
various
/
galaxies.amos
/
galaxies.amosSourceCode
Wrap
AMOS Source Code
|
1990-04-07
|
6KB
|
196 lines
Rem Colliding Galaxies
Rem Algorithm by Andrew Rankin 1989
Rem Amiga conversion by Jeff Tullin 1991
'
Set Buffer 80
Screen Open 1,640,320,4,Hires
Ink 0 : Paper 0 : Pen 0 : Print : Curs Off
Screen Open 0,640,320,4,Hires
Ink 0 : Paper 0 : Pen 0 : Print : Curs Off
Dim X#(1000),Y#(1000),Z#(1000),U#(1000),V#(1000),W#(1000)
Global GALC,A$
Hide On
'
Repeat
Repeat
Gosub SETUP
Locate 5,26 : Print "Setup complete - select (A)lter setup , (R)un simulation , (E)xit [ ]"
Locate 74,26 : Clear Key : Repeat : A$=Upper$(Inkey$) : Until(A$="A") or(A$="R") or(A$="E") : Print A$
Until A$<>"A"
If A$="R" Then Gosub SIMULATION
Until A$="E"
End
'
SETUP:
Screen 0
Cls 0 : Paper 0 : Pen 2
GALR#=30 : GALM#=5 : GALRI#=10 : GALC=12 : MZ=2
Locate 13,0 : Print "Colliding Galaxies Simulation. Amiga version 1.0"
Print
Print "This program simulates the passing of two galaxies in close proximity."
Print "To simplify calculations of star positions it is assumed that all of the"
Print "galactic mass is at the centre, and ignores the gravitational effects of any"
Print "surrounding stars. It is also assumed that the effect of forces other than "
Print "gravity are negligible. The target galaxy is taken to be a disk of stars in"
Print "stable circular orbit with zero drift velocity, while the intruder is taken as"
Print "a point of comparable mass."
Locate 1,12 : Print "SET UP:" : Locate 1,13 : Print "In the target galaxy:"
Locate 10,14 : Input "How many rings of stars are required? ";RINGS
Locate 10,15 : Input "How many stars per ring are required? ";STPR
If RINGS=1 Then Inc RINGS
STARS=STPR*RINGS : DR#=(GALR#-GALRI#)/(RINGS-1)
Print " The target galaxy is located at coordinates (0,0,0) with zero drift velocity,"
Print " and mass 5.0 units."; : Print STARS;" stars rotate in orbits of 10 to 30 units."
Locate 1,19 : Print "For the intruder galaxy:"
Locate 10,20 : Input "Mass as a fraction (%) of target galaxy? ";MASSFR#
Locate 10,21 : Print "Distance from target galaxy:"
Locate 10,22 : Input "X (-70 to 70) ? ";D#
Locate 33,22 : Input "Y (-70 to 70) ? ";E#
Locate 56,22 : Input "Z (-35 to 35) ? ";F#
Locate 10,23 : Print "Velocity components:"
Locate 10,24 : Input "X ? ";R#
Locate 33,24 : Input "Y ? ";S#
Locate 56,24 : Input "Z ? ";T#
Screen Copy 0 To 1
Return
'
SIMULATION:
Screen 0 : Cls 0
Curs Off
M#=GALM#
N#=M#*MASSFR#/100
A#=150 : B#=100 : C#=0 : D#=A#+D# : E#=E#+B# : F#=F#+C#
O#=0 : P#=0 : Q#=0
T=0 : I=0 : SF#=2
Locate 14,0 : Print "Colliding Galaxies Simulation. Amiga version 1.0"
Locate 15,1 : Print "--------Target Galaxy--------"
Locate 49,1 : Print "-------Intruder Galaxy-------"
Locate 17,2 : Print "- start:"
Locate 35,2 : Print "- now:"
Locate 51,2 : Print "- start:"
Locate 69,2 : Print "- now:"
Locate 1,3 : Print "Mass" : Locate 15,3 : Print M# : Locate 31,3 : Print M#
Locate 49,3 : Print N# : Locate 65,3 : Print N#
Print " X coordinate"
Print " Y coordinate"
Print " Z coordinate"
Print " Velocity (X)"
Print " Velocity (Y)"
Print " Velocity (Z)"
Print : Print " X-Y plane X-Z plane (Z shown * 2) Time"
Locate 15,4 : Print A# : Locate 49,4 : Print D# : Locate 15,5 : Print B# : Locate 49,5 : Print E#
Locate 15,6 : Print C# : Locate 49,6 : Print F# : Locate 15,7 : Print O# : Locate 49,7 : Print R#
Locate 15,8 : Print P# : Locate 49,8 : Print S# : Locate 15,9 : Print Q# : Locate 49,9 : Print T# : Locate 75,11 : Print T
For J=0 To RINGS-1
RAD#=J*DR#+GALRI#
VEL#=Sqr(M#/RAD#)
THETA#=0.5*VEL#/RAD#
If J=0 Then VEL#=0.9*VEL#
For K=0 To STPR-1
G#=K*2*Pi#/STPR
X#(I)=RAD#*Cos(G#)+150
Y#(I)=RAD#*Sin(G#)+100
Z#(I)=0
W#(I)=0
V#(I)=VEL#*Cos(G#-THETA#)
U#(I)=-VEL#*Sin(G#-THETA#)
Inc I
Next
Next
Screen Copy 0 To 1
Repeat
Screen 1
Gosub PL0TGALAXIES
Screen Copy 1 To 0
For I=0 To STARS-1
F1#=M#/((X#(I)-A#)^2+(Y#(I)-B#)^2+(Z#(I)-C#)^2+SF#)^1.5
F2#=N#/((X#(I)-D#)^2+(Y#(I)-E#)^2+(Z#(I)-F#)^2+SF#)^1.5
AX#=F1#*(A#-X#(I))+F2#*(D#-X#(I))
AY#=F1#*(B#-Y#(I))+F2#*(E#-Y#(I))
AZ#=F1#*(C#-Z#(I))+F2#*(F#-Z#(I))
U#(I)=U#(I)+AX#
V#(I)=V#(I)+AY#
W#(I)=W#(I)+AZ#
X#(I)=X#(I)+U#(I)
Y#(I)=Y#(I)+V#(I)
Z#(I)=Z#(I)+W#(I)
Next
RAD#=((A#-D#)^2+(B#-E#)^2+(C#-F#)^2+SF#)^1.5
AX#=(D#-A#)/RAD#
AY#=(E#-B#)/RAD#
AZ#=(F#-C#)/RAD#
O#=N#*AX#+O#
P#=N#*AY#+P#
Q#=N#*AZ#+Q#
R#=R#-M#*AX#
S#=S#-M#*AY#
T#=T#-M#*AZ#
A#=A#+O#
B#=B#+P#
C#=C#+Q#
D#=D#+R#
E#=E#+S#
F#=F#+T#
Inc T
If Inkey$<>""
Proc KEEPRESS
End If
Until Param=2
Proc NUL
Return
'
PL0TGALAXIES:
Pen 2
Locate 31,4 : Print A# : Locate 65,4 : Print D#
Locate 31,5 : Print B# : Locate 65,5 : Print E#
Locate 31,6 : Print C# : Locate 65,6 : Print F#
Locate 31,7 : Print O# : Locate 65,7 : Print R#
Locate 31,8 : Print P# : Locate 65,8 : Print S#
Locate 31,9 : Print Q# : Locate 65,9 : Print T#
Locate 75,11 : Print T
Ink 1 : Box 0,100 To 639,256 : Clip 0,100 To 639,256
G#=(M#*A#+N#*D#)/(M#+N#)
H#=(M#*B#+N#*E#)/(M#+N#)
I#=(M#*C#+N#*F#)/(M#+N#)
'
MZ=1
Ink 0
Bar 1,101 To 638,255
Ink 2
Proc D[(D#-G#)*4.267+320,320-((H#-E#)*4.267)]
Proc D[(D#-G#)*4.267+960,640-((I#-F#)*4.267*MZ+310)]
'
For I=0 To STARS-1
Proc PLT[(X#(I)-G#)*4.267+320,H#-Y#(I)*4.267+320]
Proc PLT[(X#(I)-G#)*4.267+960,(I#-Z#(I))*MZ*4.267]
Next
Return
Procedure D[A,B]
Circle A/2,B/2,2
End Proc
Procedure PLT[X,Y]
Y=640-Y
X=X/2 : Y=Y/4
Plot X,Y
End Proc
Procedure KEEPRESS
Q$=""
Clear Key
Screen Open 2,640,20,4,Hires
Cls 1 : Paper 1 : Screen Display 2,,200,,
Centre "Program halted. Save screen / Restart / Continue (S/R/C)?"
Repeat : Q$=Upper$(Inkey$)
F$=""
If Q$="S"
F$=(Fsel$(":","","Choose a filename","for this screenshot"))
End If
If F$<>""
Screen 0 : Save Iff(F$)
End If
Until(Q$="S") or(Q$="R") or(Q$="C")
Screen Close 2
Repeat : Until Inkey$=""
If Q$="R" Then L=2
End Proc[L]
Procedure NUL
End Proc[0]