-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2.2.4-a-picture-language.rkt
166 lines (141 loc) · 4.2 KB
/
2.2.4-a-picture-language.rkt
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#lang sicp
(#%require sicp-pict)
; exercise 2.44
(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 up up))
(bottom-right (below right right))
(corner (corner-split painter (- n 1))))
(beside (below painter top-left)
(below bottom-right corner))))))
(define (square-limit-1 painter n)
(let ((quarter (corner-split painter n)))
(let ((half (beside (flip-horiz quarter)
quarter)))
(below (flip-vert half) half))))
(define (square-of-four tl tr bl br)
(lambda (painter)
(let ((top (beside (tl painter) (tr painter)))
(bottom (beside (bl painter) (br painter))))
(below bottom top))))
(define (flipped-pairs painter)
(let ((combine4
(square-of-four identity flip-vert
identity flip-vert)))
(combine4 painter)))
(define (square-limit painter n)
(let ((combine4 (square-of-four flip-horiz
identity
rotate180
flip-vert)))
(combine4 (corner-split painter n))))
; exercise 2.45
(define (split first second)
(lambda (painter n)
(if (= n 0)
painter
(let ((smaller ((split first second) painter (- n 1))))
(first painter (second smaller smaller))))))
(define right-split (split beside below))
(define up-split (split below beside))
; ==========================
;(define (frame-coord-map frame)
; (lambda (v)
; (add-vect
; (origin-frame frame)
; (add-vect
; (scale-vect (xcor-vect v)
; (edge1-frame frame))
; (scale-vect (ycor-vect v)
; (edge2-frame frame))))))
; exercise 2.46
;(define (make-vect x y) (cons x y))
;(define xcor-vect car)
;(define ycor-vect cdr)
;
;(define (add-vect u v)
; (make-vect (+ (xcor-vect u) (xcor-vect v))
; (+ (ycor-vect u) (ycor-vect v))))
;
;(define (scale-vect v s)
; (make-vect (* s (xcor-vect v))
; (* s (ycor-vect v))))
;
;(define (sub-vect u v)
; (add-vect u (scale-vect v -1)))
; exercise 2.47
;(define (make-frame-list origin edge1 edge2)
; (list origin edge1 edge2))
;(define origin-frame-list car)
;(define edge1-frame-list cadr)
;(define edge2-frame-list caddr)
;
;(define (make-frame-cons origin edge1 edge2)
; (cons origin (cons edge1 edge2)))
;(define origin-frame-cons car)
;(define edge1-frame-cons cadr)
;(define edge2-frame-cons cddr)
; exercise 2.48
;(define make-segment cons)
;(define start-segment car)
;(define end-segment cdr)
; exercise 2.49
(define dl (make-vect 0 0))
(define tl (make-vect 0 1))
(define tr (make-vect 1 1))
(define dr (make-vect 1 0))
(define outline
(segments->painter
(list (make-segment dl tl)
(make-segment tl tr)
(make-segment tr dr)
(make-segment dr dl))))
(define cross
(segments->painter
(list (make-segment dl tr)
(make-segment tl dr))))
(define top (make-vect 0.5 1))
(define down (make-vect 0.5 0))
(define left (make-vect 0 0.5))
(define right (make-vect 1 0.5))
(define diamond
(segments->painter
(list (make-segment left top)
(make-segment top right)
(make-segment right down)
(make-segment down left))))
; exercise 2.50
(define (flip-horizontal painter)
(transform-painter
painter
(make-vect 1 0)
(make-vect 0 0)
(make-vect 1 1)))
(define (rotate-180 painter)
(rotate90 (rotate90 painter)))
(define (rotate-270 painter)
(rotate90 (rotate90 (rotate90 painter))))
; exercise 2.51
(define (below1 a b)
(let ((split-point (make-vect 0 0.5)))
(let ((top (transform-painter a
split-point
(make-vect 1 0.5)
(make-vect 0 1)))
(down (transform-painter b
(make-vect 0 0)
(make-vect 1 0)
split-point)))
(lambda (frame)
(top frame)
(down frame)))))
(define (below2 a b)
(rotate90
(beside
(rotate270 a)
(rotate270 b))))
; exercise 2.52
; nah