Summary
In 1512, the Sforza family regained control of Milan.
 Ludovico Sforza was  long dead, and the ruler Maximilian had taken
his place.  With his patron  defeated, Leonardo decided to go to
Rome, where Leo X, a Medici, was now  pope.  He went there at the
behest of Giuliano de Medici, the pope's brother and  commander
of the papal troops.  He and his pupils Salai and Melzi  resided
in apartments in the Belvedere, a villa inside the walls of the
Vatican. 
During these three years in Rome, Leonardo pursued architecture,
hydraulics, and  the dynamics of mirrors.  At this time, the Medici
empire's fortune depended  largely on the dye industry, and Leonardo
attempted to fashion a parabolic solar  reflector that would speed
the boiling process essential to the making of dyes.  
And although he was also at work on various architectural projects
as well,  Leonardo appears to have been bored–at least, Vasari implies
that he was.   According to Vasari, Leonardo had to amuse himself
with pranks.  He had always  been given to writing riddles, but,
if Vasari is to be believed, he now did  things like permanently
attaching bird wings to a lizard, and inflating a pig's  intestine
so that it filled a room.
Leonardo's notebooks from this time depict several apocalyptic visions,
usually  associated with a deluge reminiscent of the biblical flood.
 They also contain  are also many illustrations, as above, which
combine Leonardo's artistic skills  with his interest in hydraulics.
It was probably at this time that Leonardo drew the above
self-portrait.  It  shows an old man, with the long beard and haggard look
we have come to associate  with Leonardo.  It should be noted that,
if this is indeed a self-portrait, as  most critics agree, it is remarkable
that it is drawn from an angle, not head  on: Leonardo probably
arranged a complex system of mirrors in order to draw  himself from
this angle.
While in Rome, Leonardo completed his last major painting, Saint
John the  Baptist.  Although it was his last, it is also
one of his least famous  paintings.  John's androgynous look has
upset prudish critics for centuries, and  no one can deny that the
figure is not anatomically correct.  Paradoxically,  Leonardo often
got anatomy completely wrong in his paintings, even as he was  making
perfect anatomical sketches in his notebooks; perhaps he was drawing
a  distinction between science and art.  Other critics complain
that Leonardo has  boringly recycled here the upward-pointing finger and
the smile of Mona  Lisa.