Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
def bars(html_filename, list_of_stuff):
with open(html_filename, "w") as htmlfile:
htmlfile.write("<html><head><style>.bar { width: 100%; height: 0.3em; } </style></head><body>")
for instance_number in list_of_stuff:
htmlfile.write('<div class="bar" style="background-color: #{0};">&nbsp;</div>\n'.format(instance_number))
htmlfile.write("</body></html>")
def blocks(html_filename, list_of_stuff):
with open(html_filename, "w") as htmlfile:
htmlfile.write("<html><head><style>.block { width: 0.3em; height: 0.3em; float:left; } </style></head><body>")
for instance_number in list_of_stuff:
htmlfile.write('<div class="block" style="background-color: #{0};">&nbsp;</div>\n'.format(instance_number))
htmlfile.write("</body></html>")
from struct import pack
# Methods to generate random and ordered numbers for testing:
def random_stuff(amount):
from random import randint
# Create 'amount' of 6 digit hex numbers as a string, from 3 random (0 -> 255) numbers packed together:
return map(lambda x: pack("BBB", randint(0,255), randint(0,255), randint(0,255)).encode("hex"), range(amount))
def ordered_stuff(amount):
delta = (256 ** 3 - 1) / amount
return map(lambda x: pack("BBB", delta*x / 256 ** 2, delta*x / 256 % 256, delta*x % 256 ).encode("hex"), range(amount))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.