gitignore ignorable gtksparrow executable
[sparrow.git] / false_colour.py
blobf22beda4f3fec99795db3bae551a4570816259bc
1 #!/usr/bin/python
3 from math import sin, cos, pi
5 POINTS = 16
8 def colour_cycle(points, fn=cos):
9 colours = []
10 for i in range(points):
11 a = i * 2.0 * pi / points
12 _r = fn(a)
13 _g = fn(a + pi * 2 / 3.0)
14 _b = fn(a + pi * 4 / 3.0)
16 r = (int(255.99 * (_r + 1) * 0.5))
17 g = (int(255.99 * (_g + 1) * 0.5))
18 b = (int(255.99 * (_b + 1) * 0.5))
20 colours.append((r, g, b))
21 return colours
23 def hex_format(colours):
24 return ["%02x%02x%02x" % x for x in colours]
26 def html_test(colours):
27 print "<html><body>"
28 for c in colours:
29 rgb = "#%02x%02x%02x" % c
30 print '<div style="width:100%%; height:30px; background: %s">' % (rgb, )
31 print rgb
32 print '</div>'
33 print '</body></html>'
35 def cformat(colours, name, wrap=75, unused=True):
36 # convert to 32bit mask by replicating first couplet as last
37 # the mask will work whether the format is RGB_, _RGB, BGR_, or _BGR
38 table = ['0x%02x%02x%02x%02x' % (c[2], c[0], c[1], c[2]) for c in colours]
39 table.append('0x000000')
40 outs = []
41 if unused:
42 outs.append('UNUSED')
44 outs.extend(("static const guint32 %s [%s] = {" % (name, len(table)),
45 ' %s' % table[0]))
46 for v in table[1:]:
47 if len(outs[-1]) >= wrap:
48 outs[-1] += ','
49 outs.append(' %s' % v)
50 else:
51 outs[-1] += ', %s' % v
52 outs.append('};\n')
54 print '\n'.join(outs)
58 c = colour_cycle(POINTS)
59 #print hex_format(c)
60 #html_test(c)
61 cformat(c, "lag_false_colour")