コード例 #1
0
ファイル: draw.py プロジェクト: tolcreator/uwputils
def drawTradeRoute(draw, route, hexSize, scheme):
    colour = traderoute.getColourForBtn(int(route['btn']))
    size = traderoute.getSizeForBtn(int(route['btn']))

    for i in range(0, len(route['nodes']) - 1):
        source = sector.getCoordsFromHex(route['nodes'][i])
        dest = sector.getCoordsFromHex(route['nodes'][i + 1])
        s = hexutils.getCenter(
            hexutils.getPosition(source[0] - 1, source[1] - 1, hexSize),
            hexSize)
        d = hexutils.getCenter(
            hexutils.getPosition(dest[0] - 1, dest[1] - 1, hexSize), hexSize)
        draw.line([s, d], fill=colour, width=size)
コード例 #2
0
ファイル: draw.py プロジェクト: tolcreator/uwputils
def drawTraffic(input, output, hexSize=256, scheme=DRAFT_SCHEME):
    routes = traderoute.readFromFile(input)
    traffic = traderoute.getTrafficFromRoutes(routes)
    draw, img = hexgrid.getSectorCanvas(hexSize)
    for node, btn in traffic.items():
        colour = traderoute.getColourForBtn(int(btn))
        size = traderoute.getSizeForBtn(int(btn))
        s = hexutils.getCenter(
            hexutils.getPosition(node[0][0] - 1, node[0][1] - 1, hexSize),
            hexSize)
        d = hexutils.getCenter(
            hexutils.getPosition(node[1][0] - 1, node[1][1] - 1, hexSize),
            hexSize)
        draw.line([s, d], fill=colour, width=size)
    img.save(output)
コード例 #3
0
ファイル: draw.py プロジェクト: tolcreator/uwputils
def drawDot(draw, origin, s, hexSize, scheme):
    # Draw Dot
    coords = hexutils.getCenter(origin, hexSize)
    offset = int(hexSize / 10)
    box = [
        coords[0] - offset, coords[1] - offset, coords[0] + offset,
        coords[1] + offset
    ]
    if s['Size'] in ['0']:
        dotScheme = scheme['worlds']['asteroid']
    elif s['Hydrosphere'] in ['0']:
        if s['Atmosphere'] in ['0']:
            dotScheme = scheme['worlds']['vacuum']
        else:
            dotScheme = scheme['worlds']['desert']
    elif s['Atmosphere'] in ['5', '6', '8']:
        if s['Hydrosphere'] in ['A']:
            dotScheme = scheme['worlds']['ocean']
        else:
            dotScheme = scheme['worlds']['garden']
    elif s['Atmosphere'] in ['0', '1']:
        dotScheme = scheme['worlds']['ice']
    elif s['Atmosphere'] in ['2', '3', '4', '7', '9']:
        dotScheme = scheme['worlds']['water']
    else:
        dotScheme = scheme['worlds']['fluidocean']
    draw.ellipse(box,
                 fill=dotScheme['fill'],
                 outline=dotScheme['outline'],
                 width=2)
コード例 #4
0
ファイル: draw.py プロジェクト: tolcreator/uwputils
def drawSystemEconomics(draw, origin, wtn, hexSize, colour):
    coords = hexutils.getCenter(origin, hexSize)
    # WTN is a whole non negative integer.
    circleTable = [
        0,
        0.09375,
        0.0625,
        0.1875,
        0.125,
        0.25,
        0.375,
        0.5,
        0.75,
        1,
        1.5,
        2,
        # Anything beyond here is probably impossible.
        3,
        4,
        6,
        8,
        12,
        16
    ]
    radius = int(hexSize * circleTable[wtn])
    box = [(coords[0] - radius, coords[1] - radius),
           (coords[0] + radius, coords[1] + radius)]
    draw.ellipse(box, fill=colour, outline="#ffffff", width=int(radius / 10))
コード例 #5
0
ファイル: draw.py プロジェクト: tolcreator/uwputils
def drawNavalBase(draw, origin, hexSize, scheme):
    coords = hexutils.getCenter(origin, hexSize)
    xoff = hexutils.widthBlock(hexSize)
    yoff = int(hexutils.heightBlock(hexSize) / 2)
    coords = (coords[0] - xoff, coords[1] - yoff)
    height = hexSize / 12
    pentagon = []
    for n in range(0, 5):
        x = height * math.cos(math.radians(270 + n * 72))
        y = height * math.sin(math.radians(270 + n * 72))
        pentagon.append((int(x), int(y)))
    vertices = [
        coords[0] + pentagon[0][0],
        coords[1] + pentagon[0][1],
        coords[0] + pentagon[2][0],
        coords[1] + pentagon[2][1],
        coords[0] + pentagon[4][0],
        coords[1] + pentagon[4][1],
        coords[0] + pentagon[1][0],
        coords[1] + pentagon[1][1],
        coords[0] + pentagon[3][0],
        coords[1] + pentagon[3][1],
        coords[0] + pentagon[0][0],
        coords[1] + pentagon[0][1],
    ]
    draw.polygon(vertices, fill=scheme['base']['colour'])
    height = int(height / 4) + 1
    box = [(coords[0] - height, coords[1] - height),
           (coords[0] + height, coords[1] + height)]
    draw.ellipse(box, fill=scheme['base']['colour'])
