Replace all references to 384 by width(), and all to 288 be height(), and you're pretty much there. (You may need to qualify it if you have no implicit last.) Then replace the 100 and 300 in animate by startframe and endframe, make them parameters to a function, and you're done.
|