Three years ago, a farmer in the Hebei province of China uncovered a mysterious fossil and brought it to the the Paleontological Museum of Liaoning. Now, after studying the find, scientists have announced that the fossil is of a new, duck-sized dinosaur—and when it lived it had an incredible feather display that shined like a living rainbow.

An international team of scientists studying the dinosaur, called Caihong juji, made the discovery by carefully analyzing tiny melanosomes, the part of the cells that contain pigment, in the fossil, which turned up dramatic evidence of the dinosaur’s flamboyant plumage.

Their research was published by the journal Nature Communications on Monday.

In animals, colors are determined by the shape of the melanosomes, as well as pigment. “Hummingbirds have bright, iridescent feathers, but if you took a hummingbird feather and smashed it into tiny pieces, you’d only see black dust,” explained Chad Eliason, a postdoctoral researcher at Chicago's Field Museum of Natural History, in a press release. “The pigment in the feathers is black, but the shapes of the melanosomes that produce that pigment are what make the colors in hummingbird feathers that we see.”

Researchers looked at 66 places on the fossil under a microscope to see if they could find remnants of melanosome shapes. They found flat, circular melanosomes organized in rows on Caihong’s head, chest and tail. Those melanosomes could be compared to modern birds, whose iridescent feathers’ melanosomes have the same shape. The discovery indicates that parts of Caihong’s feather coat were luminous and multicolored, like a hummingbird’s throat.

It’s unclear exactly when iridescence evolved in birds, but Caihong gives us an idea. This 161-million-year-old fossil is the oldest example of iridescence in a feathered dinosaur yet discovered.

Today, birds with iridescence, such as male birds of paradise, use their flashy colors to attract mates. But it's a tactic used by non-avian members of the animal kingdom too. Peacock spiders, for example, rely on tiny iridescent scales when mating.

Caihong is also helping scientists understand how other traits developed in birds. The dinosaur had a crest on its head, a long wing and tail feathers, but it couldn’t fly. It is also the oldest known example of a dinosaur with asymmetrical tail feathers, meaning that the vane on one side was bigger than on the other.