Similar to assignment 1, when first opening "fx.rkt" and "fractal.rkt" I shamefully blanked out again. Even though I already had an idea from the in-class demonstrations of what the codes do, I still had trouble understanding the codes upon first glance. However, drawing upon experiences from assignment 1, I started reading the function contracts and check-expects. Man, weren't they ever so helpful. The contract gave an overall idea of what the function takes in and what the function churns out, while the check-expects essentially served as examples of the aforementioned inputs and outputs, making the understanding of functions so much easier. In addition, not only did the check-expects promote the understanding of the function, they also served as step-by-step checks as I worked my way through the code, making sure that everything I wrote produced the desired output. Working on the code bit by bit, making sure one part works before proceeding to the next, certainly had its charms. It made bug-hunting so much easier as you know the previous parts you have done definitely work, and that you only need to focus your attention on the newly added stuff. Following this strategy I was able to complete both codes in a matter of few hours, and it was such a huge improvement compared to the days I had to spend on assignment 1 to hunt for bugs.
One aspect of "fx.rkt" and "fractal.rkt" that I really liked was the added capability to respond to user input. This made the program so much more interesting when compared to the completely autonomous simulation we did previously. Pressing a key and seeing the program changes accordingly provided instant gratification and kept me occupied for hours after completing the assignment. I was especially fascinated by the use of "token", which is essentially a structure containing various parameters that take on different values in response to user key strokes. This token would then be fed into another function that specializes in producing certain effects in response to the parameters provided, and these effects were finally drawn onto the screen under the "big-bang" simulation. In some sense, the token was functioning as input for each function, which in turn served like one of those old computers before multitasking were implemented. This is something I'll be sure to use later on if I ever find myself in need of writing programs.
The most difficult part about the assignment, however, was the writing of a recursive function that produced patterns of different depth and size depending on the parameters provided. I had to start from the smallest unit and work my way up, basically figuring out how to draw the pattern when given the smallest input possible first, then figuring out how to draw the second largest pattern from the smallest by calling the function itself, and finally testing out to see if the function works for larger inputs. I had to practice writing simpler recursive functions in a separate program first, before moving onto more difficult ones, and finally integrating the desired function into the desired program. Things worked out very well using this approach in the end.
Demonstrations of the end products:
Fractal: A program that produces patterns of different size and depth depending on user input.
Fx: A program that changes the chameleon into user's desired color.


No comments:
Post a Comment