Scientists studied the well-preserved remains of a dinosaur and found that it exhibited a defense mechanism similar to camouflage in present-day animals, called countershading. By recreating the color patterns of a small Psittacosaurus, they also determined its likely habitat — dense forests.

The study published Thursday in the journal Current Biology found that the dinosaur, whose name literally means parrot lizard, was light on its underside with a darker top. The Psittacosaurus genus existed around 120 million years ago, in the early Cretaceous period, in present-day China, coinciding with the time when several large predators also roamed the region.

The researchers believe the dinosaur used countershading for protection against predators that used the shadow patterns on an object to figure out the object’s shape.

“The fossil, which is on public display at the Senckenberg Museum of Natural History in Germany, preserves clear countershading, which has been shown to function by counter-illuminating shadows on a body, thus making an animal appear optically flat to the eye of the beholder,” Jakob Vinther, from the University of Bristol in the U.K. and co-author of the study, said in a statement.

Vinther and his team realized that fossils preserve structures called melanosomes which carry melanin pigments, and in well preserved specimens, it is possible to see these melanin patterns without the use of a microscope. Partnering with Bristol-based palaeoartist, Bob Nicholls, the team created what they say is the “most scientifically accurate life-size model of a dinosaur with its real color patterns.”

“Our Psittacosaurus was reconstructed from the inside-out. There are thousands of scales, all different shapes and sizes, and many of them are only partially pigmented,” Nichols said. “It was a painstaking process but we now have the best suggestion as to what this dinosaur really looked like.”

The researchers studied photographs of the shadow patterns on the model they created under an open sky and under trees. On comparing the photographs with the patterns on the fossil, they were able to determine what kind of environment the dinosaur lived in.

“We predicted that the Psittacosaur must have lived in a forest. This demonstrates that fossil color patterns can provide not only a better picture of what extinct animals looked like, but they can also give new clues about extinct ecologies and habitats,” Vinther said.