It can make you see colored dots, if you have worked too long and your eyes don't have a rest a whole day because of tiredness. Also it happens when you stare at a very bright light for a while. In addition, the same thing happens when you go from the dark to light, you goanna see many dots, but after minutes they will be gone. But don't worry too much about it, because it is normal.
It's common to see colored dots, so you don't have to worry about it. Usually, when you're in the light condition for a long time, suddenly you get into a dark room, you will see many colored dots, red, green, yellow etc. But if it often happens, and the symptom doesn't disappear after a few minutes, you'd better go to see an eye doctor. As for the prevention, I think you should let your eyes rest when your eyes get tired.