SICP Exercise 2.50 flip-horiz
Exercise 2.50. Define the transformation flip-horiz, which flips painters horizontally, and transformations that rotate painters counterclockwise by 180 degrees and 270 degrees.
SOLUTION
The code and tests are here.
Note: I have modified 'transform-painter' and 'wave-painter' from the previous exercise to make these work intuitively.
Note: The implementation of the procedure segments->painter in the textbook is different from the similarly named procedure in the sicp plt package.
The plt package procedure takes a list of segments and draws them. Moreover, this procedure draws segments only inside the unit square where 0 <= x,y <= 1. Any points ouside the unit square are simply ignored (at least, there is no visual output)
The textbook implementation also takes a list of segments but instead of drawing them directly, evaluates to a procedure that takes a frame as its input. This procedure when supplied with a frame, maps all the segments from the originally supplied list to this frame and then draws them. Now, the 'draw-line' procedure in the textbook implementation has no equivalent in the plt package. So in order to use the plt package implementation of segments->painter, I have modified the textbook implementation of segments->painter.
Finally, to prevent a name-clash, I have renamed the textbook procedure by appending a '-local' suffix.
SOLUTION
The code and tests are here.
Note: I have modified 'transform-painter' and 'wave-painter' from the previous exercise to make these work intuitively.
Note: The implementation of the procedure segments->painter in the textbook is different from the similarly named procedure in the sicp plt package.
The plt package procedure takes a list of segments and draws them. Moreover, this procedure draws segments only inside the unit square where 0 <= x,y <= 1. Any points ouside the unit square are simply ignored (at least, there is no visual output)
The textbook implementation also takes a list of segments but instead of drawing them directly, evaluates to a procedure that takes a frame as its input. This procedure when supplied with a frame, maps all the segments from the originally supplied list to this frame and then draws them. Now, the 'draw-line' procedure in the textbook implementation has no equivalent in the plt package. So in order to use the plt package implementation of segments->painter, I have modified the textbook implementation of segments->painter.
Finally, to prevent a name-clash, I have renamed the textbook procedure by appending a '-local' suffix.
Comments
Post a Comment