Tower of Hanoi: graphical representation of optimal solution
Very nice code!

Herea are a few small things:


Since your function hanoi is a generator, you don't need to save it to a variable, you can use it directly in the for loop:




for position in hanoi(pegs, 0, 2, number_of_pegs):



According to PEP8:



  Compound statements (multiple statements on the same line) are
  generally discouraged.



reversed(range(1, number_of_pegs+1)) is the same as range(number_of_pegs, 0, -1)
You calculate 255-pegwidth three times in a row, just use (255 - pegwidth,)*3 and use that.