Tartans¶
Tartan is a traditional Scottish fabric pattern consisting of intersecting horizontal and vertical stripes in various colors. Tartans are a part of the Scottish highland dress.
The Scottish Register of Tartans lists thousands of tartan designs that were created for use by various clans, localities, organizations etc.
Making a tartan¶
Vertical and horizontal stripes of a tartan have the same pattern:
In order to combine these pictures into an image of a tartan we can use a checkerboard that alternates between showing vertical and horizontal stripes. In the image below vertical stripes were given slightly darker colors to show this pattern more clearly:
The resulting image will look as follows:
A more realistic image of a tartan can be obtained by modifying the way in which vertical and horizontal stripes are combined. Instead of using the checkerboard pattern, each column of pixels shows two pixels of vertical stripes, then two pixels of horizontal stripes and so on. In each subsequent column this pattern gets shifted down by one pixel:
This method was used to produce the following picture:
Recipe for a tartan¶
To specify the design of a tartan it suffices to give widths and colors of its vertical stripes. Since horizontal stripes have the same pattern as the vertical ones, there is no need to describe them separately. For example, the pattern of stripes of the Campbell tartan can be described as follows:
B14 K6 B6 K6 B6 K32 OG32 K6 OG32 K32 B32 K6 B6 K6 B32 K32 OG32 K6 OG32 K32 B6 K6 B6 K6 B28
The letter codes B, K, OG indicate different stripe colors, and the number following each letter code is the width of the stripe. In the production of tartan fabrics this number gives the number of threads in the stripe. In computer generated images of tartans we can take it to be the width of the stripe in pixels or some other units. The pattern will repeat to fill an image of an arbitrary size.
To complete the description of a tartan one needs to specify what color each letter code stands for. This can be done e.g. by giving RGB coordinates of each color:
B : [52, 80, 100], K : [16, 16, 16], OG : [92, 100, 40]
Project¶
The table below lists several tartan patterns. Take your UB person number and mod by 31 (PN%31) to produce a number between 0 and 30. You will use the corresponding tartan for the project. Find that tartan and write a function show_tartan(n) that produces an image of this tartan of dimensions n x n threads, with pattern repeating as many times as needed to fill the whole image.
For bonus points, write your function to take three inputs: the desired size n, a dictionary containing the color definitions, and a string defining the pattern. This will require additional code, primarily, a new function to deconstruct the pattern string into a more usable format.
Note. This is a programming project. Your project report does not need to include narrative, beyond comments explaining how your code works. The project will be graded according to the following rubrics:
Reproduction of the assigned tartan: 70%
Report organization and code documentation: 30%