Recreating a Carpet

Today I will talk a bit about this:


This is a recreation of a carpet that was hung across an exhibition hall at a local museum. My parents, with whom I was seeing the exhibition, marveled at the impressive variety of symbols, while I quickly tried to figure out how it might have been generated. Probably not by hand, I prompted.

This was the original:



All the symbols are 11x11 tiles and show 8-way symmetry (horizontal mirroring, vertical mirroring and 90° rotation - 2*2*2 = 8). This means, to generate a pattern like this, we need to calculate a triangular slice of one symbol, then draw each of those tiles eight times. For each tile, there are five possible colours - red, yellow, green, blue and empty/black. Well, why don't we just pick one of the options randomly?



The strange thing is that just randomly picking colours is almost sufficient. However, there are two changes that have to be made.

First, just generating empty spots with equal frequency throughout the shape will lead to strange, quite often square symbols. Instead, the symbols should tend towards a circular or diamond shape. This is accomplished by raising the frequency of empty spots the further you get from the centre.

The other is something I will call coherence. Coherent shapes have just a single colour spread throughout the whole symbol, while incoherent shapes choose colour completely randomly. A middle ground between the two tends to generate lumps of pixels together. Let me show this off:


For each new column of symbols, coherence is decreased by 5%. The sorts of patterns generated in the middle might be very pleasant, but alas, that is not actually what the original artwork used. Instead, a point around 25% coherence or 75% incoherence seems to mostly fit. However, I think that the original algorithm had a different sort of coherence than the one I implemented, which simply had a X% chance of inheriting the colour of the last pixel generated.

Finally, I want to show off the detail work I added to the drawing routine to make it more carpetty instead of pixelly:


Sure, I did not quite hit the colour warmth of the original or the exact texture, but I personally think it looks quite nice and rustic. Each "pixel" consists of several vertical lines with slight colour variation, and then a diagonal –=– shape across the pixel in a lighter colour. Finally, a dark, transparent outer box.

And that's about all I could squeeze out of that one carpet I saw at a museum.

Code and demonstration can be found here as usual.

Comments

  1. This reminds me of https://github.com/zfedoran/pixel-sprite-generator, which has a somewhat similar setup.

    ReplyDelete
  2. That's rather lovely. You should look at the costs of getting this made into a tapestry - there's places that will do it.

    ReplyDelete

Post a Comment