def draw(title, subtitle, author, cover_width=<NUM_LIT>, cover_height=<NUM_LIT>):
<EOL>def processColors():<EOL><INDENT>base_saturation = <NUM_LIT:100><EOL>base_brightness = <NUM_LIT><EOL>color_distance = <NUM_LIT:100><EOL>invert = True<EOL>counts = len(title) + len(author)<EOL>color_seed = int(_map(_clip(counts, <NUM_LIT:2>, <NUM_LIT>), <NUM_LIT:2>, <NUM_LIT>, <NUM_LIT:10>, <NUM_LIT>))<EOL>shape_color = Image.colorHSB(color_seed, base_saturation, base_brightness-(counts % <NUM_LIT:20>))<EOL>base_color = Image.colorHSB((<EOL>color_seed + color_distance) % <NUM_LIT>,<EOL>base_saturation,<EOL>base_brightness<EOL>)<EOL>if invert:<EOL><INDENT>shape_color, base_color = base_color, shape_color<EOL><DEDENT>if (counts % <NUM_LIT:10>) == <NUM_LIT:0>:<EOL><INDENT>shape_color, base_color = base_color, shape_color<EOL><DEDENT>return shape_color, base_color<EOL><DEDENT>def drawBackground():<EOL><INDENT>fill = Image.colorRGB(<NUM_LIT:255>, <NUM_LIT:255>, <NUM_LIT:255>)<EOL>cover_image.rect(<NUM_LIT:0>, <NUM_LIT:0>, cover_width, cover_height, fill)<EOL><DEDENT>def drawArtwork():<EOL><INDENT>artwork_start_x = <NUM_LIT:0><EOL>artwork_start_y = cover_height - cover_width<EOL>grid_count, grid_total, grid_size = breakGrid()<EOL>cover_image.rect(<NUM_LIT:0>, <NUM_LIT:0>, cover_width, cover_height * cover_margin / <NUM_LIT:100>, base_color)<EOL>cover_image.rect(<NUM_LIT:0>, <NUM_LIT:0> + artwork_start_y, cover_width, cover_width, base_color)<EOL>c64_title = c64Convert()<EOL>for c, i in zip(itertools.cycle(c64_title), range(<NUM_LIT:0>, grid_total)):<EOL><INDENT>grid_x = int(i % grid_count)<EOL>grid_y = int(i / grid_count)<EOL>x = grid_x * grid_size + artwork_start_x<EOL>y = grid_y * grid_size + artwork_start_y<EOL>drawShape(c, x, y, grid_size)<EOL><DEDENT><DEDENT>def breakGrid():<EOL><INDENT>min_title = <NUM_LIT:2><EOL>max_title = <NUM_LIT><EOL>length = _clip(len(title), min_title, max_title)<EOL>grid_count = int(_map(length, min_title, max_title, <NUM_LIT:2>, <NUM_LIT:11>))<EOL>grid_total = grid_count * grid_count<EOL>grid_size = cover_width / grid_count<EOL>return grid_count, grid_total, grid_size<EOL><DEDENT>def c64Convert():<EOL><INDENT>c64_letters = "<STR_LIT>"<EOL>c64_title = "<STR_LIT>"<EOL>for c in title:<EOL><INDENT>if c in c64_letters:<EOL><INDENT>c64_title += c<EOL><DEDENT>else:<EOL><INDENT>c64_title += c64_letters[ord(c) % len(c64_letters)]<EOL><DEDENT><DEDENT>return c64_title<EOL><DEDENT>def drawShape(c, x, y, s):<EOL><INDENT>shape_thickness = <NUM_LIT:10><EOL>thick = int(s * shape_thickness / <NUM_LIT:100>)<EOL>if c in "<STR_LIT>":<EOL><INDENT>cover_image.ellipse(x, y, s, s, shape_color)<EOL><DEDENT>elif c in "<STR_LIT>":<EOL><INDENT>cover_image.ellipse(x, y, s, s, shape_color)<EOL>cover_image.ellipse(x+thick, y+thick, s-(thick*<NUM_LIT:2>), s-(thick*<NUM_LIT:2>), base_color)<EOL><DEDENT>elif c in "<STR_LIT>":<EOL><INDENT>cover_image.rect(x, y+thick, s, thick, shape_color)<EOL><DEDENT>elif c in "<STR_LIT>":<EOL><INDENT>cover_image.rect(x, y+s-(thick*<NUM_LIT:2>), s, thick, shape_color)<EOL><DEDENT>elif c in "<STR_LIT>":<EOL><INDENT>cover_image.rect(x+thick, y, thick, s, shape_color)<EOL><DEDENT>elif c in "<STR_LIT>":<EOL><INDENT>cover_image.rect(x+s-(thick*<NUM_LIT:2>), y, thick, s, shape_color)<EOL><DEDENT>elif c in "<STR_LIT>":<EOL><INDENT>cover_image.arc(x, y, <NUM_LIT:2>*s, <NUM_LIT:2>*s, <NUM_LIT>, <NUM_LIT>, shape_color, thick)<EOL><DEDENT>elif c in "<STR_LIT>":<EOL><INDENT>cover_image.arc(x-s, y, <NUM_LIT:2>*s, <NUM_LIT:2>*s, <NUM_LIT>, <NUM_LIT>, shape_color, thick)<EOL><DEDENT>elif c in "<STR_LIT>":<EOL><INDENT>cover_image.rect(x, y, s, thick, shape_color)<EOL>cover_image.rect(x, y, thick, s, shape_color)<EOL><DEDENT>elif c in "<STR_LIT>":<EOL><INDENT>cover_image.rect(x, y, s, thick, shape_color)<EOL>cover_image.rect(x+s-thick, y, thick, s, shape_color)<EOL><DEDENT>elif c in "<STR_LIT>":<EOL><INDENT>cover_image.triangle(x, y+s, x+(s/<NUM_LIT:2>), y, x+s, y+s, shape_color)<EOL><DEDENT>elif c in "<STR_LIT>":<EOL><INDENT>cover_image.triangle(x, y, x+(s/<NUM_LIT:2>), y+s, x+s, y, shape_color)<EOL><DEDENT>elif c in "<STR_LIT>":<EOL><INDENT>cover_image.rect(x, y+(thick*<NUM_LIT:2>), s, thick, shape_color)<EOL><DEDENT>elif c in "<STR_LIT>":<EOL><INDENT>cover_image.rect(x, y+s-(thick*<NUM_LIT:3>), s, thick, shape_color)<EOL><DEDENT>elif c in "<STR_LIT>":<EOL><INDENT>cover_image.rect(x+(thick*<NUM_LIT:2>), y, thick, s, shape_color)<EOL><DEDENT>elif c in "<STR_LIT>":<EOL><INDENT>cover_image.rect(x+s-(thick*<NUM_LIT:3>), y, thick, s, shape_color)<EOL><DEDENT>elif c in "<STR_LIT>":<EOL><INDENT>cover_image.arc(x, y-s, <NUM_LIT:2>*s, <NUM_LIT:2>*s, <NUM_LIT>, <NUM_LIT>, shape_color, thick)<EOL><DEDENT>elif c in "<STR_LIT>":<EOL><INDENT>cover_image.arc(x-s, y-s, <NUM_LIT:2>*s, <NUM_LIT:2>*s, <NUM_LIT:0>, <NUM_LIT>, shape_color, thick)<EOL><DEDENT>elif c in "<STR_LIT>":<EOL><INDENT>cover_image.rect(x, y, thick, s, shape_color)<EOL>cover_image.rect(x, y+s-thick, s, thick, shape_color)<EOL><DEDENT>elif c == "<STR_LIT::>":<EOL><INDENT>cover_image.rect(x+s-thick, y, thick, s, shape_color)<EOL>cover_image.rect(x, y+s-thick, s, thick, shape_color)<EOL><DEDENT>elif c in "<STR_LIT>":<EOL><INDENT>cover_image.triangle(x, y+(s/<NUM_LIT:2>), x+(s/<NUM_LIT:2>), y, x+s, y+(s/<NUM_LIT:2>), shape_color)<EOL>cover_image.triangle(x, y+(s/<NUM_LIT:2>), x+(s/<NUM_LIT:2>), y+s, x+s, y+(s/<NUM_LIT:2>), shape_color)<EOL><DEDENT>elif c in "<STR_LIT>":<EOL><INDENT>cover_image.ellipse(x+(s/<NUM_LIT:2>), y+(s/<NUM_LIT:3>), thick*<NUM_LIT:2>, thick*<NUM_LIT:2>, shape_color)<EOL>cover_image.ellipse(x+(s/<NUM_LIT:3>), y+s-(s/<NUM_LIT:3>), thick*<NUM_LIT:2>, thick*<NUM_LIT:2>, shape_color)<EOL>cover_image.ellipse(x+s-(s/<NUM_LIT:3>), y+s-(s/<NUM_LIT:3>), thick*<NUM_LIT:2>, thick*<NUM_LIT:2>, shape_color)<EOL><DEDENT>elif c in "<STR_LIT>":<EOL><INDENT>cover_image.rect(x, y+(thick*<NUM_LIT:3>), s, thick, shape_color)<EOL><DEDENT>elif c in "<STR_LIT>":<EOL><INDENT>cover_image.rect(x, y, s, s, shape_color)<EOL>cover_image.triangle(x+thick, y, x+(s/<NUM_LIT:2>), y+(s/<NUM_LIT:2>)-thick, x+s-thick, y, base_color)<EOL>cover_image.triangle(x, y+thick, x+(s/<NUM_LIT:2>)-thick, y+(s/<NUM_LIT:2>), x, y+s-thick, base_color)<EOL>cover_image.triangle(x+thick, y+s, x+(s/<NUM_LIT:2>), y+(s/<NUM_LIT:2>)+thick, x+s-thick, y+s, base_color)<EOL>cover_image.triangle(x+s, y+thick, x+s, y+s-thick, x+(s/<NUM_LIT:2>)+thick, y+(s/<NUM_LIT:2>), base_color)<EOL><DEDENT>elif c in "<STR_LIT>":<EOL><INDENT>cover_image.rect(x+(thick*<NUM_LIT:3>), y, thick, s, shape_color)<EOL><DEDENT>elif c in "<STR_LIT>":<EOL><INDENT>cover_image.rect(x, y, s, s, shape_color)<EOL>cover_image.triangle(x, y, x+s-thick, y, x, y+s-thick, base_color)<EOL>cover_image.triangle(x+thick, y+s, x+s, y+s, x+s, y+thick, base_color)<EOL><DEDENT>elif c in "<STR_LIT>":<EOL><INDENT>cover_image.rect(x, y, s, s, shape_color)<EOL>cover_image.triangle(x+thick, y, x+s, y, x+s, y+s-thick, base_color)<EOL>cover_image.triangle(x, y+thick, x, y+s, x+s-thick, y + s, base_color)<EOL><DEDENT>elif c == "<STR_LIT:U+002C>":<EOL><INDENT>cover_image.rect(x+(s/<NUM_LIT:2>), y+(s/<NUM_LIT:2>), s/<NUM_LIT:2>, s/<NUM_LIT:2>, shape_color)<EOL><DEDENT>elif c == "<STR_LIT:;>":<EOL><INDENT>cover_image.rect(x, y+(s/<NUM_LIT:2>), s/<NUM_LIT:2>, s/<NUM_LIT:2>, shape_color)<EOL><DEDENT>elif c == "<STR_LIT:?>":<EOL><INDENT>cover_image.rect(x, y, s/<NUM_LIT:2>, s/<NUM_LIT:2>, shape_color)<EOL>cover_image.rect(x+(s/<NUM_LIT:2>), y+(s/<NUM_LIT:2>), s/<NUM_LIT:2>, s/<NUM_LIT:2>, shape_color)<EOL><DEDENT>elif c == "<STR_LIT:<>":<EOL><INDENT>cover_image.rect(x+(s/<NUM_LIT:2>), y, s/<NUM_LIT:2>, s/<NUM_LIT:2>, shape_color)<EOL><DEDENT>elif c == "<STR_LIT:>>":<EOL><INDENT>cover_image.rect(x, y, s/<NUM_LIT:2>, s/<NUM_LIT:2>, shape_color)<EOL><DEDENT>elif c == "<STR_LIT:@>":<EOL><INDENT>cover_image.rect(x, y+(s/<NUM_LIT:2>)-(thick/<NUM_LIT:2>), s, thick, shape_color)<EOL><DEDENT>elif c == "<STR_LIT:[>":<EOL><INDENT>cover_image.rect(x+(s/<NUM_LIT:2>)-(thick/<NUM_LIT:2>), y, thick, s, shape_color)<EOL><DEDENT>elif c == "<STR_LIT:]>":<EOL><INDENT>cover_image.rect(x, y+(s/<NUM_LIT:2>)-(thick/<NUM_LIT:2>), s, thick, shape_color)<EOL>cover_image.rect(x+(s/<NUM_LIT:2>)-(thick/<NUM_LIT:2>), y, thick, s, shape_color)<EOL><DEDENT>elif c == "<STR_LIT:0>":<EOL><INDENT>cover_image.rect(x+(s/<NUM_LIT:2>)-(thick/<NUM_LIT:2>), y+(s/<NUM_LIT:2>)-(thick/<NUM_LIT:2>), thick, s/<NUM_LIT:2>+thick/<NUM_LIT:2>, shape_color)<EOL>cover_image.rect(x+(s/<NUM_LIT:2>)-(thick/<NUM_LIT:2>), y+(s/<NUM_LIT:2>)-(thick/<NUM_LIT:2>), s/<NUM_LIT:2>+thick/<NUM_LIT:2>, thick, shape_color)<EOL><DEDENT>elif c == "<STR_LIT:1>":<EOL><INDENT>cover_image.rect(x, y+(s/<NUM_LIT:2>)-(thick/<NUM_LIT:2>), s, thick, shape_color)<EOL>cover_image.rect(x+(s/<NUM_LIT:2>)-(thick/<NUM_LIT:2>), y, thick, s/<NUM_LIT:2>+thick/<NUM_LIT:2>, shape_color)<EOL><DEDENT>elif c == "<STR_LIT:2>":<EOL><INDENT>cover_image.rect(x, y+(s/<NUM_LIT:2>)-(thick/<NUM_LIT:2>), s, thick, shape_color)<EOL>cover_image.rect(x+(s/<NUM_LIT:2>)-(thick/<NUM_LIT:2>), y+(s/<NUM_LIT:2>)-(thick/<NUM_LIT:2>), thick, s/<NUM_LIT:2>+thick/<NUM_LIT:2>, shape_color)<EOL><DEDENT>elif c == "<STR_LIT:3>":<EOL><INDENT>cover_image.rect(x, y+(s/<NUM_LIT:2>)-(thick/<NUM_LIT:2>), s/<NUM_LIT:2>+thick/<NUM_LIT:2>, thick, shape_color)<EOL>cover_image.rect(x+(s/<NUM_LIT:2>)-(thick/<NUM_LIT:2>), y, thick, s, shape_color)<EOL><DEDENT>elif c == "<STR_LIT:4>":<EOL><INDENT>cover_image.rect(x, y, thick*<NUM_LIT:2>, s, shape_color)<EOL><DEDENT>elif c == "<STR_LIT:5>":<EOL><INDENT>cover_image.rect(x, y, thick*<NUM_LIT:3>, s, shape_color)<EOL><DEDENT>elif c == "<STR_LIT>":<EOL><INDENT>cover_image.rect(x+s-(thick*<NUM_LIT:3>), y, thick*<NUM_LIT:3>, s, shape_color)<EOL><DEDENT>elif c == "<STR_LIT>":<EOL><INDENT>cover_image.rect(x, y, s, thick*<NUM_LIT:2>, shape_color)<EOL><DEDENT>elif c == "<STR_LIT>":<EOL><INDENT>cover_image.rect(x, y, s, thick*<NUM_LIT:3>, shape_color)<EOL><DEDENT>elif c == "<STR_LIT>":<EOL><INDENT>cover_image.rect(x, y+s-(thick*<NUM_LIT:3>), s, thick*<NUM_LIT:3>, shape_color)<EOL><DEDENT>elif c == "<STR_LIT:.>":<EOL><INDENT>cover_image.rect(x+(s/<NUM_LIT:2>)-(thick/<NUM_LIT:2>), y+(s/<NUM_LIT:2>)-(thick/<NUM_LIT:2>), thick, s/<NUM_LIT:2>+thick/<NUM_LIT:2>, shape_color)<EOL>cover_image.rect(x, y+(s/<NUM_LIT:2>)-(thick/<NUM_LIT:2>), s/<NUM_LIT:2>+thick/<NUM_LIT:2>, thick, shape_color)<EOL><DEDENT>elif c == "<STR_LIT:=>":<EOL><INDENT>cover_image.rect(x+(s/<NUM_LIT:2>)-(thick/<NUM_LIT:2>), y, thick, s/<NUM_LIT:2>+thick/<NUM_LIT:2>, shape_color)<EOL>cover_image.rect(x, y+(s/<NUM_LIT:2>)-(thick/<NUM_LIT:2>), s/<NUM_LIT:2>, thick, shape_color)<EOL><DEDENT>elif c == "<STR_LIT:->":<EOL><INDENT>cover_image.rect(x+(s/<NUM_LIT:2>)-(thick/<NUM_LIT:2>), y, thick, s/<NUM_LIT:2>+thick/<NUM_LIT:2>, shape_color)<EOL>cover_image.rect(x+(s/<NUM_LIT:2>)-(thick/<NUM_LIT:2>), y+(s/<NUM_LIT:2>)-(thick/<NUM_LIT:2>), s/<NUM_LIT:2>+thick/<NUM_LIT:2>, thick, shape_color)<EOL><DEDENT>elif c == "<STR_LIT:+>":<EOL><INDENT>cover_image.rect(x+(s/<NUM_LIT:2>)-(thick/<NUM_LIT:2>), y+(s/<NUM_LIT:2>)-(thick/<NUM_LIT:2>), s/<NUM_LIT:2>+thick/<NUM_LIT:2>, thick, shape_color)<EOL>cover_image.rect(x+(s/<NUM_LIT:2>)-(thick/<NUM_LIT:2>), y, thick, s, shape_color)<EOL><DEDENT>elif c == "<STR_LIT:*>":<EOL><INDENT>cover_image.rect(x+s-(thick*<NUM_LIT:2>), y, thick*<NUM_LIT:2>, s, shape_color)<EOL><DEDENT>elif c == "<STR_LIT:/>":<EOL><INDENT>cover_image.rect(x, y+s-(thick*<NUM_LIT:2>), s, thick*<NUM_LIT:2>, shape_color)<EOL><DEDENT>elif c == "<STR_LIT:U+0020>":<EOL><INDENT>cover_image.rect(x, y, s, s, base_color)<EOL><DEDENT>else:<EOL><INDENT>assert not "<STR_LIT>"<EOL><DEDENT><DEDENT>def scale_font(text, font_name, font_properties):<EOL><INDENT>(font_size, font_slant, font_weight) = font_properties<EOL>w = len(text) * font_size<EOL>if w > cover_width * <NUM_LIT:3>:   <EOL><INDENT>return  (font_size * <NUM_LIT>, font_slant, font_weight)<EOL><DEDENT>elif w < cover_width :<EOL><INDENT>return  (font_size * <NUM_LIT>, font_slant, font_weight)<EOL><DEDENT>else:<EOL><INDENT>return font_properties<EOL><DEDENT><DEDENT>def select_font(text):<EOL><INDENT>for char in text:<EOL><INDENT>if ord(char) >= <NUM_LIT>:<EOL><INDENT>return '<STR_LIT>'<EOL><DEDENT><DEDENT>return '<STR_LIT>'<EOL><DEDENT>def drawText():<EOL><INDENT>fill = Image.colorRGB(<NUM_LIT:50>, <NUM_LIT:50>, <NUM_LIT:50>)<EOL>title_font_size = cover_width * <NUM_LIT><EOL>subtitle_font_size = cover_width * <NUM_LIT><EOL>title_font_properties = (title_font_size, cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_BOLD)<EOL>subtitle_font_properties = (subtitle_font_size, cairo.FONT_SLANT_NORMAL,<EOL>cairo.FONT_WEIGHT_NORMAL)<EOL>title_font_family = select_font(title)<EOL>subtitle_font_family = select_font(subtitle)<EOL>title_font_properties = scale_font(title, title_font_family, title_font_properties)<EOL>subtitle_font_properties = scale_font(<EOL>subtitle,<EOL>subtitle_font_family,<EOL>subtitle_font_properties<EOL>)<EOL>title_font = cover_image.font(title_font_family, title_font_properties)<EOL>subtitle_font = cover_image.font(subtitle_font_family, subtitle_font_properties)<EOL>title_height = (cover_height - cover_width - (cover_height * cover_margin / <NUM_LIT:100>)) * <NUM_LIT><EOL>x = cover_height * cover_margin / <NUM_LIT:100><EOL>y = cover_height * cover_margin / <NUM_LIT:100> * <NUM_LIT:2><EOL>width = cover_width - (<NUM_LIT:2> * cover_height * cover_margin / <NUM_LIT:100>)<EOL>height = title_height<EOL>title_lines, font_height = cover_image.text(title, x, y, width, height, fill, title_font)<EOL>if subtitle:<EOL><INDENT>y = min(<EOL>y + font_height * title_lines * cover_height,<EOL>title_height - subtitle_font_properties[<NUM_LIT:0>]<EOL>)<EOL>cover_image.text(subtitle, x, y, width, height, fill, subtitle_font)<EOL><DEDENT>author_font_size = cover_width * <NUM_LIT><EOL>author_font_properties = (<EOL>author_font_size,<EOL>cairo.FONT_SLANT_NORMAL,<EOL>cairo.FONT_WEIGHT_NORMAL<EOL>)<EOL>author_font = cover_image.font(select_font(author), author_font_properties)<EOL>author_height = (cover_height - cover_width - (cover_height * cover_margin / <NUM_LIT:100>)) * <NUM_LIT><EOL>x = cover_height * cover_margin / <NUM_LIT:100><EOL>y = title_height<EOL>width = cover_width - (<NUM_LIT:2> * cover_height * cover_margin / <NUM_LIT:100>)<EOL>height = author_height<EOL>cover_image.text(author, x, y, width, height, fill, author_font)<EOL><DEDENT>cover_margin = <NUM_LIT:2><EOL>cover_image = Image(cover_width, cover_height)<EOL>shape_color, base_color = processColors()<EOL>drawBackground()<EOL>drawArtwork()<EOL>drawText()<EOL>return cover_image<EOL>
Main drawing function, which generates a cover of the given dimension and
renders title, author, and graphics.