The author makes this comment at the end of the post:
I wish I knew how to make a website where you could enter a number and have it show you the factorization diagram… maybe eventually.After I read that, I felt like I had to do it myself. I decided to ignore the Haskell code and just take a stab at implementing something using JavaScript and the <canvas> element.
I knew that I whatever I came up with would be unlikely to match the elegance of the Haskell version, but after whipping up a very primitive Diagram interface, I had some code that made it pretty simple to implement the kind of factor diagrams I wanted.
Instead of starting with the greatest factor and moving down, my version starts by filling the entire canvas space with a circle, which can be thought of as 1. It then loops through each factor, F, and each time it scales the current diagram down proportionately to F, and places copies of the scaled version at each vertex of an F-sided polygon filling the entire canvas space. If you're a programmer, it's probably easier to just read the code than to try and follow that explanation.
All in all, it actually works pretty well, although I would definitely need to expand my Diagram interface before it could be considered useful for doing much more than render these diagrams. For fun, here is an example of how to render the factor diagrams for the numbers 1-25 on a canvas element:
This is the output:
And since I claimed the whole point of this project was to create the interactive Web version, here it is:
- Factor Diagrams Online (tested in Chrome and Firefox, not in Internet Explorer)
- Complete source code