def makeColors(self): colors = { # use original RoboFab colors for Font and Glyph objects 'font': Color.from_hsl(80, 0.50, 0.49), 'glyph': Color.from_hsl(38, 0.91, 0.69), } # color set 1: Font sub-objects for i, obj in enumerate(self.colorSets[0][1:]): color = colors['font'].with_hue(colors['font'].hsl[0] + (i + 1) * 25) colors[obj] = color # color set 2: Glyph sub-objects for i, obj in enumerate(self.colorSets[1][1:]): color = colors['glyph'].with_hue(colors['glyph'].hsl[0] - (i + 1) * 15) colors[obj] = color # color set 3: Contour sub-objects for i, obj in enumerate(self.colorSets[2][1:]): color = colors['contour'].with_hue(colors['contour'].hsl[0] - (i + 1) * 20) colors[obj] = color # color set 4: Layer colors['layer'] = colors['font'].blend(colors['glyph'], percent=0.5) self.colors = colors
class FontPartsColorScheme: colorSets = [ ['font', 'font lib', 'info', 'groups', 'kerning', 'features'], [ 'glyph', 'glyph lib', 'anchor', 'component', 'image', 'guideline', 'contour' ], ['contour', 'point', 'bPoint', 'segment'], ['font', 'layer', 'glyph'], ] baseColors = { # use the original RoboFab colors for Font and Glyph objects # calculate colors for all other objects from those two 'font': Color.from_hsl(80, 0.50, 0.49), 'glyph': Color.from_hsl(38, 0.91, 0.69), } def __init__(self): self.makeColors() def makeColors(self): ''' Calculate colors for all objects. Colors are stored in a dict as `grapefruit.Color` objects. ''' colors = self.baseColors.copy() # color set 1: Font sub-objects for i, obj in enumerate(self.colorSets[0][1:]): color = colors['font'].with_hue(colors['font'].hsl[0] + (i + 1) * 23) colors[obj] = color # color set 2: Glyph sub-objects for i, obj in enumerate(self.colorSets[1][1:]): color = colors['glyph'].with_hue(colors['glyph'].hsl[0] - (i + 1) * 15) colors[obj] = color # color set 3: Contour sub-objects for i, obj in enumerate(self.colorSets[2][1:]): color = colors['contour'].with_hue(colors['contour'].hsl[0] - (i + 1) * 20) colors[obj] = color # color set 4: Layer colors['layer'] = colors['font'].blend(colors['glyph'], percent=0.5) self.colors = colors @property def colorsRGB(self): colors = {} for obj, color in self.colors.items(): colors[obj] = color.rgb return colors @property def colorsCMYK(self): colors = {} for obj, color in self.colors.items(): colors[obj] = color.cmyk return colors def drawSwatches(self, pos, cellSize, padding, captions=False): x, y = pos w, h = cellSize save() translate(x, y) fontSize(w * .12) for colorSet in reversed(self.colorSets): save() for obj in colorSet: color = self.colorsRGB[obj] fill(*color) rect(0, 0, w, h) if captions: fill(0) text(obj, (w * .1, h * .2)) translate(w + padding, 0) restore() translate(0, (h + padding)) restore()