The colorful feathers of peacocks are primarily the result of sexual selection. Peacocks use their vibrant plumage to attract peahens during mating season; the more elaborate and brilliant the feathers, the more appealing the male is to potential mates.
The feathers also serve a display function. When a peacock fans out its tail, it creates a dazzling spectacle visible from afar, which can intimidate rivals and attract mates.
Additionally, the bright colors and patterns may offer some protection from predators by helping to camouflage the peacock in certain environments.