当前位置: 首页>>代码示例>>Python>>正文


Python Canvas.ellipse方法代码示例

本文整理汇总了Python中reportlab.pdfgen.canvas.Canvas.ellipse方法的典型用法代码示例。如果您正苦于以下问题:Python Canvas.ellipse方法的具体用法?Python Canvas.ellipse怎么用?Python Canvas.ellipse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在reportlab.pdfgen.canvas.Canvas的用法示例。


在下文中一共展示了Canvas.ellipse方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: SpiralTest

# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import ellipse [as 别名]
class SpiralTest(unittest.TestCase):
    """ Construct and draw image with ColorSpiral colours placed on the
        HSV spiral
    """
    def setUp(self):
        """ Set up canvas for drawing"""
        output_filename = os.path.join("Graphics", "spiral_test.pdf")
        self.c = Canvas(output_filename, pagesize=A4)
        # co-ordinates of the centre of the canvas
        self.x_0, self.y_0 = 0.5 * A4[0], 0.5 * A4[1]

    def test_colorlist(self):
        """ Get set of eight colours, no jitter, using ColorSpiral."""
        cs = ColorSpiral(a=4, b=0.33, jitter=0)
        colours = list(cs.get_colors(8))
        cstr = ["(%.2f, %.2f, %.2f)" % (r, g, b)
                for r, g, b in colours]
        expected = \
            ['(0.64, 0.74, 0.81)', '(0.68, 0.52, 0.76)', '(0.72, 0.41, 0.55)',
             '(0.68, 0.39, 0.31)', '(0.63, 0.54, 0.22)', '(0.48, 0.59, 0.13)',
             '(0.24, 0.54, 0.06)', '(0.01, 0.50, -0.00)']
        self.assertEqual(cstr, expected)

    def test_colorspiral(self):
        """ Get set of 16 colours, no jitter, using ColorSpiral."""
        cs = ColorSpiral(a=4, b=0.33, jitter=0)
        radius = A4[0] * 0.025
        for r, g, b in cs.get_colors(16):
            self.c.setFillColor((r, g, b))
            # Convert HSV colour to rectangular coordinates on HSV disc
            h, s, v = colorsys.rgb_to_hsv(r, g, b)
            coords = cmath.rect(s * A4[0] * 0.45, h * 2 * pi)
            x, y = self.x_0 + coords.real, self.y_0 + coords.imag
            self.c.ellipse(x - radius, y - radius, x + radius, y + radius,
                           stroke=0, fill=1)
        self.finish()

    def finish(self):
        """ Clean up and save image."""
        self.c.save()
开发者ID:widdowquinn,项目名称:ColorSpiral,代码行数:42,代码来源:test_ColorSpiral.py

示例2: oblique

# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import ellipse [as 别名]
can.line(1*cm, 1*cm, 20*cm, 1*cm)               # ligne horizontale en bas
can.line(1*cm, 28*cm, 20*cm, 1*cm)              # ligne oblique (descendante)
can.setLineWidth(3)                             # nouvelle épaisseur des lignes
can.setFillColorRGB(1,1,.5)                     # couleur de remplissage (RVB)
can.rect(2*cm, 2*cm, 18*cm, 20*cm, fill=1)      # rectangle de 18 x 20 cm

# Dessin d'un bitmap (aligné par son coin inférieur gauche). La méthode
# drawImage renvoie les dimensions du bitmap (en pixels) dans un tuple :
dX, dY =can.drawImage("cocci3.gif", 1*cm, 23*cm, mask="auto")
ratio =dY/dX                                    # rapport haut./larg. de l'image
can.drawImage("cocci3.gif", 1*cm, 14*cm,
              width=3*cm, height=3*cm*ratio, mask="auto")
can.drawImage("cocci3.gif", 1*cm, 7*cm, width=12*cm, height=5*cm, mask="auto")

can.setFillColorCMYK(.7,0,.5,0)                 # couleur de remplissage (CMJN)
can.ellipse(3*cm, 4*cm, 19*cm, 10*cm, fill=1)   # ellipse (! axes = 16 x 6 cm)
can.setLineWidth(1)                             # nouvelle épaisseur des lignes
can.ellipse(centreX -.5*cm, centreY -.5*cm,     # petit cercle indiquant la
            centreX +.5*cm, centreY +.5*cm)     # position du centre de la page

# Quelques textes, avec polices, orientation et alignement divers :
can.setFillColor("navy")                        # couleur des textes
texteC ="Petite pluie abat grand vent."         # texte à centrer
can.setFont("Times-Bold", 18)
can.drawCentredString(centreX, centreY, texteC)
texteG ="Qui ne risque rien, n'a rien."         # texte à aligner à gauche
can.setFont("Helvetica", 18)
can.drawString(centreX, centreY -1*cm, texteG)
texteD ="La nuit porte conseil."                # texte à aligner à droite
can.setFont("Courier", 18)
can.drawRightString(centreX, centreY -2*cm, texteD)
开发者ID:mseyne,项目名称:apprendre-python,代码行数:33,代码来源:imprimer_2.py

示例3: PDFGenerator

# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import ellipse [as 别名]

#.........这里部分代码省略.........
                    self.canvas.rect(
                            self.report.margin_left + graphic.left,
                            top_position - graphic.top - graphic.height,
                            graphic.width,
                            graphic.height,
                            graphic.stroke,
                            graphic.fill,
                            )
                elif isinstance(element, Line):
                    self.canvas.line(
                            self.report.margin_left + graphic.left,
                            top_position - graphic.top,
                            self.report.margin_left + graphic.right,
                            top_position - graphic.bottom,
                            )
                elif isinstance(element, Circle):
                    self.canvas.circle(
                            self.report.margin_left + graphic.left_center,
                            top_position - graphic.top_center,
                            graphic.radius,
                            graphic.stroke,
                            graphic.fill,
                            )
                elif isinstance(element, Arc):
                    self.canvas.arc(
                            self.report.margin_left + graphic.left,
                            top_position - graphic.top,
                            self.report.margin_left + graphic.right,
                            top_position - graphic.bottom,
                            graphic.start_angle,
                            graphic.extent,
                            )
                elif isinstance(element, Ellipse):
                    self.canvas.ellipse(
                            self.report.margin_left + graphic.left,
                            top_position - graphic.top,
                            self.report.margin_left + graphic.right,
                            top_position - graphic.bottom,
                            graphic.stroke,
                            graphic.fill,
                            )
                elif isinstance(element, Image):
                    self.canvas.drawInlineImage(
                            graphic.image,
                            self.report.margin_left + graphic.left,
                            top_position - graphic.top - graphic.height,
                            graphic.width,
                            graphic.height,
                            )

        # Band borders
        if band.borders.get('all', None):
            self.canvas.rect(
                    band_rect['left'],
                    band_rect['top'] - band.height,
                    band_rect['right'] - band_rect['left'],
                    band.height,
                    )

        if band.borders.get('top', None):
            self.canvas.line(band_rect['left'], band_rect['top'], band_rect['right'],
                    band_rect['top'])

        if band.borders.get('right', None):
            self.canvas.line(band_rect['right'], band_rect['top'], band_rect['right'],
                    band_rect['bottom'])
开发者ID:macndesign,项目名称:django-geraldo,代码行数:70,代码来源:pdf.py


注:本文中的reportlab.pdfgen.canvas.Canvas.ellipse方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。