A lot of trial and error with the programming, and a lot of math hahah! I'll probably be writing up a devlog on how it's done, but the source is all public on github (linked in the game page)
Very glad you liked it! Thank you very much for the comment c: