The Science behind it:
Light Need Not Apply
One common misconception about a human’s vision is that our eyes require light (photons) to be stimulated. Even in the absence of photons, the neurons in our visual system are always active. The thalamus (part of the brain responsible for relaying sensory signals), your visual cortex, and your retina are in an “always on” state – even while you sleep. The neurons in these visual systems are continuously relaying signals and information.
This continuous activity is sometimes referred to as background activity. It’s this background activity that is responsible for your trippy visuals and interesting patterns in the absence of light. The technical term for this phenomena is a “Phosphene“.
When you are in a completely dark room or just closing your eyes to go to sleep, the neurons in your visual system will spontaneously fire, and in doing so, will activate other visual neurons and so on. These neurons acting together collectively are what is causing those interesting and strange visual effects. The colors, duration, frequency, duration and type of effects seen will vary depending on which part of the visual system the neurons are acting up in.
“Seeing stars” is another common phosphene or visual effect that can occur, and is most common immediately after blowing your nose, intense laughter, a sneeze, a heavy cough, a blow to the head, or standing up too quickly. However, these phosphenes are usually the result of mechanical or metabolic stimulation, as opposed to spontaneous activity.
Low blood pressure, low oxygenation or a lack of glucose are most common causes of metabolic stimulation. Certain drugs can also produce metabolic stimulation of the visual system to varying degrees, the most potent and well known among them being LSD and psilocybin.
http://zidbits.com/2013/03/what-are-the-colors-you-see-when-you-shut-your-eyes/
Hope this helps 🙂
Have a wonderful day <3
Ash