-
Notifications
You must be signed in to change notification settings - Fork 0
/
2-51.scm
58 lines (48 loc) · 1.69 KB
/
2-51.scm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#lang sicp
(#%require sicp-pict)
(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)))))
(define (below painter1 painter2)
(let ((split-point (make-vect 0 0.5)))
(let ((paint-bottom
(transform-painter painter1
(make-vect 0.0 0.0)
(make-vect 1 0)
split-point))
(paint-top
(transform-painter painter2
split-point
(make-vect 1.0 0.5)
(make-vect 0 1))))
(lambda (frame)
(paint-top frame)
(paint-bottom frame)))))
(paint (below einstein einstein))
(define (compose f1 f2)
(lambda (x)
(f1 (f2 x))))
(define (rotate90 painter)
(transform-painter painter
(make-vect 1.0 0.0)
(make-vect 1.0 1.0)
(make-vect 0.0 0.0)))
(define rotate270 (compose rotate90
(compose rotate90
rotate90)))
(define (below-2 painter1 painter2)
(rotate270 (beside (rotate90 painter1)
(rotate90 painter2))))
(paint (below-2 einstein einstein))