# 练习2.48-练习2.51

16 篇文章 0 订阅
15 篇文章 0 订阅

1.练习2.48

(define (make-segment start end)
(cons start end))

(define (start-segment seg)
(car seg))

(define (end-segment seg)
(cdr seg))

2.练习2.49

(require (planet "sicp.ss" ("soegaard" "sicp.plt" 2 1)))

(define one 1.0)

(define origin (make-vect 0 0))

(define lower-right (make-vect one 0))

(define upper-left (make-vect 0 one))

(define upper-right (make-vect one one))

(define (outline frame)
((segments->painter (list (make-segment origin lower-right)
(make-segment lower-right upper-right)
(make-segment upper-right upper-left)
(make-segment upper-left origin)))
frame))

(define seg1 (make-segment origin upper-right))

(define seg2 (make-segment upper-left lower-right))

(define (diamond frame)
((segments->painter (list (make-segment (make-vect 0 0.5) (make-vect 0.5 0))
(make-segment (make-vect 0.5 0) (make-vect 0.99 0.5))
(make-segment (make-vect 0.99 0.5) (make-vect 0.5 0.99))
(make-segment (make-vect 0.5 0.99) (make-vect 0 0.5))))
frame))
(define (wave frame)
((segments->painter (list
(make-segment (make-vect 0.4 1.0)      ; 头部左上
(make-vect 0.35 0.85))
(make-segment (make-vect 0.35 0.85)    ; 头部左下
(make-vect 0.4 0.64))
(make-segment (make-vect 0.4 0.65)     ; 左肩
(make-vect 0.25 0.65))
(make-segment (make-vect 0.25 0.65)    ; 左手臂上部
(make-vect 0.15 0.6))
(make-segment (make-vect 0.15 0.6)     ; 左手上部
(make-vect 0.0 0.85))

(make-segment (make-vect 0.0 0.65)     ; 左手下部
(make-vect 0.15 0.35))
(make-segment (make-vect 0.15 0.35)    ; 左手臂下部
(make-vect 0.25 0.6))

(make-segment (make-vect 0.25 0.6)     ; 左边身体
(make-vect 0.35 0.5))
(make-segment (make-vect 0.35 0.5)     ; 左腿外侧
(make-vect 0.25 0.0))
(make-segment (make-vect 0.6 1.0)      ; 头部右上
(make-vect 0.65 0.85))
(make-segment (make-vect 0.65 0.85)    ; 头部右下
(make-vect 0.6 0.65))
(make-segment (make-vect 0.6 0.65)     ; 右肩
(make-vect 0.75 0.65))
(make-segment (make-vect 0.75 0.65)    ; 右手上部
(make-vect 1.0 0.3))

(make-segment (make-vect 1.0 0.15)     ; 右手下部
(make-vect 0.6 0.5))
(make-segment (make-vect 0.6 0.5)      ; 右腿外侧
(make-vect 0.75 0.0))

(make-segment (make-vect 0.4 0.0)      ; 左腿内侧
(make-vect 0.5 0.3))
(make-segment (make-vect 0.6 0.0)      ; 右腿内侧
(make-vect 0.5 0.3)))
)
frame))

3.练习2.50

(define (flip-horiz-my painter)
((transform-painter (make-vect 1.0 0.0)
(make-vect 0.0 0.0)
(make-vect 1.0 1.0))
painter))

(define (contrarotate180 painter)
((transform-painter (make-vect 1.0 1.0)
(make-vect 0.0 1.0)
(make-vect 1.0 0.0))
painter))

(define (contrarotate270 painter)
((transform-painter (make-vect 0.0 1.0)
(make-vect 0.0 0.0)
(make-vect 1.0 1.0))
painter))

4.练习2.51

(define (below-my painter1 painter2)
(let ((split-point (make-vect 0.0 0.5)))
(let ((paint-up
((transform-painter (make-vect 0.0 0.0)
(make-vect 1.0 0.0)
split-point)
painter1))
(paint-down
((transform-painter split-point
(make-vect 1.0 0.5)
(make-vect 0.0 1.0))
painter2)))
(lambda (frame)
(paint-up frame)
(paint-down frame)))))

