img/buildicons.py
author Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
Mon Dec 21 23:52:38 2009 +0000 (2009-12-21)
changeset 123 bc4c90cbd778
parent 33 b0d0c11fb746
permissions -rw-r--r--
For OS X
tonyg@33
     1
#!/usr/bin/env python
tonyg@33
     2
tonyg@33
     3
import cairo
tonyg@33
     4
import math
tonyg@33
     5
tonyg@33
     6
pi = math.pi
tonyg@33
     7
tonyg@33
     8
WIDTH = 20
tonyg@33
     9
MID = WIDTH / 2.0
tonyg@33
    10
BLOBRADIUS = WIDTH / 4.0
tonyg@33
    11
LINEWIDTH = WIDTH / 12.0
tonyg@33
    12
tonyg@40
    13
ENABLE_CROSSOVER = False
tonyg@40
    14
tonyg@33
    15
surface = None
tonyg@33
    16
ctx = None
tonyg@33
    17
tonyg@33
    18
def reset(n = None):
tonyg@33
    19
    global surface, ctx
tonyg@33
    20
    if n and surface:
tonyg@33
    21
        surface.write_to_png(n)
tonyg@33
    22
    surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, WIDTH, WIDTH)
tonyg@33
    23
    ctx = cairo.Context(surface)
tonyg@33
    24
    ctx.set_line_width(LINEWIDTH)
tonyg@33
    25
tonyg@33
    26
#     ctx.set_source_rgb(1,1,1)
tonyg@33
    27
#     ctx.paint()
tonyg@33
    28
#     ctx.set_source_rgb(0,0,0)
tonyg@33
    29
tonyg@33
    30
def m(n):
tonyg@33
    31
    ctx.move_to(MID, MID)
tonyg@33
    32
    if n & 1: ctx.line_to(MID, 0); ctx.stroke()
tonyg@33
    33
    ctx.move_to(MID, MID)
tonyg@33
    34
    if n & 2: ctx.line_to(0, MID); ctx.stroke()
tonyg@33
    35
    ctx.move_to(MID, MID)
tonyg@33
    36
    if n & 4: ctx.line_to(MID, WIDTH); ctx.stroke()
tonyg@33
    37
    ctx.move_to(MID, MID)
tonyg@33
    38
    if n & 8: ctx.line_to(WIDTH, MID); ctx.stroke()
tonyg@33
    39
tonyg@33
    40
    ctx.arc(MID, MID, BLOBRADIUS, 0, pi * 2)
tonyg@33
    41
    ctx.fill()
tonyg@33
    42
    ctx.set_source_rgb(1,1,1)
tonyg@33
    43
    ctx.arc(MID, MID, BLOBRADIUS - LINEWIDTH, 0, pi * 2)
tonyg@33
    44
    ctx.fill()
tonyg@33
    45
tonyg@33
    46
    reset("blob_%d.png" % n)
tonyg@33
    47
tonyg@33
    48
def k(n):
tonyg@33
    49
    if n & 1:
tonyg@33
    50
        ctx.move_to(MID, 0)
tonyg@40
    51
        if ENABLE_CROSSOVER and n & 2:
tonyg@33
    52
            ctx.line_to(MID, MID - BLOBRADIUS - LINEWIDTH / 4)
tonyg@33
    53
            ctx.stroke()
tonyg@33
    54
            ctx.move_to(MID, MID - LINEWIDTH / 4)
tonyg@33
    55
        ctx.line_to(MID, WIDTH)
tonyg@33
    56
        ctx.stroke()
tonyg@33
    57
    if n & 2:
tonyg@33
    58
        ctx.move_to(0, MID)
tonyg@40
    59
        if ENABLE_CROSSOVER and n & 1:
tonyg@33
    60
            ctx.line_to(MID - BLOBRADIUS + LINEWIDTH, MID)
tonyg@33
    61
            ctx.curve_to(MID - BLOBRADIUS + LINEWIDTH, MID - BLOBRADIUS,
tonyg@33
    62
                         MID + BLOBRADIUS - LINEWIDTH, MID - BLOBRADIUS,
tonyg@33
    63
                         MID + BLOBRADIUS - LINEWIDTH, MID)
tonyg@33
    64
        ctx.line_to(WIDTH, MID)
tonyg@33
    65
        ctx.stroke()
tonyg@33
    66
    if n & 4:
tonyg@33
    67
        ctx.arc(0, WIDTH, WIDTH/2, pi / 2, 0)
tonyg@33
    68
        ctx.stroke()
tonyg@33
    69
    if n & 8:
tonyg@33
    70
        ctx.arc(WIDTH, WIDTH, WIDTH/2, pi, 3 * pi / 2)
tonyg@33
    71
        ctx.stroke()
tonyg@33
    72
    reset("stick_%d.png" % n)
tonyg@33
    73
tonyg@33
    74
reset()
tonyg@33
    75
for n in range(16):
tonyg@33
    76
    m(n)
tonyg@33
    77
    k(n)
tonyg@33
    78
tonyg@33
    79
def topleft():
tonyg@33
    80
    ctx.move_to(MID, 0)
tonyg@33
    81
    ctx.line_to(0, MID)
tonyg@33
    82
    ctx.stroke()
tonyg@33
    83
def bottomright():
tonyg@33
    84
    ctx.move_to(WIDTH, MID)
tonyg@33
    85
    ctx.line_to(MID, WIDTH)
tonyg@33
    86
    ctx.stroke()
tonyg@33
    87
bottomright()
tonyg@33
    88
reset("slide_l.png")
tonyg@33
    89
topleft()
tonyg@33
    90
bottomright()
tonyg@33
    91
reset("slide_m.png")
tonyg@33
    92
topleft()
tonyg@33
    93
reset("slide_r.png")