+def box(size, back):
+ canvas = {}
+
+ # The back side of the cardboard box in the installer icon.
+
+ boxwidth = round(15 * size)
+ boxheight = round(12 * size)
+ boxdepth = round(4 * size)
+ boxfrontflapheight = round(5 * size)
+ boxrightflapheight = round(3 * size)
+
+ # Three shades of basically acceptable brown, all achieved by
+ # halftoning between two of the Windows-16 colours. I'm quite
+ # pleased that was feasible at all!
+ dark = halftone(cr, cK)
+ med = halftone(cr, cy)
+ light = halftone(cr, cY)
+ # We define our halftoning parity in such a way that the black
+ # pixels along the RHS of the visible part of the box back
+ # match up with the one-pixel black outline around the
+ # right-hand side of the box. In other words, we want the pixel
+ # at (-1, boxwidth-1) to be black, and hence the one at (0,
+ # boxwidth) too.
+ parityadjust = int(boxwidth) % 2
+
+ # The entire back of the box.
+ if back:
+ for x in range(int(boxwidth + boxdepth)):
+ ytop = max(-x-1, -boxdepth-1)
+ ybot = min(boxheight, boxheight+boxwidth-1-x)
+ for y in range(int(ytop), int(ybot)):
+ pixel(x, y, dark[(x+y+parityadjust) % 2], canvas)
+
+ # Even when drawing the back of the box, we still draw the
+ # whole shape, because that means we get the right overall size
+ # (the flaps make the box front larger than the box back) and
+ # it'll all be overwritten anyway.
+
+ # The front face of the box.
+ for x in range(int(boxwidth)):
+ for y in range(int(boxheight)):
+ pixel(x, y, med[(x+y+parityadjust) % 2], canvas)
+ # The right face of the box.
+ for x in range(int(boxwidth), int(boxwidth+boxdepth)):
+ ybot = boxheight + boxwidth-x
+ ytop = ybot - boxheight
+ for y in range(int(ytop), int(ybot)):
+ pixel(x, y, dark[(x+y+parityadjust) % 2], canvas)
+ # The front flap of the box.
+ for y in range(int(boxfrontflapheight)):
+ xadj = int(round(-0.5*y))
+ for x in range(int(xadj), int(xadj+boxwidth)):
+ pixel(x, y, light[(x+y+parityadjust) % 2], canvas)
+ # The right flap of the box.
+ for x in range(int(boxwidth), int(boxwidth + boxdepth + boxrightflapheight + 1)):
+ ytop = max(boxwidth - 1 - x, x - boxwidth - 2*boxdepth - 1)
+ ybot = min(x - boxwidth - 1, boxwidth + 2*boxrightflapheight - 1 - x)
+ for y in range(int(ytop), int(ybot+1)):
+ pixel(x, y, med[(x+y+parityadjust) % 2], canvas)
+
+ # And draw a border.
+ border(canvas, size, [(0, int(boxheight)-1, BL)])
+
+ return canvas
+
+def boxback(size):
+ return box(size, 1)
+def boxfront(size):
+ return box(size, 0)
+