Reptiles had colour vision and mammals evolved from them, but due to the reptiles dominance during the day the tiny early mammals;for many millions of years became nocturnal in order to avoid most of the diurnal, sun-loving reptiles. Mammals existed by night and just about survived in the reptile dominated world but lost their colour vision as it's not necessary at night.
After the extinction of the dinosaurs (except for birds) and other groups of reptiles and the end of reptile dominance the mammals engaged in a rapid evolutionary expansion to occupy the niches left behind. There was a fierce competition with the birds which didn't evolve into such diverse forms, so finally lost out.
As the birds evolved, in parallel with them new groups of plants diversified and many had symbiotic relationships with birds. The birds ate the fruits, that the plants evolved to attract them, so that their seeds would be spread over the maximum possible area. Now, it's no good if the birds eat unripe fruits that are nasty tasting and have seeds not yet ready to germinate so colour coding evolved to signal to the birds when the fruits were ready (birds still having reptile colour vision). So fruits that are ripe are red, orange, yellow etc, but not usually green. Green means unripe and birds avoid them.
The mammals meanwhile remained with black and white vision, except for a few like dogs or cows that evolved a limited colour vision for their lifestyles, but lacing in some of the spectrum that we see and with fewer photo-receptors per area than we have so the definition is not great.
But the primates, as they evolved in the trees, became fruit eaters, and thus needed to evolve colour vision to see what was good to eat.
So, our colour vision is due to our ancestors having to know when fruit was ripe.
After the extinction of the dinosaurs (except for birds) and other groups of reptiles and the end of reptile dominance the mammals engaged in a rapid evolutionary expansion to occupy the niches left behind. There was a fierce competition with the birds which didn't evolve into such diverse forms, so finally lost out.
As the birds evolved, in parallel with them new groups of plants diversified and many had symbiotic relationships with birds. The birds ate the fruits, that the plants evolved to attract them, so that their seeds would be spread over the maximum possible area. Now, it's no good if the birds eat unripe fruits that are nasty tasting and have seeds not yet ready to germinate so colour coding evolved to signal to the birds when the fruits were ready (birds still having reptile colour vision). So fruits that are ripe are red, orange, yellow etc, but not usually green. Green means unripe and birds avoid them.
The mammals meanwhile remained with black and white vision, except for a few like dogs or cows that evolved a limited colour vision for their lifestyles, but lacing in some of the spectrum that we see and with fewer photo-receptors per area than we have so the definition is not great.
But the primates, as they evolved in the trees, became fruit eaters, and thus needed to evolve colour vision to see what was good to eat.
So, our colour vision is due to our ancestors having to know when fruit was ripe.