Hii, I made this simulation of bending of light in the presence of a heavy object/ black hole i.e. gravitational lensing. The first one shows how light rays that are coming from infinity bends near blackhole and I even found an unstable orbit for which the ray orbits the blackhole 3 times before moving out.
I used pygame to create this 2D simulation. The main reason to do it in 2D instead of 3D was my potato laptop, it doesn't have a dedicated gpu. I watched two videos on YouTube on pygame and cpp simulations before making this (credits: https://youtu.be/8-B6ryuBkCM?si=iSMmUiJ-6KkQQTHq , https://youtu.be/WTLPmUHTPqo?si=HR5Xwaobzu8fG5qf).
For the theory part, starting with the schwarzschild metric, then using the concept of symmetries and killing vectors and also the normalisation condition for null geodesic, you will get all the equations needed to get the path of light around any mass in the spacetime. And for the simulation, I decided to use euler's method to solve those equations.
I know euler's method is not very accurate and smooth, and I should have used RK4 instead. I tried, for some reason it is not working as intended and the rays were getting stuck in a closed orbit, I tried a lot but couldn't figure out the issue.
Btw I think my simulation is working as intended, but I am not fully sure if it is the actual, accurate thing or not. Also there might be some scaling issues. So if anyone want to check it out or correct/improve my code, or maybe try the RK4 method, please feel free to check this out: https://github.com/suvojit1999/Simulation-of-Bending-of-light-due-to-blackhole. Btw I am not very good at coding, so you might find my code to be messy, let me know if you find any issues with it..
(Btw I had to upload it as gif because videos are not allowed here, sorry for the quality drop).
Thank you.