So for this week, I had some problems with the tutorial. Again, let me reiterate, I'm no pro at computer science, but I'm trying!
Specifically, I had problems with question 8.23 in our 'textbook' Picturing Programs. The question was to
make an animation of a picture on a white background (200x200) that would always have the y coordinate of 50 with a changing x variable.
So, I had a little bit of an idea of how to get started.
First I would need to define a function that puts an image on top of another image at a specific coordinate. And given the hint from the tutorial handout, this function would be 'place-image'.
My first attempt on DrRacket was this:
(define picture x-coordinate (place-image pic:hacker
x-coordinate 50
(rectangle 200 200 "solid" "white")))
(big-bang 10
(check-with number?)
(on-draw picture x-coordinate)
...And well it failed. The error message was: define: expected only one expression after the variable name picture, but found 1 extra part
You know, I don't know if it's just me but sometimes I wish the computer can talk more explicitly...
Anyways, I think the problem is that I need to let DrRacket know that I want the x-coordinate to represent, well, the x-coordinate. I went about many different ways and failed. So on Wednesday I went to ask my TA for help.
I didn't bring my attempted solution to the tutorial...and when my TA helped me, the animation worked... I didn't understand why I couldn't get it with my solution when it was essentially the same idea... until I got home and compared the TA's solution to mine and I realized I was missing a bracket. Really, a bracket?
So here's the TA's solution (with just the added brackets...)
(define (picture x-coordinate) (place-image pic:hacker
x-coordinate 50
(rectangle 200 200 "solid" "white")))
(big-bang 10
(check-with number?)
(on-draw picture)
(on-tick add1 1))
Well of course, the lesson isn't just that I need to be more careful with brackets but that this bigbang function is quite versatile and that defining a function before usiong bigbang can add much more dimension to the animation.
No comments:
Post a Comment