paul@23 | 1 | # -*- coding: iso-8859-1 -*- |
paul@23 | 2 | """ |
paul@23 | 3 | MoinMoin - ViewSupport library (derived from EventAggregatorSupport) |
paul@23 | 4 | |
paul@23 | 5 | @copyright: 2008, 2009, 2010, 2011, 2012 by Paul Boddie <paul@boddie.org.uk> |
paul@23 | 6 | @license: GNU GPL (v2 or later), see COPYING.txt for details. |
paul@23 | 7 | """ |
paul@23 | 8 | |
paul@23 | 9 | # Colour-related functions. |
paul@23 | 10 | |
paul@23 | 11 | def getColour(s): |
paul@23 | 12 | colour = [0, 0, 0] |
paul@23 | 13 | digit = 0 |
paul@23 | 14 | for c in s: |
paul@23 | 15 | colour[digit] += ord(c) |
paul@23 | 16 | colour[digit] = colour[digit] % 256 |
paul@23 | 17 | digit += 1 |
paul@23 | 18 | digit = digit % 3 |
paul@23 | 19 | return tuple(colour) |
paul@23 | 20 | |
paul@23 | 21 | def getBlackOrWhite(colour): |
paul@23 | 22 | if sum(colour) / 3.0 > 127: |
paul@23 | 23 | return (0, 0, 0) |
paul@23 | 24 | else: |
paul@23 | 25 | return (255, 255, 255) |
paul@23 | 26 | |
paul@23 | 27 | # vim: tabstop=4 expandtab shiftwidth=4 |