The optical properties of the flavylium state of the cyanin dye are simulated numerically by combining Car-Parrinello molecular dynamics and linear-response time-dependent density functional theory calculations. The spectrum of the dye calculated in the gas phase is characterized by two peaks in the yellow and in the blue (green and violet), using a GGA-PBE (hybrid-B3LYP) DFT functional, which would bring about a greenish (bright orange) color incompatible with the dark purple hue observed in nature. Describing the effect of the water solvent through a polarizable continuum model does not modify qualitatively the resulting picture. An explicit simulation of both solvent and thermal effects using ab initio molecular dynamics results instead in a spectrum that is compatible with the observed coloration. This result is analyzed in terms of the spectroscopic effects of the molecular distortions induced by thermal fluctuations.