-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrainbows.rkt
81 lines (61 loc) · 1.99 KB
/
rainbows.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
#lang slideshow
;; this file generates a png image with
;; a specified height, width, and pixel size.
;; change the colors to make a different colored image
(require racket/draw)
(define clist (list "red" "orange" "yellow" "green" "blue" "purple"))
;(define clist (send the-color-database get-names))
; the more colors you use, the smaller width and height should be
(define width 20)
(define height 20)
(define pixel-size 3)
(define clen (length clist))
(define (square n)
(filled-rectangle n n))
;; colorizes a square p with lst (has already been split into chunks of 6)
(define (rainbow p lst)
(map (lambda (color)
(colorize p color))
lst))
;; splits a list into chunks of size n
(define (split-n n xs)
(if (null? xs)
'()
(let ((first-chunk (take xs n))
(rest (drop xs n)))
(cons first-chunk (split-n n rest)))))
;; calls rainbow for each square with color l in lst
(define (beauty lst)
(define (iter count)
(cond [(<= count 0)
(apply hc-append
(map (lambda (l)
(apply vc-append (rainbow (square pixel-size) l)))
lst))]
[else
(vc-append
(apply hc-append
(map (lambda (l)
(apply vc-append (rainbow (square pixel-size) l)))
lst))
(iter (sub1 count)))]))
(iter (sub1 height)))
;; recusively adds a list to lst that takes the old list and puts the last object in front
(define (my-length)
(define (iter lst cvc)
(cond
;;true
[(> cvc (+ (* clen (sub1 width)) (sub1 clen)))
(beauty (split-n clen lst))]
;;recurses
[else
(iter (flatten (list (rest (take lst clen))
(first lst)
lst))
(add1 cvc))]))
;starts the recursive call
(iter (reverse clist) 1))
(define image (my-length))
image
(send (pict->bitmap image)
save-file "/tmp/rainbows.png" 'png)