Richard Matheson, whose novels, short stories, screenplays and teleplays drew the blueprints for dozens of science fiction and horror movies and television shows, died on Sunday at his home in Calabasas, Calif. He was 87.

His death was confirmed by his son Richard Christian, known as R. C.

Mr. Matheson had a prolific imagination for the “what if?” story, and he drew his ideas from both actual events and other stories. After the unsettling experience of being tailgated by a truck driver, he wrote the short story “Duel,” about a motorist who is relentlessly stalked in a highway chase by a tractor-trailer, its driver unseen. The story became the basis for Steven Spielberg’s first feature film, starring Dennis Weaver.

An early novel, and perhaps his best-known work, “I Am Legend,” about the last surviving human in a world in which everyone else is a vampire, was published in 1954 and adapted in 1964 as “The Last Man on Earth” with Vincent Price, in 1971 as “The Omega Man” with Charlton Heston and in 2007 as “I Am Legend” with Will Smith.

Mr. Matheson was inspired to write it while watching the 1931 film version of “Dracula.”

“My mind drifted off, and I thought, ‘If one vampire is scary, what if the whole world is full of vampires?’ ” Mr. Matheson said in an interview with the Archive of American Television.