コード例 #1
0
    def test_rgb(self):
        self.assertEqualColor('rgb(1,2,3)', rgb(1, 2, 3))
        self.assertEqualColor('rgb(1, 2, 3)', rgb(1, 2, 3))
        self.assertEqualColor('rgb( 1 , 2 , 3)', rgb(1, 2, 3))

        self.assertEqualColor('#123', rgb(0x11, 0x22, 0x33))
        self.assertEqualColor('#112233', rgb(0x11, 0x22, 0x33))
        self.assertEqualColor('#abc', rgb(0xaa, 0xbb, 0xcc))
        self.assertEqualColor('#ABC', rgb(0xaa, 0xbb, 0xcc))
        self.assertEqualColor('#abcdef', rgb(0xab, 0xcd, 0xef))
        self.assertEqualColor('#ABCDEF', rgb(0xab, 0xcd, 0xef))

        with self.assertRaises(ValueError):
            color('rgb(10, 20)')

        with self.assertRaises(ValueError):
            color('rgb(a, 10, 20)')

        with self.assertRaises(ValueError):
            color('rgb(10, b, 20)')

        with self.assertRaises(ValueError):
            color('rgb(10, 20, c)')

        with self.assertRaises(ValueError):
            color('rgb(10, 20, 30, 0.5)')
コード例 #2
0
    def test_named_color(self):
        self.assertEqualColor('Red', rgb(0xFF, 0, 0))
        self.assertEqualColor('RED', rgb(0xFF, 0, 0))
        self.assertEqualColor('red', rgb(0xFF, 0, 0))
        self.assertEqualColor('rEd', rgb(0xFF, 0, 0))

        self.assertEqualColor('CornflowerBlue', rgb(0x64, 0x95, 0xED))
        self.assertEqualColor('cornflowerblue', rgb(0x64, 0x95, 0xED))
        self.assertEqualColor('CORNFLOWERBLUE', rgb(0x64, 0x95, 0xED))
        self.assertEqualColor('Cornflowerblue', rgb(0x64, 0x95, 0xED))
        self.assertEqualColor('CoRnFlOwErBlUe', rgb(0x64, 0x95, 0xED))

        with self.assertRaises(ValueError):
            color('not a color')
コード例 #3
0
 def assertEqualColor(self, value, expected):
     # Nothing fancy - a color is equal if the attributes are all the same
     actual = color(value)
     self.assertEqual(actual.r, expected.r)
     self.assertEqual(actual.g, expected.g)
     self.assertEqual(actual.b, expected.b)
     self.assertAlmostEqual(actual.a, expected.a, places=3)
コード例 #4
0
 def assertEqualHSL(self, value, expected):
     # Nothing fancy - a color is equal if the attributes are all the same
     actual = color(value)
     self.assertEqual(actual.h, expected.h)
     self.assertEqual(actual.s, expected.s)
     self.assertEqual(actual.l, expected.l)
     self.assertAlmostEqual(actual.a, expected.a, places=3)
コード例 #5
0
    def test_hsl(self):
        self.assertEqualHSL('hsl(1,20%,30%)', hsl(1, 0.2, 0.3))
        self.assertEqualHSL('hsl(1, 20%, 30%)', hsl(1, 0.2, 0.3))
        self.assertEqualHSL('hsl( 1, 20% , 30%)', hsl(1, 0.2, 0.3))

        with self.assertRaises(ValueError):
            color('hsl(1, 20%)')

        with self.assertRaises(ValueError):
            color('hsl(a, 20%, 30%)')

        with self.assertRaises(ValueError):
            color('hsl(1, a, 30%)')

        with self.assertRaises(ValueError):
            color('hsl(1, 20%, a)')

        with self.assertRaises(ValueError):
            color('hsl(1, 20%, 30%, 0.5)')
