Play around with the code, I've left some comments as to how it works. Feel free to backpack it and use it in your own projects if you want.