convert to C# from http://www.arongranberg.com/unity/unitypaint/