Brief :
I was studying about Tower of Hanoi ( https://en.wikipedia.org/wiki/Tower_of_Hanoi ) and I thought to myself how about I make a visualisation of this wonderful puzzle all by myself ? I had no idea about how to do that , I progressed with that thought . So , finally with HTML canvas and javascript , I figured out a way to manipulate animation without using any external dependency .
Things I learned :
- Html Canvas and Javascript for front end.
- Python for backend.
- Exchanging information between back-end and front-end in web app
- Flask
How I built :
I made a tower() class in python which takes input n during initialisation in it's constructor - which is the number of discs , and there is a method call inside it named hanoi() which will organise the discs from initial pole to final pole using 3rd pole as an auxiliary pole .
There is a count property of that class which get's incremented whenever there is a successful conversion of a disc .
I used flask as the web framework and used its inbuilt jinja templating engine to render a html page and used wtforms to get the parameter 'n' i.e. number of discs as user input .
Finally n is passed to flask and python processes and returns the count property of tower() class and the array of the sequential transformations .
In front end I used vanilla javascript to get the array and in a loop iterating through all pairs of the array , I updated the html canvas . With a new pair , the previous drawn element gets cleared and new element is drawn .In this way I was able to get the illusion of animation . Also I used SetInterval function and recursively called it with a delay of a "speed" (time in millisecond ) parameter which is decided by the user through a range bar in home page .
Finally user gives input , adjusts speed (speed is set to default as 500ms) and see the animation in action .
I minified the js and used it inside html to decrease load times .
Challenges I faced :
- The making of the animation without requestAnimationFrame() was a huge challenge . I made everything from scratch and that was very difficult .
- I didn't know anything about html forms and HTTP requests . I learnt flask , forms and templating . It was a challenge , but once the basics were clear it was easy .
Thanks you so much for giving me this platform :)



Log in or sign up for Devpost to join the conversation.