正在加载图片...
6.001 Structure and Interpretation of Computer Programs. Copyright o 2004 by Massachusetts Institute of Technology Slide 30.1.29 So, just to complete this idea, here is a better definition of A better George Remember we have george-lines from before (detine g(makepicture george-lines) 8m00 Operations on pictures Slide 30.1.30 So what is the big deal? Well. george is abstraction(george-lines: a set of segments)and a rocedure(g: a process for drawing those lines within a rectangle). Note that g contains the information about the segments within it as part of the procedural abstraction This makes it quite easy to use George as a building block other pictures, and that is what we want to turn to next H Again, remember what a picture is: it's a procedure that takes a 6001 SICP mo rectangle as input, and scales its line segments to draw within the rectangle(or frame) So we can easily generalize this idea to arbitrary frames, not just rectangular ones. Remember that a frame is just a set of three vectors, an origin and two axes, so by picking vectors for axes that are not orthogonal, we get skewing for free To rotate a picture, we can just shift the axes, in particular, make the old horizontal axis vertical, and the old vertical axis the negative horizontal axis. If we do this, then we can see that drawing the picture within this new coordinate frame will accomplish the task of rotating the original picture Slide 30.1.31 Operations on picture and we can easily build code to do this. Note what this does, in(define (rotateso pict) a very cool way. Rotate 90 returns a picture, that is a procedure(lambda rect of one argument, a rectangle. That new picture asks the old +vect(origin rect picture to draw itself, but in a new frame. And that frame ply comes about by creating a new origin, a new horizontal tvert rect ale-vect(horiz rect axis and a new vertical axis, just as we sketched Also notice how nicely the data abstractions preserve the cleanliness of this code. It is very easy to see what is being done 6m13P6.001 Structure and Interpretation of Computer Programs. Copyright © 2004 by Massachusetts Institute of Technology. Slide 30.1.29 So, just to complete this idea, here is a better definition of George. Slide 30.1.30 So what is the big deal? Well, George is now both a data abstraction (george-lines: a set of segments) and a procedure (g: a process for drawing those lines within a rectangle). Note that g contains the information about the segments within it as part of the procedural abstraction This makes it quite easy to use George as a building block in other pictures, and that is what we want to turn to next. Again, remember what a picture is: it's a procedure that takes a rectangle as input, and scales its line segments to draw within the rectangle (or frame). So we can easily generalize this idea to arbitrary frames, not just rectangular ones. Remember that a frame is just a set of three vectors, an origin and two axes, so by picking vectors for axes that are not orthogonal, we get skewing for free. To rotate a picture, we can just shift the axes, in particular, make the old horizontal axis vertical, and the old vertical axis the negative horizontal axis. If we do this, then we can see that drawing the picture within this new coordinate frame will accomplish the task of rotating the original picture. Slide 30.1.31 And we can easily build code to do this. Note what this does, in a very cool way. Rotate90 returns a picture, that is a procedure of one argument, a rectangle. That new picture asks the old picture to draw itself, but in a new frame. And that frame simply comes about by creating a new origin, a new horizontal axis and a new vertical axis, just as we sketched. Also notice how nicely the data abstractions preserve the cleanliness of this code. It is very easy to see what is being done here
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有