The shapes and colours that you can see when you rub your eyes are known as phosphenes. They were a subject of debate from the time of the ancient Greeks. But why do we see stars when we rub our eyes?
Scientists now say that rubbing your eyes increases the pressure within the eyeball and this pressure activates ganglion cells in the retina in the same way as light does. With this, you are tricking your brain into interpreting the activation as though you were seeing light from the world outside.
Most common phosphenes are diffuse blobs of different colours that move with the rubbing. Then there are scintillating and rapidly moving grid-like patterns which probably reflect the organisation of cells higher up in the visual system. These patterns can also be associated with psychedelic paintings as the major hallucinogens also affect the visual system. Other effects include an array of intense blue points of light.
If you want to experience these, you need to be careful and press gently for some time. Make sure you are not putting too much pressure to avoid any potential damage to the eye.