コード例 #6
0
ファイル: draw.py プロジェクト: tolcreator/uwputils
def drawSystemDemographics(draw, origin, system, hexSize, colour):
    coords = hexutils.getCenter(origin, hexSize)
    s = uwp.strToUwp(system['uwpString'])
    circleTable = {
        '0': {
            'base': 0,
            'max': 0
        },
        '1': {
            'base': 0.015125,
            'max': 0.03125
        },
        '2': {
            'base': 0.03125,
            'max': 0.0625
        },
        '3': {
            'base': 0.0625,
            'max': 0.125
        },
        '4': {
            'base': 0.125,
            'max': 0.25
        },
        '5': {
            'base': 0.25,
            'max': 0.5
        },
        '6': {
            'base': 0.5,
            'max': 1
        },
        '7': {
            'base': 1,
            'max': 2
        },
        '8': {
            'base': 2,
            'max': 4
        },
        '9': {
            'base': 4,
            'max': 8
        },
        'A': {
            'base': 8,
            'max': 16
        },
    }
    base = int(hexSize * circleTable[s['Population']]['base'])
    if system['p'] in ['1', '2', '3', '4', '5', '6', '7', '8', '9']:
        max = int(hexSize * circleTable[s['Population']]['max'])
        range = max - base
        mod = int(int(system['p']) * range / 10)
    else:
        mod = 0
    radius = int((base + mod) / 2)
    box = [(coords[0] - radius, coords[1] - radius),
           (coords[0] + radius, coords[1] + radius)]
    draw.ellipse(box, fill=colour, outline='#ffffff', width=int(radius / 10))
コード例 #7
0
ファイル: draw.py プロジェクト: tolcreator/uwputils
def drawScoutBase(draw, origin, hexSize, scheme):
    coords = hexutils.getCenter(origin, hexSize)
    xoff = hexutils.widthBlock(hexSize)
    coords = (coords[0] - xoff, coords[1])
    height = hexSize / 12
    xoff = int(height / math.sqrt(3))
    yoff = int(height)
    vertices = [(coords[0], coords[1]), (coords[0] - xoff, coords[1] + yoff),
                (coords[0] + xoff, coords[1] + yoff), (coords[0], coords[1])]
    draw.polygon(vertices, fill=scheme['base']['colour'])
コード例 #8
0
ファイル: draw.py プロジェクト: tolcreator/uwputils
def drawGasGiant(draw, origin, giant, hexSize, scheme):
    if giant not in ['0', ' ']:
        coords = hexutils.getCenter(origin, hexSize)
        xoff = hexutils.widthBlock(hexSize)
        yoff = int(hexutils.heightBlock(hexSize) / 2)
        coords = (coords[0] + xoff, coords[1] - yoff)
        offset = int(hexSize / 25)
        box = [(coords[0] - offset, coords[1] - offset),
               (coords[0] + offset, coords[1] + offset)]
        draw.ellipse(box, fill=scheme['gasgiant']['colour'])
コード例 #9
0
ファイル: draw.py プロジェクト: tolcreator/uwputils
def drawUwp(draw, origin, uwpString, hexSize, scheme):
    coords = hexutils.getCenter(origin, hexSize)
    typeface = scheme['uwp']['font']
    fontsize = scheme['uwp']['size']
    fnt = ImageFont.truetype(typeface, size=int(hexSize / fontsize))
    size = fnt.getsize(uwpString)
    xoff = int(size[0] / 2)
    yoff = int(hexSize / 7)
    coords = (coords[0] - xoff, coords[1] + yoff)
    draw.text(coords, uwpString, font=fnt, fill=scheme['uwp']['colour'])
コード例 #10
0
ファイル: draw.py プロジェクト: tolcreator/uwputils
def drawStarport(draw, origin, starport, hexSize, scheme):
    coords = hexutils.getCenter(origin, hexSize)
    typeface = scheme['starport']['font']
    fontsize = scheme['starport']['size']
    fnt = ImageFont.truetype(typeface, size=int(hexSize / fontsize))
    size = fnt.getsize(starport)
    xoff = int(size[0] / 2)
    yoff = size[1] + int(hexSize / 7)
    coords = (coords[0] - xoff, coords[1] - yoff)
    draw.text(coords, starport, font=fnt, fill=scheme['starport']['colour'])
コード例 #11
0
ファイル: draw.py プロジェクト: tolcreator/uwputils
def drawName(draw, origin, name, population, hexSize, scheme):
    coords = hexutils.getCenter(origin, hexSize)
    underline = False
    if population in ['9', 'A']:
        typeface = scheme['name']['hipop']['font']
        fontsize = scheme['name']['hipop']['size']
        output = name.upper()
        underline = True
    else:
        typeface = scheme['name']['regular']['font']
        fontsize = scheme['name']['regular']['size']
        output = name
    fnt = ImageFont.truetype(typeface, size=int(hexSize / fontsize))
    size = fnt.getsize(output)
    xoff = int(size[0] / 2)
    yoff = int(2 * hexSize / 7)
    coords = (coords[0] - xoff, coords[1] + yoff)
    draw.text(coords, output, font=fnt, fill=scheme['name']['colour'])
    if underline:
        line = [(coords[0], coords[1] + size[1] + int(hexSize / 100)),
                (coords[0] + size[0], coords[1] + size[1] + int(hexSize / 100))
                ]
        draw.line(line, fill=scheme['name']['colour'], width=int(hexSize / 50))