git @ Cat's Eye Technologies NaNoGenLab / 42aa964
Import of checkerboard-layout experiment. Chris Pressey 10 years ago
3 changed file(s) with 65 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
0 checkerboard-layout
1 ===================
2
3 Requirements
4 ------------
5
6 * Python 2.7.6 (probably works with older versions too)
7 * An input text
8 * A modern web browser (to see the result)
9
10 Basic Strategy
11 --------------
12
13 * Display each alternating word on a background of an alternating
14 colour. This allows us to remove intervening spaces and still
15 claim that the result is readable.
16
17 Sample Output
18 -------------
19
20 Here is a screenshot of Firefox 33.0 displaying something by Lord Dunsany
21 that was passed through this script:
22
23 ![screenshor][screenshot.png]
0 #!/usr/bin/env python
1
2
3 def template(title, styles, wordlist):
4 return """<!DOCTYPE html>
5 <head>
6 <meta charset="utf-8">
7 <title>{0}</title>
8 <style>{1}</style>
9 </head>
10 <body>{2}</body>
11 """.format(title, '\n'.join(styles), ''.join(wordlist))
12
13
14 def main(argv):
15 words = []
16 with open(argv[1], 'r') as f:
17 for line in f:
18 words.extend(line.strip().replace('-', ':').split())
19
20 styles = [
21 ".b0 { background: black; color: white; word-wrap: break-word }",
22 ".b1 { background: white; color: black; word-wrap: break-word }",
23 ]
24
25 title = "Gimme that Old-Time Collision"
26
27 num = 0
28 marked_up_words = []
29 for word in words:
30 marked_up_words.append(
31 '<span class="b{0}">{1}</span>'.format(num % 2, word)
32 )
33 num += 1
34
35 print template(title, styles, marked_up_words)
36
37
38 if __name__ == '__main__':
39 import sys
40 main(sys.argv)