コード例 #6
0
    def test_rgba(self):
        self.assertEqualColor('rgba(1,2,3,0.5)', rgba(1, 2, 3, 0.5))
        self.assertEqualColor('rgba(1, 2, 3, 0.5)', rgba(1, 2, 3, 0.5))
        self.assertEqualColor('rgba( 1 , 2 , 3 , 0.5)', rgba(1, 2, 3, 0.5))

        self.assertEqualColor('#1234', rgba(0x11, 0x22, 0x33, 0.2666))
        self.assertEqualColor('#11223344', rgba(0x11, 0x22, 0x33, 0.2666))
        self.assertEqualColor('#abcd', rgba(0xaa, 0xbb, 0xcc, 0.8666))
        self.assertEqualColor('#ABCD', rgba(0xaa, 0xbb, 0xcc, 0.8666))
        self.assertEqualColor('#abcdefba', rgba(0xab, 0xcd, 0xef, 0.7294))
        self.assertEqualColor('#ABCDEFBA', rgba(0xab, 0xcd, 0xef, 0.7294))

        with self.assertRaises(ValueError):
            color('rgba(10, 20, 30)')

        with self.assertRaises(ValueError):
            color('rgba(a, 10, 20, 0.5)')

        with self.assertRaises(ValueError):
            color('rgba(10, b, 20, 0.5)')

        with self.assertRaises(ValueError):
            color('rgba(10, 20, c, 0.5)')

        with self.assertRaises(ValueError):
            color('rgba(10, 20, 30, c)')

        with self.assertRaises(ValueError):
            color('rgba(10, 20, 30, 0.5, 5)')
コード例 #7
0
__name__ = 'Commodore 64'

# Commodore64 'full screen' is 403 pixels wide x 284 pixels high,
# including the border area
full_screen_size = (403, 284)

# Commodore64 'addressable' screen area - 320 pixels wide x 200 pixels high
screen_size = (320, 200)

# Commodore64 text characters are 8 pixels wide x 8 pixels high
character_size = (8, 8)

# Commodore 64 colors - see the very interesting article here:
#    http://unusedino.de/ec64/technical/misc/vic656x/colors/
colors = [
    color('#000000'),  # 0  black
    color('#FFFFFF'),  # 1  white
    color('#68372B'),  # 2  red
    color('#70A4B2'),  # 3  cyan
    color('#6F3D86'),  # 4  purple
    color('#588D43'),  # 5  green
    color('#352879'),  # 6  blue
    color('#B8C76F'),  # 7  yellow
    color('#6F4F25'),  # 8  orange
    color('#433900'),  # 9  brown
    color('#9A6759'),  # 10 light red
    color('#444444'),  # 11 dark grey
    color('#6C6C6C'),  # 12 grey
    color('#9AD284'),  # 13 light green
    color('#6C5EB5'),  # 14 light blue
    color('#959595'),  # 15 light grey
コード例 #8
0
__name__ = 'ZX Spectrum'

# ZX Spectrum 'full screen' is 403 pixels wide x 312 pixels high,
# including the border area
full_screen_size = (352, 312)

# ZX Spectrum 'addressable' screen area - 256 pixels wide x 192 pixels high
screen_size = (256, 192)

# ZX Spectrum text characters are 8 pixels wide x 8 pixels high
character_size = (8, 8)

# ZX Spectrum  colors
colors = [
    # dark
    color('#000000'),  # black
    color('#0000D7'),  # blue
    color('#D70000'),  # red
    color('#D700D7'),  # magenta
    color('#00D700'),  # green
    color('#00D7D7'),  # cyan
    color('#D7D700'),  # yellow
    color('#D7D7D7'),  # white
    # bright
    color('#000000'),  # black
    color('#0000FF'),  # blue
    color('#FF0000'),  # red
    color('#FF00FF'),  # magenta
    color('#00FF00'),  # green
    color('#00FFFF'),  # cyan
    color('#FFFF00'),  # yellow
コード例 #9
0
# http://harveycohen.net/oznaki/microbee.html
__name__ = 'MicroBee'

# Microbee 'full screen' is 512 pixels wide x 512 pixels high,
# including the border area
full_screen_size = (512, 512)

# Microbee 'addressable' screen area - 512 pixels wide x 512 pixels high
screen_size = (512, 512)

# Microbee text characters are 8 pixels wide x 16 pixels high
character_size = (8, 16)

# Microbee colors (monochrome display)
colors = [
    color('#000000'),  # black
    color('#00FF00'),  # green
]

default_border_color = 0  # black
default_screen_color = 0  # black
default_text_color = 1  # green

font = MICROBEE_FONT

# The character code to use for the cursor ('_')

cursor_char = 95

# Cursor blink delay (in ms)
cursor_blink_delay = 500