How does the gravity field get drawn?

  • GodOfChaos
    6th September Member 0 Permalink

    I always wondered how those patterns are created. 

  • LBPHacker
    6th September Developer 0 Permalink
    The code is here.

    For each pixel position on the screen already containing information about the simulation, the gravity force vector is subtracted from it (see later), its components are rounded to the nearest integer, and the pixel at this new position is picked. Then this new pixel's colour is "added" (literal addition from grade 1) to the pixel's colour at the original position, component by component.

    This in itself would merely cause duplication of image data, so the code actually subtracts the gravity force from the pixel position in a tricky way: instead of converting each gravity force unit to a single pixel position unit, it converts a gravity force unit to 0.750, 0.875, 1.000 pixel position units for the R, G, B colour channels, respectively. This causes the image data to be duplicated at different distances from its origin *per colour channel*, which causes a chromatic aberration effect.
  • GodOfChaos
    6th September Member 0 Permalink

    @LBPHacker (View Post)

     By gravity field, i meant the one that shows up when you press Ctrl + G, not the gravitational lensing effect, which is what you just described...