Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- primes = []
- def getfac(n):
- if n == 1:
- return []
- for p in primes:
- if n % p == 0:
- return [p] + getfac(n / p)
- else:
- primes.append(n)
- return [n]
- faclist = [[], []] + [getfac(n) for n in range(2, 101)]
- palette = ['224186', '941520', 'df9c19', '502364', 'c02b5e', '483131', 'd03a20',
- '065371', '111113', '641821', '177c6f', '8c2261', 'b21b23', 'd1b341',
- '7f65a4', '385190', '63771c', 'bb506b', '3a9fbb', '836f6f', '789b65',
- '7ba3c2', '8482a6', 'bd96a1', 'b1a676']
- cmap = { prime: color for prime, color in zip(primes, palette) }
- pitch = 5
- # 1: 17
- # 2: 8 + 1 + 8
- # 3: 5 + 1 + 5 + 1 + 5
- div1, div2, div3, sep = pitch * 17, pitch * 8, pitch * 5, pitch * 2
- unit = '<td width={div1} height={div1}'.format(div1=div1)
- row = lambda height, *tds: '<tr>' + ''.join('<td {} height={} />'.format(td, height) for td in tds) + '</tr>'
- col2 = lambda c0, c1: ('bgcolor="#{c[%d]}" width={div2}' % c0, 'width={pitch}', 'bgcolor="#{c[%d]}" width={div2}' % c1)
- subtable = lambda *items: '{unit}><table border=0 cellspacing=0 cellpadding=0>' + ''.join(items) + '</table></td>'
- squares = [
- # blank
- '{unit} />',
- # 1x1
- '{unit} bgcolor="#{c[0]}" />',
- # 1x2
- subtable(row(div1, *col2(0, 1))),
- # 3x1
- subtable(row(div3, 'bgcolor="#{c[0]}" width={div1}'),
- row(pitch, 'width={div1}'),
- row(div3, 'bgcolor="#{c[1]}" width={div1}'),
- row(pitch, 'width={div1}'),
- row(div3, 'bgcolor="#{c[2]}" width={div1}')),
- # 2x2
- subtable(row(div2, *col2(0, 1)),
- row(pitch, 'width={div1} colspan=3'),
- row(div2, *col2(2, 3))),
- # 2, 1, 2
- subtable(row(div3, 'bgcolor="#{c[0]}" width={div2} colspan=2', 'width={pitch}', 'bgcolor="#{c[1]}" width={div2} colspan=2'),
- row(pitch, 'width={div1} colspan=5'),
- row(div3, '', 'bgcolor="#{c[2]}" width={div2} colspan=3', ''),
- row(pitch, 'width={div1} colspan=5'),
- row(div3, 'bgcolor="#{c[3]}" width={div2} colspan=2', 'width={pitch}', 'bgcolor="#{c[4]}" width={div2} colspan=2')),
- # 3x2
- subtable(row(div3, *col2(0, 1)),
- row(pitch, 'width={div1} colspan=3'),
- row(div3, *col2(2, 3)),
- row(pitch, 'width={div1} colspan=3'),
- row(div3, *col2(4, 5))) ]
- with open('20120429.html', 'wb') as f:
- print >>f, '<html><body bgcolor="#ccc8c7"><table border=0 cellspacing={sep} cellpadding=0>'.format(**globals())
- for row in range(91, 0, -10):
- print >>f, '<tr>'
- for n in range(row, row + 10):
- colors = [cmap[fac] for fac in faclist[n]]
- print >>f, squares[len(colors)].format(c=colors, **globals())
- print >>f, '</tr>'
- print >>f, '</table></body></html>'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement