From fdea32da361c620e7ff3966e60f1a8d6ad6e637e Mon Sep 17 00:00:00 2001 From: Neale Pickett Date: Fri, 28 May 2010 13:34:16 -0500 Subject: [PATCH] Add oregon tartan, mute colors a bit --- tartans/Jamfile | 2 +- tartans/loom.py | 76 +++++++++++++++++++++++++---------------------- tartans/or.tartan | 11 +++++++ tartans/tartan.m4 | 2 ++ 4 files changed, 55 insertions(+), 36 deletions(-) create mode 100644 tartans/or.tartan diff --git a/tartans/Jamfile b/tartans/Jamfile index 12f6731..28b7d9d 100644 --- a/tartans/Jamfile +++ b/tartans/Jamfile @@ -47,4 +47,4 @@ actions TartanToPng { } Webify index.mdwn ; -Tartan albuquerque armstrong az blackwatch buchanan co nm nmloe nv ok pjs pjs2 shrek tx ut wa ; +Tartan albuquerque armstrong az blackwatch buchanan co nm nmloe nv ok pjs pjs2 shrek tx ut wa or ; diff --git a/tartans/loom.py b/tartans/loom.py index a0fb001..2da011f 100755 --- a/tartans/loom.py +++ b/tartans/loom.py @@ -2,6 +2,7 @@ # coding: utf-8 import re +import random class Yarn: """A spool of yarn. @@ -10,15 +11,32 @@ class Yarn: saturation values ranging from 0.0 (no saturation) to 1.0 (full saturation). + Since we're pretending to be actual dyes here, we can fuzz it out a + bit by not doing full screen saturation and adding a little bit of + randomness to the color when queried. + """ + maxval = 190 + fuzz = 0 + def __init__(self, r, g, b): self.rgb = (r, g, b) - self.color = (int(r * 256), int(g * 256), int(b * 256)) + self.intrgb = [int(c * self.maxval) for c in self.rgb] + + intfuzz = int(self.fuzz * self.maxval) + self.limits = [(max(0, c - intfuzz), min(self.maxval, c + intfuzz)) + for c in self.intrgb] def __repr__(self): return '' % (self.rgb) + def get_color(self): + if self.fuzz: + color = [random.randrange(l, h) for (l, h) in self.limits] + return color + else: + return self.intrgb class Loom: @@ -64,7 +82,7 @@ class PNGLoom(Loom): row = [] for c in fr: for i in range(scale): - row.extend(c.color) + row.extend(c.get_color()) for i in range(scale): imgstr.fromlist(row) x = len(fr * scale) @@ -117,39 +135,25 @@ def ascii_test(): # # Colors according to http://www.tartanregister.gov.uk/guidance.aspx # -colors = [('A', '\x00\x44\x99'), # Azure (light blue) - ('B', '\x00\x00\x44'), # Blue - ('C', '\xdc\x14\x3c'), # Crimson - ('G', '\x00\x44\x00'), # Green - ('K', '\x00\x00\x00'), # Black - ('Mn', '\x80\x00\x00'), # Maroon - ('N', '\x44\x44\x44'), # Neutral (gray) - ('P', '\x99\x00\x99'), # Purple - ('R', '\x99\x00\x00'), # Red (scarlet) - ('T', '\x66\x66\x00'), # Tan (brown) - ('W', '\x99\x99\x99'), # White - ('Y', '\x99\x99\x00'), # Yellow - ] -if True: - colors = {'R': Yarn(0.50, 0.00, 0.00), # Red - 'G': Yarn(0.00, 0.30, 0.00), # Green - 'B': Yarn(0.00, 0.00, 0.50), # Blue - 'C': Yarn(0.00, 0.25, 0.25), # Cyan - 'Y': Yarn(0.80, 0.80, 0.00), # Yellow - 'P': Yarn(0.60, 0.00, 0.60), # Purple (?!) - 'W': Yarn(0.60, 0.60, 0.60), # White - 'K': Yarn(0.00, 0.00, 0.00), # Black - 'BK': Yarn(0.00, 0.00, 0.00), # Black - 'GR': Yarn(0.25, 0.25, 0.25), # Gray - 'DB': Yarn(0.00, 0.00, 0.30), # Dark Blue - 'LB': Yarn(0.00, 0.25, 0.60), # Light Blue - 'LR': Yarn(0.60, 0.00, 0.00), # Light Red - 'LG': Yarn(0.00, 0.60, 0.00), # Light Green - 'LV': Yarn(0.50, 0.25, 0.60), # Lavender - 'BR': Yarn(0.30, 0.25, 0.00), # Brown - 'LGR': Yarn(0.60, 0.60, 0.60), # Light Gray - 'LBR': Yarn(0.40, 0.40, 0.00), # Light Brown - } +colors = {'R': Yarn(0.50, 0.00, 0.00), # Red + 'G': Yarn(0.00, 0.40, 0.00), # Green + 'B': Yarn(0.00, 0.00, 0.50), # Blue + 'C': Yarn(0.00, 0.50, 0.50), # Cyan + 'Y': Yarn(0.80, 0.80, 0.00), # Yellow + 'P': Yarn(0.60, 0.00, 0.60), # Purple + 'W': Yarn(0.90, 0.90, 0.90), # White + 'K': Yarn(0.00, 0.00, 0.00), # Black + 'BK': Yarn(0.00, 0.00, 0.00), # Black + 'GR': Yarn(0.50, 0.50, 0.50), # Gray + 'DB': Yarn(0.00, 0.00, 0.30), # Dark Blue + 'LB': Yarn(0.00, 0.40, 0.90), # Light Blue + 'LR': Yarn(0.80, 0.00, 0.00), # Light Red + 'LG': Yarn(0.00, 0.60, 0.00), # Light Green + 'LV': Yarn(0.50, 0.25, 0.60), # Lavender + 'BR': Yarn(0.60, 0.40, 0.20), # Brown + 'LGR': Yarn(0.60, 0.60, 0.60), # Light Gray + 'LBR': Yarn(0.80, 0.70, 0.50), # Light Brown + } sett_re = re.compile('([A-Za-z]{1,3}|\([A-Fa-f0-9]{3}\))(\d{1,3})') @@ -177,6 +181,8 @@ def str_to_sett(s): o = sett[:] o.reverse() sett += o + if len(sett) % 4: + sett += sett return sett def tartan(sett): diff --git a/tartans/or.tartan b/tartans/or.tartan new file mode 100644 index 0000000..62290cf --- /dev/null +++ b/tartans/or.tartan @@ -0,0 +1,11 @@ +Name: Oregon +Sett: Y6 LV10 G4 LV4 G4 W2 G8 LBR24 R4 LB2 K2 + +I had to reverse-engineer this from the UK tartan registry. If you +create an account with them, and request a sett, they'll email up to 5 +per day to you. I don't understand why a state's official tartan should +be so difficult to obtain: it seems like it ought to belong to the +people of that state and be easily accessed by them. + +Well, here you go, people of Oregon. + diff --git a/tartans/tartan.m4 b/tartans/tartan.m4 index d904b57..a5ae7be 100644 --- a/tartans/tartan.m4 +++ b/tartans/tartan.m4 @@ -6,6 +6,8 @@ Title: TARTAN Tartan clear: both;"> +

This image

+ divert(1) I place this image in the public domain, in the hope that it will