Last active
August 29, 2015 14:06
-
-
Save jkominek/e7d6575459aa88be9b60 to your computer and use it in GitHub Desktop.
Generate some HTML you can print and cut apart to make labels for drawers of resistors
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# resistor colors | |
colors = [ 'black', '#964b00', 'red', '#ffa500', 'yellow', | |
'#9acd32', '#6495ed', '#ee82ee', 'gray', 'white' ] | |
# borders around some of the lighter colors | |
border = [ 0, 0, 0, 0, 1, 0, 0, 0, 1, 1 ] | |
out = open("labels.html","wb") | |
out.write("<html><body><table>") | |
chunks = [ ] | |
for i in range(10, 100): | |
a = i // 10 | |
b = i % 10 | |
chunks.append(""" | |
<span style="bottom-padding:2em;"> | |
<svg width="1.5in" height="0.75in" style="text-anchor:middle;"> | |
<rect width="0.375in" height="0.75in" style="fill:%s;stroke-width:%i;stroke:black" /> | |
<text x="0.5625in" y="0.65in" style="stroke:none; font-size:0.75in;">%i</text> | |
<text x="0.9375in" y="0.65in" style="stroke:none; font-size:0.75in;">%i</text> | |
<rect x="1.125in" width="0.375in" height="0.75in" style="fill:%s;stroke-width:%i;stroke:black" /> | |
</svg> | |
</span> | |
""" % (colors[a], border[a], a, b, colors[b], border[b])) | |
s = 0 | |
while s<100: | |
row = "".join([ "<td style='padding:1em;'>%s</td>" % (c,) for c in chunks[s:s+4] ]) | |
out.write("<tr>"+row+"</tr>") | |
s += 4 | |
out.write("</table></body></html>") | |
out.flush() | |
out.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
oh, and it is public domain. or ISC license if you live somewhere public domain doesn't exist. or whatever license you want.