Some New Code

After playing around with Project Euler for a while, I determined I wanted to challenge my coding skills even more, but stay firmly planted in the mathematical realm in which I’m familiar. So, I’ve begun writing some code that can be used for certain mathematical objects. In particular, I’ve written a fraction class, a 2D vector class, and a complex number class. You can find the code on GitHub.

As intended, the biggest challenge was taking everything I knew about how these do and should work, and transfer it into consistent code. Once I had the basics down, it was then a matter of letting these different types work with each other. It’s very simple to create vectors where the components are integers or floats, because those numerical types are built into Python. It became much more difficult to figure out how to let the components also be the fractions I wrote myself.

So, it’s been a fun challenge. This weekend I began looking into how to have some rudimentary graphics. I quickly determined trying to use Turtle would be cute, but dumb. Similarly, trying to learn an entire other graphics program that fits in with Python would be a fool’s errand as well. So, I went the simpler route, and adapted a very simple script that allows for the use of Asymptote vector graphics to be used inside of Python.

The script, allegedly written by some student and tossed onto the end of the official documentation for Asymptote, is quite basic. It makes a class out of an instance of Asymptote, and draws things into a PostScript file as you go. I had to tweak it because it didn’t handle input correctly at all, but it was a good challenge that I figured out.

There’s more to come, because I’m really enjoying this project and building up a lot of code that I actually care about. I’ve tried getting into other projects (web-development using Python, even some game stuff) and it’s all just so boring to me. Working through mathematics has been great, and there’s a lot of room for creativity now. I’m looking forward to it.

Leave a Reply