The code seems to be working fine.
You can check out another example at  [url=http://www.phy.ntnu.edu.tw/ntnujava/index.php?topic=1073.0]EJS version of Fourier Synthesis (You can hear the sound,too![/url]