Beispiel #1
0
def printStylesheet(prime_to_color):
    print '''<style>
    table {
      vertical-align: bottom;
      width: 1in;
      height: 1in;
      display: inline-table;
    }
    tr, td {
      /* KLUDGE: Makes columns equal width on Safari. */
      width:1%;
    }
    '''

    # We want a diverse palette, so evenly divide a Hilbert curve for RGB
    # space. This is inspired by (and uses code from)
    # http://corte.si/posts/visualisation/binvis/index.html
    num_colors = max(prime_to_color.values()) + 1
    hilbert = scurve.fromSize('hilbert', 3, RGB_SIZE)
    colors = [hilbert[i] for i in range(0, RGB_SIZE, RGB_SIZE // num_colors)]

    # We also want numbers that are close to each other to have very
    # different colors, so phiffle the colors, and convert to CSS-friendly
    # form while we're at it.
    colors = ['#%02x%02x%02x' % (r, g, b) for (r, g, b) in phiffle(colors)]

    for prime, color in sorted(prime_to_color.items()):
        print '    .prime_%d { background-color: %s; }' % (prime,
                                                           colors[color])
    print '''</style>'''
def main():
    from optparse import OptionParser, OptionGroup
    parser = OptionParser(
                usage = "%prog [options] output",
                version="%prog 0.1",
            )
    parser.add_option("-c", "--color", action="store", dest="color", default="0A2376")
    parser.add_option(
        "-b", "--background", action="store", dest="background", default="FFFFFF"
    )
    parser.add_option(
        "-s", "--size", action="store",
        type="int", dest="size", default=100
    )
    parser.add_option(
        "-o", "--order", action="store",
        type="int", dest="order", default=None,
        help = "Order of the curve."
    )
    parser.add_option(
        "-p", "--points", action="store",
        type="int", dest="points", default=None,
        help = "Total number of points on the curve."
    )
    parser.add_option(
        "-d", "--dotsize", action="store",
        type="int", dest="dotsize", default=2
    )
    parser.add_option(
        "-m", "--mark", action="append",
        type="int", dest="mark", default=[]
    )
    parser.add_option(
        "-u", "--curve", action="store",
        type="str", dest="curve", default="hilbert"
    )
    bla=[]
    bla.append("test.png")
    bla.append("-o 4")
    options, args = parser.parse_args(bla)
    if len(args) != 1:
        parser.error("Please specify output file.")

    if options.order:
        c = scurve.fromOrder(options.curve, 2, options.order)
    elif options.points:
        c = scurve.fromSize(options.curve, 2, options.points)
    else:
        parser.error("Must specify either points or order.")

    d = draw.Demo(
            c,
            options.size,
            options.color,
            options.background,
            options.dotsize,
            *options.mark
        )
    d.draw()
    d.save(args[0])
Beispiel #3
0
def printStylesheet(prime_to_color):
    print """<style>
    table {
      vertical-align: bottom;
      width: 1in;
      height: 1in;
      display: inline-table;
    }
    tr, td {
      /* KLUDGE: Makes columns equal width on Safari. */
      width:1%;
    }
    """

    # We want a diverse palette, so evenly divide a Hilbert curve for RGB
    # space. This is inspired by (and uses code from)
    # http://corte.si/posts/visualisation/binvis/index.html
    num_colors = max(prime_to_color.values()) + 1
    hilbert = scurve.fromSize("hilbert", 3, RGB_SIZE)
    colors = [hilbert[i] for i in range(0, RGB_SIZE, RGB_SIZE // num_colors)]

    # We also want numbers that are close to each other to have very
    # different colors, so phiffle the colors, and convert to CSS-friendly
    # form while we're at it.
    colors = ["#%02x%02x%02x" % (r, g, b) for (r, g, b) in phiffle(colors)]

    for prime, color in sorted(prime_to_color.items()):
        print "    .prime_%d { background-color: %s; }" % (prime, colors[color])
    print """</style>"""
Beispiel #4
0
 def colour(self, x, n):
     if n != self.size:
         self.curve = scurve.fromSize("hilbert", 3, self.findSize(n))
     d = float(self.curve.dimensions()[0])
     # Scale X to sample evenly from the curve, if the list length isn't
     # an exact match for the Hilbert curve size.
     x = x * int(len(self.curve) / float(n))
     return tuple([i / d for i in self.curve.point(x)])
Beispiel #5
0
 def colour(self, x, n):
     if n != self.size:
         self.curve = scurve.fromSize("hilbert", 3, self.findSize(n))
     d = float(self.curve.dimensions()[0])
     # Scale X to sample evenly from the curve, if the list length isn't
     # an exact match for the Hilbert curve size.
     x = x*int(len(self.curve)/float(n))
     return tuple([i/d for i in self.curve.point(x)])
Beispiel #6
0
def drawmap_square(map, size, csource, name, prog):
    prog.set_target((size**2))
    map = scurve.fromSize(map, 2, size**2)
    c = Image.new("RGB", map.dimensions())
    cd = ImageDraw.Draw(c)
    step = len(csource) / float(len(map))
    for i, p in enumerate(map):
        color = csource.point(int(i * step))
        cd.point(tuple(p), fill=tuple(color))
        if not i % 100:
            prog.tick(i)
    c.save(name)
Beispiel #7
0
def drawmap_unrolled(map, size, csource, name, prog):
    prog.set_target((size**2) * 4)
    map = scurve.fromSize(map, 2, size**2)
    c = Image.new("RGB", (size, size * 4))
    cd = ImageDraw.Draw(c)
    step = len(csource) / float(len(map) * 4)

    sofar = 0
    for quad in range(4):
        for i, p in enumerate(map):
            off = (i + (quad * size**2))
            color = csource.point(int(off * step))
            x, y = tuple(p)
            cd.point((x, y + (size * quad)), fill=tuple(color))
            if not sofar % 100:
                prog.tick(sofar)
            sofar += 1
    c.save(name)
Beispiel #8
0
 def __init__(self, data, block):
     _Color.__init__(self, data, block)
     self.csource = scurve.fromSize("hilbert", 3, 256**3)
     self.step = len(self.csource) / float(len(self.symbol_map))