(paint (below-my einstein einstein))

(paint (rotate90 (beside (rotate270 einstein) (rotate270 einstein))))

5.练习2.52

(define (wave frame)
((segments->painter (list
(make-segment (make-vect 0.4 1.0)      ; 头部左上
(make-vect 0.35 0.85))
(make-segment (make-vect 0.35 0.85)    ; 头部左下
(make-vect 0.4 0.64))
(make-segment (make-vect 0.4 0.65)     ; 左肩
(make-vect 0.25 0.65))
(make-segment (make-vect 0.25 0.65)    ; 左手臂上部
(make-vect 0.15 0.6))
(make-segment (make-vect 0.15 0.6)     ; 左手上部
(make-vect 0.0 0.85))

(make-segment (make-vect 0.0 0.65)     ; 左手下部
(make-vect 0.15 0.35))
(make-segment (make-vect 0.15 0.35)    ; 左手臂下部
(make-vect 0.25 0.6))

(make-segment (make-vect 0.25 0.6)     ; 左边身体
(make-vect 0.35 0.5))
(make-segment (make-vect 0.35 0.5)     ; 左腿外侧
(make-vect 0.25 0.0))
(make-segment (make-vect 0.6 1.0)      ; 头部右上
(make-vect 0.65 0.85))
(make-segment (make-vect 0.65 0.85)    ; 头部右下
(make-vect 0.6 0.65))
(make-segment (make-vect 0.6 0.65)     ; 右肩
(make-vect 0.75 0.65))
(make-segment (make-vect 0.75 0.65)    ; 右手上部
(make-vect 1.0 0.3))

(make-segment (make-vect 1.0 0.15)     ; 右手下部
(make-vect 0.6 0.5))
(make-segment (make-vect 0.6 0.5)      ; 右腿外侧
(make-vect 0.75 0.0))

(make-segment (make-vect 0.4 0.0)      ; 左腿内侧
(make-vect 0.5 0.3))
(make-segment (make-vect 0.6 0.0)      ; 右腿内侧
(make-vect 0.5 0.3))
(make-segment (make-vect 0.5 0.75)      ; 笑脸左
(make-vect 0.45 0.8))
(make-segment (make-vect 0.5 0.75)      ; 笑脸右
(make-vect 0.55 0.8)))
)
frame))

(define (up-split painter n)
(if (= n 0)
painter
(let ((smaller (up-split painter (- n 1))))
(below painter (below smaller smaller)))))

(define (right-split painter n)
(if (= n 0)
painter
(let ((smaller (right-split painter (- n 1))))
(beside painter (below smaller smaller)))))

(define (beside-same-painter painter)
(beside painter painter))

(define (below-same-painter painter)
(below painter painter))

(define (corner-split painter n)
(if (= n 0)
painter
(let ((up (up-split painter (- n 1)))
(right (right-split painter (- n 1))))
(let ((top-left (beside-same-painter up))
(bottom-right (below-same-painter right))
(corner (corner-split painter (- n 1))))
(beside (below painter top-left)
(below bottom-right corner))))))

(define (square-list painter n)
(let ((quarter (corner-split (flip-horiz painter) n)))
(let ((half (beside (flip-horiz quarter) quarter)))
(below (flip-vert half) half))))

• 0
点赞
• 0
收藏
觉得还不错? 一键收藏
• 打赏
• 0
评论
04-28 517
08-15 531
01-08 656
01-06 625
01-13 617
02-07 609
01-20 602
01-07 585
01-20 578
01-20 564
01-17 558
01-23 556
01-15 549
01-10 523

### “相关推荐”对你有帮助么？

• 非常没帮助
• 没帮助
• 一般
• 有帮助
• 非常有帮助

_海阔天空

¥1 ¥2 ¥4 ¥6 ¥10 ¥20

1.余额是钱包充值的虚拟货币，按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载，可以购买VIP、付费专栏及课程。