Ejemplo n.º 1
0
def hitlist(x0, y0, x1, y1):
    bb0 = bbox(x0, y0, x1, y1)
    hits = []
    for item in cvs:
        bb1 = item.bbox()
        if bb0.intersects(bb1):
            hits.append(item)
    return hits
Ejemplo n.º 2
0
 def save(self, name='test', legend=False):
     # Schrijf een PDF file weg
     self.generateRadarPlot()
     # Voeg legende toe
     if legend == True:
         self.addLegend()
     # Schrijf het weg naar een .svg bestand
     self.c.writePDFfile(os.path.join('export', name), page_bbox=bbox.bbox(-(self.r + 4) * self.s, -(self.r) * self.s, (self.r + 4) * self.s, (self.r + 2) * self.s))
def generate_tile(item):
    title = item['title']
    print(title)
    image = item['image']

    if item['quantity'] > 1:
        handle_multiple(item)
        return

    #72dpi is illustrator default
    drawing = svgfile.svgfile(0, 0, 'images%s' % image, parsed=True, resolution=72)
    setEtch(drawing.canvas)
    canvas_size = get_canvas_size(item)
    drawing_size = (drawing.bbox().width(), drawing.bbox().height())

    dir = 'tiles/%s' % item['type']
    if not os.path.exists(dir):
        os.makedirs(dir)
    c = canvas.canvas()

    center = ( (canvas_size[0] - drawing_size[0]) / 2, (canvas_size[1] - drawing_size[1]) / 2 )
    c.insert(drawing, [trafo.translate(center[0], center[1])])

    yMargin = (canvas_size[1] - drawing_size[1]) / 2
    yPos = yMargin - yMargin / 2
    baseline = text.parbox.middle
    textbox = '{\large %s}' % title
    if 'subtitle' in item:
        textbox += '\n\n'
        textbox += item['subtitle']

    if yPos < (unit.t_inch / 2):
        baseline = text.parbox.bottom

    c.text(canvas_size[0] / 2, yPos, textbox, [
            text.halign.boxcenter,
            text.halign.flushcenter,
            text.parbox(canvas_size[0] - .25 * unit.t_inch, baseline = baseline)
    ])

    #draw Cut line
    if CUT_LINE:
        c.stroke(
            path.rect(0, 0, canvas_size[0], canvas_size[1]),
            [ style.linewidth(0.001), color.rgb.red ]
        )

    p = document.page(c, bbox=bbox.bbox(0, 0, canvas_size[0], canvas_size[1]))
    d = document.document([p])
    d.writeSVGfile('%s/%s.svg' % (dir, slugify(title)))
Ejemplo n.º 4
0
    def clear(self):
        """
        Clears the grader, creating all new canvases for drawing.
        """
        from pyx import canvas
        from pyx import bbox
        from pyx import document
        from .window import Window

        self._canvas = canvas.canvas()
        bounds = bbox.bbox(self.x, self.y, self.width, self.height)
        self._page = document.page(self._canvas,
                                   paperformat=document.paperformat.Letter,
                                   bbox=bounds)
        self._submitted = Window()
        self._submitted.title = 'Student Submission'
        self._solution = Window()
        self._solution.title = 'Instructor Solution'
        self._comments = []
Ejemplo n.º 5
0
def pyxColor(string):
    """Return a pyxColor instance.

    :param string: RGB color name like 'ffffff'
    :return: pyx color.

    >>> assert pyxColor('ffffff')
    """
    assert len(string) == 6
    colorTuple = tuple(
        int('0x' + c, 16) for c in [string[i:i + 2] for i in range(0, 6, 2)])
    return color.rgb(*[i / 255.0 for i in colorTuple])


if __name__ == '__main__':  # pragma: no cover
    out = sys.argv[1]
    if not pyx:
        sys.exit(1)
    for icon in set(d['Color'] for d in reader('../cobl-data/cldf/languages.csv', dicts=True)):
        assert len(icon) == 6
        c = canvas.canvas()
        c.draw(
            path.circle(20, 20, 13.6),
            [deco.stroked([linewidth]), deco.filled([pyxColor(icon)])])
        stream = c.pipeGS("pngalpha", resolution=20, bbox=bbox.bbox(0, 0, 40, 40))
        with open(os.path.join(out, 'c{0}.png'.format(icon)), 'wb') as fp:
            fp.write(stream.read())
    sys.exit(0)

Ejemplo n.º 6
0
def pyxColor(string):
    """
    :param string: RGB color name like 'ffffff'
    :return: pyx color.

    >>> assert pyxColor('ffffff')
    """
    assert len(string) == 6
    colorTuple = tuple(
        int('0x' + c, 16) for c in [string[i:i + 2] for i in range(0, 6, 2)])
    return color.rgb(*[i / 255.0 for i in colorTuple])


if __name__ == '__main__':  # pragma: no cover
    if not pyx:
        sys.exit(1)
    asset_resolver = AssetResolver()
    for icon in ICONS:
        c = canvas.canvas()
        c.draw(shapes[icon.name[0]], [
            deco.stroked([linewidth]),
            deco.filled([pyxColor(icon.name[1:])])
        ])
        stream = c.pipeGS("pngalpha",
                          resolution=20,
                          bbox=bbox.bbox(0, 0, 40, 40))
        with open(asset_resolver.resolve(icon.asset_spec).abspath(),
                  'wb') as fp:
            fp.write(stream.read())
    sys.exit(0)
Ejemplo n.º 7
0
    "f": polygon((2, 36), (38, 36), (20, 5)),  # inverted pyramid
    "d": polygon((20, 2), (38, 20), (20, 38), (2, 20)),  # diamond
}


def pyxColor(string):
    """
    :param string: RGB color name like 'ffffff'
    :return: pyx color.

    >>> assert pyxColor('ffffff')
    """
    assert len(string) == 6
    colorTuple = tuple(int('0x' + c, 16) for c in [string[i:i+2] for i in range(0, 6, 2)])
    return color.rgb(*[i / 255.0 for i in colorTuple])


if __name__ == '__main__':  # pragma: no cover
    if not pyx:
        sys.exit(1)
    asset_resolver = AssetResolver()
    for icon in ICONS:
        c = canvas.canvas()
        c.draw(
            shapes[icon.name[0]],
            [deco.stroked([linewidth]), deco.filled([pyxColor(icon.name[1:])])])
        stream = c.pipeGS("pngalpha", resolution=20, bbox=bbox.bbox(0, 0, 40, 40))
        with open(asset_resolver.resolve(icon.asset_spec).abspath(), 'wb') as fp:
            fp.write(stream.read())
    sys.exit(0)