练习2.48-练习2.51

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
    评论

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

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

_海阔天空

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值