I share you a nice Black Hole simulation at the approximation

Here the code :
Code: Select all
EnableExplicit
#Width = 800
#Height = 600
Structure Particle
angle.f
radius.f
x.f
y.f
z.f
EndStructure
Global NewList Particles.Particle()
Procedure InitParticles(count)
Protected i
For i = 0 To count
AddElement(Particles())
Particles()\angle = Random(360)
Particles()\radius = 1.5 + Random(100) / 50.0
Particles()\x = Particles()\radius * Cos(Radian(Particles()\angle))
Particles()\y = 0
Particles()\z = Particles()\radius * Sin(Radian(Particles()\angle))
Next
EndProcedure
Procedure InitGL()
glEnable_(#GL_DEPTH_TEST)
glEnable_(#GL_POINT_SMOOTH)
glPointSize_(3.0)
EndProcedure
Procedure DrawSphere(radius.f, latRes.i = 16, lonRes.i = 16)
Protected i, j
Protected theta1.f, theta2.f
Protected phi1.f, phi2.f
Protected x1.f, y1.f, z1.f
Protected x2.f, y2.f, z2.f
For i = 0 To latRes - 1
theta1 = i * #PI / latRes
theta2 = (i + 1) * #PI / latRes
glBegin_(#GL_TRIANGLE_STRIP)
For j = 0 To lonRes
phi1 = j * 2 * #PI / lonRes
x1 = radius * Sin(theta1) * Cos(phi1)
y1 = radius * Cos(theta1)
z1 = radius * Sin(theta1) * Sin(phi1)
x2 = radius * Sin(theta2) * Cos(phi1)
y2 = radius * Cos(theta2)
z2 = radius * Sin(theta2) * Sin(phi1)
glVertex3f_(x1, y1, z1)
glVertex3f_(x2, y2, z2)
Next
glEnd_()
Next
EndProcedure
Procedure RenderScene()
glViewport_(0, 0, #Width, #Height)
glMatrixMode_(#GL_PROJECTION)
glLoadIdentity_()
gluPerspective_(45.0, #Width / #Height, 0.1, 100.0)
glTranslatef_(0.0, 0.0, -1.0)
glMatrixMode_(#GL_MODELVIEW)
glLoadIdentity_()
glClearColor_(0.0, 0.0, 0.0, 1.0)
glClear_(#GL_COLOR_BUFFER_BIT | #GL_DEPTH_BUFFER_BIT)
gluLookAt_(0, 2, 6, 0, 0, 0, 0, 1, 0)
; Central black hole
glPushMatrix_()
glColor3f_(0.0, 0.0, 0.0)
DrawSphere(1.5, 20, 20)
glPopMatrix_()
; violet particles (horizon)
glBegin_(#GL_POINTS)
glColor3f_(1.0, 0.0, 1.0) ; violet
ForEach Particles()
; Update for angle in rotation
Particles()\angle + 0.5
If Particles()\angle > 360
Particles()\angle = 0
EndIf
; Coordinates in a circle around the black hole
Particles()\x = Particles()\radius * Cos(Radian(Particles()\angle))
Particles()\z = Particles()\radius * Sin(Radian(Particles()\angle))
; === Manual Gravitational Warp ===
Define strength.f = 0.4 ; Intensity of deformation
Define falloff.f = 0.9 ; Bigger = more spread out
Particles()\y = strength * Exp( -Pow(Particles()\z, 2) / falloff )
; Show particle
glVertex3f_(Particles()\x, Particles()\y, Particles()\z)
Next
glEnd_()
FlipBuffers()
EndProcedure
; === MAIN ===
InitKeyboard()
; Creates a true cross-platform OpenGL window
If OpenWindow(0, 0, 0, #Width/DesktopResolutionX(), #Height/DesktopResolutionY(), "Black Hole Simulation", #PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0), 0, 0, #Width, #Height, 0, 0, 0)
SetFrameRate(60)
InitGL()
InitParticles(3000)
Repeat
RenderScene()
ExamineKeyboard()
If KeyboardPushed(#PB_Key_Escape)
Break
EndIf
ForEver
EndIf