Refactored triangle.js to be more object-oriented