# Meyas

Hi, I'm Fabi. I write knitting patterns among other things

## Solving a quilt puzzle: Part 2

Color it

This blog post is a continuation of post Solving a quilt puzzle: Part 1.

According to the plan I delineated in Part 1, I should now attribute a color to each number I used on the previous section.

I was planning on using a Robert Kaufman roll-up (more on it in Part 1), and on Robert Kaufman’s website you can see a picture of the fabric for each color on the roll. I screenshot it and got the RGB color values for each fabric with Gimp. Now I needed to tell Racket what my colors were.

I compiled a list of colors like so:

``````(define c1 (make-color 246 246 248))
(define c2 (make-color 245 243 231))
(define c3 (make-color 246 246 236))
``````

And did the same for all 38 colors.

This was my range of colors:

I could finally start thinking in triangles. In Racket painting and drawing a triangle is as simple as:

``````;; draw a equilateral triangle, length 40, and paint it with color red
(triangle 40 "solid" "red")
``````

All that was left to do was to draw the triangles, and have each triangle get its color from the same index on the matrix we got on Part 1. At the same time, I would rotate every other triangle 180°, and rotate the triangles on the next row in opposite order.

``````;; list of colors defined by me
(define rangeofcolors (vector c1 c2 c3 c4 c5 c6 c7 c8 c9 c10 c11 c12 c13 c14 c15 c16
c17 c18 c19 c20 c21 c22 c23 c24 c25 c26 c27 c28 c29 c30 c31 c32 c33 c34 c35 c36 c37
c38))

;; draw equilateral triangle, length 40, color x
(define (givecolor x)
(triangle 40 "solid" x))
;; draw and rotate 180° equilateral triangle, length 40, color z
(define (givecolor180 z)
(rotate 180 (triangle 40 "solid" z)))

;; get a matrix of 26 rows from Part 1
(define quilt (paint_n_rows 26))

;; paint triangles, but rotate them on [odd rows and even index of quilt]
;; and on [even rows and odd index of quilt]
(define (colorit anyquilt j i)
(if (odd? j)
(if (odd? i)
(givecolor (vector-ref rangeofcolors (vector-ref (list-ref anyquilt j) i)))
;;else
(givecolor180 (vector-ref rangeofcolors (vector-ref (list-ref anyquilt j) i))))
;;else
(if (odd? i)
(givecolor180 (vector-ref rangeofcolors (vector-ref (list-ref anyquilt j) i)))
;;else
(givecolor (vector-ref rangeofcolors (vector-ref (list-ref anyquilt j) i))))))

;; save image (copied straight from stackoverflow ;))
(define (save-pict the-pict name kind)
(define bm (pict->bitmap the-pict))
(send bm save-file name kind))

;; bringing it all together
(define (print-all-pretty)
;;
(let ([result (for/fold ([rows (blank)]) ([j (length quilt)])
;; draw a new picture with each row of triangles
(vc-append
(for/fold ([row2 (blank)]) ([i (vector-length (list-ref quilt j))])
;; draw a new picture of row of each triangle in the specified color
;; and remove white space between triangles
(hc-append -20 (colorit quilt j i) row2))
rows
))])
(begin
(print result)
;; crop image to remove half a triangle on the side edge and save it
(save-pict (crop 20 0 880 1040 (pict->bitmap result)) "triangles.png" 'png)
)))
``````

And this is the final result:

I’m in love with it. As soon as I saw the result I ordered the fabric.

I feel like I should say something about Racket, but since I can’t compare it with anything else due to my lack of experience, my review is pretty much meaningless. Here it goes: I think it wasn’t too hard to understand the syntax, although at times it felt like I was lost in a sea of parentheses. The documentation is extensive and if I ever need to do something similar, I won’t hesitate to use Racket again. (By the way, my husband is in love with Racket.)

As for the quilt, in the near future I will have to mess around with the maximum number of triangles and the number of colors, because after receiving the fabric in the mail I realized I had made a couple of mistakes. First, each strip only yields 27 triangles instead of 31 (due to the selvedges); second, the roll has 4 extra colors in addition to the 37 displayed on the manufacturer’s website. But it should be fine.

I plan on continuing to write updates, but this time on actually sewing the quilt, which is more in line with the content of this blog.

Right now I’m cutting the triangles and beginning to get a sense of just how long this project will take.

This was fun and I hope it helps someone in the future.