正在加载图片...
6.001 Structure and Interpretation of Computer Programs. Copyright o 2004 by Massachusetts Institute of Technology Slide 30.1.26 To use a picture, we simply give it a rectangle(as a data Creating a picture abstraction) and the picture procedure will then display it on the screen inside that rectangle. Slide 30.1.27 So here is the code for doing that The picture abstraction Note that this is a higher order procedure it takes a list as input, (define tmake-picture seglis) and returns a procedure as output. That procedure when given a ligher order rectangle as input, will ask each of the lines segments in the data structure embedded within the procedure to draw itself, et((b(start-segment segment)) appropriately scaled within the rectangle. For-each is (e(end-segment segment) (xcor b) Just like map, except that it doesn't accumulate an answer as it walks down the list applying its internal lambda to each element segt》 The key thing to note is how we are using standard list operations to capture this procedural abstraction of a picture Slide 30.1.28 Drawing lines is just algebra Just to be careful. what should draw-line do?The idea is that this procedure is given a rectangle, which contains wing a line is just some algebra. If rectangle has an within it an origin vector, an x axis and a y axis.Draw-line point p with compenents and es mappe o th oint takes an x and y coordinate value of a point(defined in a canonical rectangle), and scales the new horizontal and vertical axes by those amounts, and then shifts this by the offset to the (1,1) origin, using the vector algebra shown. Doing this for two xac points automatically shifts and stretches a line to fit within the new rectangle 0,06.001 Structure and Interpretation of Computer Programs. Copyright © 2004 by Massachusetts Institute of Technology. Slide 30.1.26 To use a picture, we simply give it a rectangle (as a data abstraction) and the picture procedure will then display it on the screen inside that rectangle. Slide 30.1.27 So here is the code for doing that. Note that this is a higher order procedure: it takes a list as input, and returns a procedure as output. That procedure when given a rectangle as input, will ask each of the lines segments in the data structure embedded within the procedure to draw itself, appropriately scaled within the rectangle. For-each is just like map, except that it doesn't accumulate an answer as it walks down the list applying its internal lambda to each element. The key thing to note is how we are using standard list operations to capture this procedural abstraction of a picture. Slide 30.1.28 Just to be careful, what should draw-line do? The idea is that this procedure is given a rectangle, which contains within it an origin vector, an x axis and a y axis. Draw-line takes an x and y coordinate value of a point (defined in a canonical rectangle), and scales the new horizontal and vertical axes by those amounts, and then shifts this by the offset to the origin, using the vector algebra shown. Doing this for two points automatically shifts and stretches a line to fit within the new rectangle
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有