LOS ANGELES – Ray Bradbury imagined the future, and didn’t always like what he saw.

In his books, the science fiction-fantasy master conjured a dark, depressing future where the government used fire departments to burn books in order to hold its people in ignorance and where racial hatred was so pervasive that some people left Earth for other planets.

At the same time, his work, just like the author himself, could also be joyful, whimsical and nostalgic, as when he was describing the magic of a Midwestern summer or the innocence and fearlessness of a boy who befriends a houseful of ghosts.

Bradbury, who died Tuesday at age 91, said often that all of his stories, no matter how fantastic or frightening they might be, were metaphors for everyday life and everything it entailed. And they all came from his childhood. “The great thing about my life is that everything I’ve done is a result of what I was when I was 12 or 13,” he said in 1982.

For more than 70 years, Bradbury spun tales that appeared in books and magazines, in the movie theater and on the television screen, firing the imaginations of generations of children, college kids and grown-ups across the world.

In many ways, he was always that 12-year-old boy who was inspired to become a writer after a chance meeting with a carnival magician called Mr. Electrico who, to Bradbury’s delight, tapped him with his sword and said: “Live forever!”

“I decided that was the greatest idea I had ever heard,” Bradbury said later. “I started writing every day. I never stopped.”

Many of his stories were fueled by the nightmares he suffered as a child growing up poor in the Midwest during the Great Depression. At the same time, though, they were tempered by the joy he found upon arriving with his family in glitzy Los Angeles in 1934.

Decades later he would still boast of hanging out at film studios and cajoling actors to sign autographs and pose for photos, even once getting 1930s movie queen Jean Harlow to kiss him on the cheek.

“What I have always been is a hybrid author,” Bradbury explained in 2009. “I am completely in love with movies, and I am completely in love with theater, and I am completely in love with libraries.”

Much of Hollywood was also in love with him, and tributes from actors, directors and other celebrities poured in upon news of his death.

“He was my muse for the better part of my sci-fi career,” director Steven Spielberg said in a statement. “He lives on through his legion of fans. In the world of science fiction and fantasy and imagination, he is immortal.”

Although he was slowed by a stroke in 1999 that forced him to use a wheelchair, Bradbury kept up socially and professionally.

As he had done for decades, he continued to write every day, trying to produce at least 1,000 words, in the basement of his home in the Cheviot Hills section of Los Angeles and to make frequent visits to book fairs, libraries and schools.

His writings ranged from horror and mystery to humor and sympathetic stories about the Irish, blacks and Mexican-Americans.

Bradbury also scripted John Huston’s 1956 film version of “Moby Dick” and wrote for “The Twilight Zone” and other television programs, including “The Ray Bradbury Theater,” for which he adapted dozens of his works.

He rose to literary fame in 1950 with “The Martian Chronicles,” a series of intertwined stories that satirized capitalism, racism and superpower tensions as it portrayed Earth colonizers destroying an idyllic Martian civilization.

His stories continue to be taught at high schools and universities.

“Kids still read him. They still love him. People come and go, but he’s one of those writers who continually engages young people. I think his legacy is going to last for a long time,” said Luis J. Rodriguez, author of “Always Running.” He added that Bradbury’s work helped inspire him to become a writer.

“The Martian Chronicles,” like Arthur C. Clarke’s “Childhood’s End” and the Robert Wise film “The Day the Earth Stood Still,” was a Cold War morality tale in which imagined lives on other planets serve as commentary on human behavior on Earth. It has been published in more than 30 languages, was made into a TV miniseries and inspired a computer game.

The “Chronicles” also prophesized the banning of books, especially works of fantasy. It was a theme Bradbury would take on fully in the 1953 release, “Fahrenheit 451.”

Inspired by the Cold War, the rise of television and the author’s passion for libraries, it was an apocalyptic narrative of nuclear war abroad and empty pleasure at home.

It was Bradbury’s only true science-fiction work, according to the author, who said all his other works should have been classified as fantasy. “It was a book based on real facts and also on my hatred for people who burn books,” he told The Associated Press in 2002.

A futuristic classic often taught alongside George Orwell’s “1984” and Aldous Huxley’s “Brave New World,” Bradbury’s novel also anticipated today’s world of iPods, interactive television, electronic surveillance and live, sensational media events.

Although involved in many futuristic projects, including the New York World’s Fair of 1964 and the Spaceship Earth display at Walt Disney World in Florida, Bradbury was deeply attached to the past. He refused to drive a car and shunned flying, saying a fatal traffic accident he witnessed as a child left him with a lifelong fear of automobiles.Bradbury’s literary style was honed in pulp magazines and influenced by Ernest Hemingway and Thomas Wolfe, and he became the rare science fiction writer treated seriously by the literary world.

In 2007, he received a special Pulitzer Prize citation. Seven years earlier, he received an honorary National Book Award medal for lifetime achievement, an honor given to Philip Roth and Arthur Miller among others.

Other honors included an Academy Award nomination for an animated film, “Icarus Montgolfier Wright,” and an Emmy for his teleplay of “The Halloween Tree.” His fame extended to the moon, where Apollo astronauts named a crater “Dandelion Crater,” in honor of “Dandelion Wine,” his beloved coming-of-age novel.

Born Ray Douglas Bradbury on Aug. 22, 1920, in Waukegan, Ill., the author once described himself as “that special freak, the man with the child inside who remembers all.”

His father, Leonard, a power company lineman, was a descendant of Mary Bradbury, who was tried for witchcraft at Salem, Mass.

Until near the end of his life, Bradbury resisted one of the innovations he helped anticipate: electronic books, likening them to burnt metal and urging readers to stick to the old-fashioned pleasures of ink and paper.

In late 2011, as the rights to “Fahrenheit 451” were up for renewal, he gave in and allowed his most famous novel to come out in digital form. In return, he received a great deal of money and a special promise from Simon & Schuster.

The publisher agreed to make the e-book available to libraries, the only Simon & Schuster e-book at the time that library patrons could download.

Bradbury is survived by his four daughters, Susan Nixon, Ramona Ostergren, Bettina Karapetian and Alexandra Bradbury. Marguerite Bradbury, his wife of 57 years, died in 2003.