my attempt
http://www.phy.ntnu.edu.tw/ntnujava/index.php?topic=1026.msg3765#msg3765