Clock, illustrating the idea of recursion

There is rarely a topic as confusing to students as recursion. Did you know that if you google “recursion”, google will suggest that you click on a link for recursion, and you can click forever and still end up in the same place? Recursion is the art of solving a problem by breaking the problem into smaller problems, which are then broken down into even smaller problems in the same way,.. etc. Of course, at some point, the programmer needs to define the solution to a ‘tiny’ problem without breaking it down any further, and we call these solutions the ‘base case’.

In the below sketch, instead of marking the hours with numbers, we’ve marked them with little clocks that represent the time, and each of those have little clocks that represent the time on them! Click on the sketch to disable the recursive function and only run the draw() function:

Code for the recursive clock follows。 You can edit and run this code on the KTBYTE Coder

One Reply to “Clock, illustrating the idea of recursion”

Leave a Reply

Your email address will not be published. Required fields are marked *