Please check out the following applets:


[url=http://www.phy.ntnu.edu.tw/ntnujava/index.php?topic=313.msg1009#msg1009]RC circuit (DC: charge/discharge) [/url]
[url=http://www.phy.ntnu.edu.tw/ntnujava/index.php?topic=368.msg1151#msg1151]RLC AC circuit[/url]
or

[url=http://www.phy.ntnu.edu.tw/ntnujava/index.php?topic=545.msg1793#msg1793]Rectifier circuit[/url]

For color to change according to their position, you need to define an array  for color object, and set their value from coordinate.