The two sets of grey patches in the illustration are identical. (If you don't believe it, look at the source code for the applet. You can download the program and experiment with it yourself.) A light background makes the grey patches look darker; a dark background makes them look lighter. This effect is called simultaneous contrast.
There seems to be more contrast between the grey patches when they are on a dark background than when they are on a light background. The three greys look more similar to each other when they are on a light background. This effect is called the surround effect. I don’t understand it.