sicp每日一题[2.51]
1.sicp每日一题[1.42]2.sicp每日一题[1.43]3.sicp每日一题[1.44]4.sicp每日一题[1.45]5.sicp每日一题[1.46]6.sicp每日一题[2.1]7.sicp每日一题[2.2]8.sicp每日一题[2.3]9.sicp每日一题[2.4]10.sicp每日一题[2.5]11.sicp每日一题[2.6]12.sicp每日一题[2.7]13.sicp每日一题[2.8]14.sicp每日一题[2.9]15.sicp每日一题[2.11]16.sicp每日一题[2.10]17.sicp每日一题[2.12]18.sicp每日一题[2.13-2.16]19.sicp每日一题[2.17]20.sicp每日一题[2.18]21.sicp每日一题[2.19]22.sicp每日一题[2.20]23.sicp每日一题[2.21]24.sicp每日一题[2.22-2.23]25.sicp每日一题[2.24-2.27]26.sicp每日一题[2.28]27.sicp每日一题[2.29]28.sicp每日一题[2.30]29.sicp每日一题[2.31]30.sicp每日一题[2.32]31.sicp每日一题[2.33]32.sicp每日一题[2.34]33.sicp每日一题[2.35]34.sicp每日一题[2.36-2.37]35.sicp每日一题[2.38-2.39]36.sicp每日一题[2.40]37.sicp每日一题[2.41]38.sicp每日一题[2.42]39.sicp每日一题[2.43]40.sicp每日一题[2.44]41.sicp每日一题[2.45]42.sicp每日一题[2.46]43.sicp每日一题[2.47]44.sicp每日一题[2.48]45.sicp每日一题[2.49]46.sicp每日一题[2.50]
47.sicp每日一题[2.51]
48.sicp每日一题[2.52]49.sicp每日一题[2.53-2.55]50.sicp每日一题[2.56]51.sicp每日一题[2.57]52.sicp每日一题[2.58]53.sicp每日一题[2.59]54.sicp每日一题[2.60]55.sicp每日一题[2.61]56.sicp每日一题[2.62]57.sicp每日一题[2.63-2.64]58.sicp每日一题[2.65]59.sicp每日一题[2.66]60.sicp每日一题[2.67-2.68]61.sicp每日一题[2.69]62.sicp每日一题[2.70]63.sicp每日一题[2.71]64.sicp每日一题[2.72]65.sicp每日一题[2.73]66.sicp每日一题[2.74]67.sicp每日一题[2.75]68.sicp每日一题[2.76]69.sicp每日一题[2.77]70.sicp每日一题[2.78]71.sicp每日一题[2.79]72.sicp每日一题[2.80]73.sicp每日一题[2.81]74.sicp每日一题[2.82]75.sicp每日一题[2.83]76.sicp每日一题[2.84]77.sicp每日一题[2.85-2.86]Exercise2.51
Define the below operation for painters. below takes two painters as arguments. The resulting painter, given a frame, draws with the first painter in the bottom of the frame
and with the second painter in the top. Define below in two different ways—first by writing a procedure that is analogous to the beside procedure given above, and again
in terms of beside and suitable rotation operations (from Exercise 2.50).
这道题目难度不大,理解了 2.50 那张图后,再仿照 beside 的代码,只要把3个坐标的位置调整一下就可以了; 至于利用 beside 和旋转来实现 below,就更简单了,先把2幅图向右旋转90°,然后 beside 排到一起,
最后再把排到一起的图形向左旋转90°即可。
#lang racket
(require (planet "sicp.ss" ("soegaard" "sicp.plt" 2 1)))
(define sub-vect vector-sub)
; Transforming and combining painters
(define (transform-painter painter origin corner1 corner2)
(lambda (frame)
(let ((m (frame-coord-map frame)))
(let ((new-origin (m origin)))
(painter (make-frame
new-origin
(sub-vect (m corner1) new-origin)
(sub-vect (m corner2) new-origin)))))))
(define (beside painter1 painter2)
(let ((split-point (make-vect 0.5 0.0)))
(let ((paint-left
(transform-painter
painter1
(make-vect 0.0 0.0)
split-point
(make-vect 0.0 1.0)))
(paint-right
(transform-painter
painter2
split-point
(make-vect 1.0 0.0)
(make-vect 0.5 1.0))))
(lambda (frame)
(paint-left frame)
(paint-right frame)))))
; analogous to beside
(define (below painter1 painter2)
(let ((split-point (make-vect 0.0 0.5)))
(let ((paint-up
(transform-painter
painter2
split-point
(make-vect 1.0 0.5)
(make-vect 0.0 1.0)))
(paint-low
(transform-painter
painter1
(make-vect 0.0 0.0)
(make-vect 1.0 0.0)
split-point)))
(lambda (frame)
(paint-up frame)
(paint-low frame)))))
(paint (below einstein (beside einstein einstein)))
(define (rotate90 painter)
(transform-painter painter
(make-vect 1.0 0.0) ; new origin
(make-vect 1.0 1.0) ; new end of edge1
(make-vect 0.0 0.0))) ; new end of edge2
(define (rotate180 painter)
(transform-painter painter
(make-vect 0.0 1.0) ; new origin
(make-vect 1.0 1.0) ; new end of edge1
(make-vect 0.0 0.0))) ; new end of edge2
(define (rotate270 painter)
(transform-painter painter
(make-vect 0.0 1.0) ; new origin
(make-vect 0.0 0.0) ; new end of edge1
(make-vect 1.0 1.0))) ; new end of edge2
; in terms of beside and suittable rotation
(define (below- painter1 painter2)
(rotate90 (beside (rotate270 painter1) (rotate270 painter2))))
(paint (below- einstein (beside einstein einstein)))
结果如下所示:
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?