コード例 #1
0
    def draw(self):
        s = self.size  # abbreviate as we will use this a lot
        g = shapes.Group()
        g.transform = [1, 0, 0, 1, self.x, self.y]

        # background
        g.add(
            shapes.Circle(s * 0.5, s * 0.5, s * 0.5, fillColor=self.skinColor))

        # left eye
        g.add(
            shapes.Circle(s * 0.35, s * 0.65, s * 0.1, fillColor=colors.white))
        g.add(
            shapes.Circle(s * 0.35,
                          s * 0.65,
                          s * 0.05,
                          fillColor=self.eyeColor))

        # right eye
        g.add(
            shapes.Circle(s * 0.65, s * 0.65, s * 0.1, fillColor=colors.white))
        g.add(
            shapes.Circle(s * 0.65,
                          s * 0.65,
                          s * 0.05,
                          fillColor=self.eyeColor))

        # nose
        g.add(
            shapes.Polygon(
                points=[s * 0.5, s * 0.6, s * 0.4, s * 0.3, s * 0.6, s * 0.3],
                fillColor=None))

        # mouth
        if self.mood == 'happy':
            offset = -0.05
        elif self.mood == 'sad':
            offset = +0.05
        else:
            offset = 0

        g.add(
            shapes.Polygon(
                points=[
                    s * 0.3,
                    s * 0.2,  #left of mouth
                    s * 0.7,
                    s * 0.2,  #right of mouth
                    s * 0.6,
                    s * (0.2 + offset),  # the bit going up or down
                    s * 0.4,
                    s * (0.2 + offset)  # the bit going up or down
                ],
                fillColor=colors.pink,
                strokeColor=colors.red,
                strokeWidth=s * 0.03))

        return g
コード例 #2
0
ファイル: Glyphs.py プロジェクト: PapenfussLab/Mungo
 def draw(self):
     # general widget bits
     w = float(self.length)
     h = float(self.height)
     # print self.label,w,h
     
     # Set minimum size
     if abs(w)<self.wmin:
         xmid = self.x+0.5*w
         w = w/abs(w) * self.wmin
         self.x = xmid-0.5*w
     
     g = shapes.Group()
     if abs(w)>self.wNoTail:
         # arrow specific bits
         body = shapes.Rect(x=self.x, y=self.y-self.aspectRatio*h/2,
             width=2*(w/3),
             height=self.aspectRatio*h,
             fillColor=self.fillColor,
             strokeColor=self.strokeColor,
             strokeWidth=self.strokeWidth)
         g.add(body)
         
         head = shapes.Polygon(
             points=[self.x+w, self.y,
                 self.x+2*(w/3), self.y+h/2,
                 self.x+2*(w/3), self.y-h/2,
                 self.x+w, self.y],
             fillColor=self.fillColor,
             strokeColor=self.strokeColor,
             strokeWidth=self.strokeWidth)
         g.add(head)
     else:
         head = shapes.Polygon(
             points=[self.x+w, self.y,
                 self.x, self.y+h/2,
                 self.x, self.y-h/2,
                 self.x+w, self.y],
             fillColor=self.fillColor,
             strokeColor=self.strokeColor,
             strokeWidth=self.strokeWidth)
         g.add(head)
     
     if self.label:
         b = g.getBounds()
         s = Label()
         s.setText(self.label)
         s.setOrigin(self.x+0.5*w+self.labeldx, self.y-h/2+b[3]-b[1]+self.labeldy)
         s.boxAnchor = self.boxAnchor
         s.textAnchor = self.textAnchor
         s.fontName = 'Helvetica'
         s.fontSize = self.fontSize
         s.angle = self.labelAngle
         g.add(s)
     
     return g
コード例 #3
0
    def draw(self):
        # general widget bits
        s = float(self.size)  # abbreviate as we will use this a lot
        g = shapes.Group()
        ew = self.strokeWidth
        ae = s * 0.125  #(ae = 'an eighth')

        # danger sign specific bits

        ew = self.strokeWidth
        ae = s * 0.125  #(ae = 'an eighth')

        outerTriangle = shapes.Polygon(points=[
            self.x, self.y, self.x + s, self.y, self.x + (s / 2), self.y + s
        ],
                                       fillColor=None,
                                       strokeColor=self.strokeColor,
                                       strokeWidth=0)
        g.add(outerTriangle)

        innerTriangle = shapes.Polygon(points=[
            self.x + (s / 50), self.y + (s / 75), (self.x + s) - (s / 50),
            self.y + (s / 75), self.x + (s / 2), (self.y + s) - (s / 50)
        ],
                                       fillColor=self.fillColor,
                                       strokeColor=None,
                                       strokeWidth=0)
        g.add(innerTriangle)

        exmark = shapes.Polygon(points=[
            ((self.x + s / 2) - ew / 2), self.y + ae * 2.5,
            ((self.x + s / 2) + ew / 2), self.y + ae * 2.5,
            ((self.x + s / 2) + ((ew / 2)) + (ew / 6)), self.y + ae * 5.5,
            ((self.x + s / 2) - ((ew / 2)) - (ew / 6)), self.y + ae * 5.5
        ],
                                fillColor=self.strokeColor,
                                strokeColor=None)
        g.add(exmark)

        exdot = shapes.Polygon(points=[
            ((self.x + s / 2) - ew / 2), self.y + ae,
            ((self.x + s / 2) + ew / 2), self.y + ae,
            ((self.x + s / 2) + ew / 2), self.y + ae * 2,
            ((self.x + s / 2) - ew / 2), self.y + ae * 2
        ],
                               fillColor=self.strokeColor,
                               strokeColor=None)
        g.add(exdot)

        return g
コード例 #4
0
    def testPolygon(self):
        points = [0, 0, 10, 30, 25, 15]
        s = shapes.Polygon(points)
        assert s.getBounds() == (0, 0, 25, 30)

        s = shapes.PolyLine(points)
        assert s.getBounds() == (0, 0, 25, 30)
コード例 #5
0
  def drawPolygon(self, pointlist, edgeColor=None, edgeWidth=None, fillColor=transparent, closed=0,
                  dash=None, **kwargs):
    """drawPolygon(pointlist) -- draws a polygon
    pointlist: a list of (x,y) tuples defining vertices
    """
    if not edgeColor:
      edgeColor = self.defaultLineColor

    edgeColor = colorToRL(edgeColor)
    if not fillColor or fillColor == transparent:
      fillColor = None
    else:
      fillColor = colorToRL(fillColor)

    if edgeWidth:
      w = edgeWidth
    else:
      w = self.defaultLineWidth

    points = []
    for x, y in pointlist:
      points.append(x)
      points.append(self.fixY(y))
    self.drawing.add(
      shapes.Polygon(points, strokeColor=edgeColor, strokeWidth=w, strokeDashArray=dash,
                     fillColor=fillColor))
コード例 #6
0
    def draw(self):
        # general widget bits
        s = float(self.size)  # abbreviate as we will use this a lot
        g = shapes.Group()

        # arrow specific bits
        body = shapes.Rect(x=self.x,
                           y=(self.y + (s / 2)) - (s / 24),
                           width=9 * (s / 10),
                           height=(s / 12),
                           fillColor=self.fillColor,
                           strokeColor=None,
                           strokeWidth=0)
        g.add(body)

        head = shapes.Polygon(points=[
            self.x + (2.5 * (s / 3)), (self.y + (s / 2)),
            self.x + (4 * (s / 6)), self.y + 4 * (s / 6), self.x + s,
            self.y + (s / 2), self.x + (4 * (s / 6)), self.y + 2 * (s / 6)
        ],
                              fillColor=self.fillColor,
                              strokeColor=None,
                              strokeWidth=0)
        g.add(head)

        return g
コード例 #7
0
ファイル: Glyphs.py プロジェクト: PapenfussLab/Mungo
 def draw(self):
     # general widget bits
     w = float(self.length)
     h = float(self.height)
     g = shapes.Group()
     
     body = shapes.Polygon(
         [self.x-0.5*w, self.y-0.5*w,
          self.x-0.5*w, self.y+0.5*w,
          self.x+0.5*w, self.y],
         fillColor=self.fillColor,
         strokeColor=self.strokeColor,
         strokeWidth=self.strokeWidth)
     g.add(body)
     
     if self.label:
         b = g.getBounds()
         s = Label()
         s.setText(self.label)
         s.setOrigin(self.x+0.5*w, self.y-h/2+b[3]-b[1]+4)
         s.boxAnchor = self.boxAnchor
         s.textAnchor = self.textAnchor
         s.fontName = 'Helvetica'
         s.fontSize = self.fontSize
         s.angle = self.labelAngle
         g.add(s)
     
     return g
コード例 #8
0
    def draw(self):
        # general widget bits
        s = float(self.size)  # abbreviate as we will use this a lot
        g = shapes.Group()

        # arrow specific bits
        x = self.x
        y = self.y
        s2 = s / 2
        s3 = s / 3
        s5 = s / 5
        s24 = s / 24

        g.add(
            shapes.Polygon(points=[
                x,
                y + 11 * s24,
                x,
                y + 13 * s24,
                x + 18.75 * s24,
                y + 13 * s24,
                x + 2 * s3,
                y + 2 * s3,
                x + s,
                y + s2,
                x + 2 * s3,
                y + s3,
                x + 18.75 * s24,
                y + 11 * s24,
            ],
                           fillColor=self.fillColor,
                           strokeColor=self.strokeColor,
                           strokeWidth=self.strokeWidth))

        return g
コード例 #9
0
    def draw(self):
        # general widget bits
        s = float(self.size)  # abbreviate as we will use this a lot
        g = shapes.Group()

        x = self.x
        y = self.y
        s2 = s / 2
        s3 = s / 3
        s5 = s / 5
        g.add(
            shapes.Polygon(
                points=[
                    x,
                    y + s3,
                    x,
                    y + 2 * s3,
                    x + s2,
                    y + 2 * s3,
                    x + s2,
                    y + 4 * s5,
                    x + s,
                    y + s2,
                    x + s2,
                    y + s5,
                    x + s2,
                    y + s3,
                ],
                fillColor=self.fillColor,
                strokeColor=self.strokeColor,
                strokeWidth=self.strokeWidth,
            ))
        return g
コード例 #10
0
    def draw(self):
        # general widget bits
        s = float(self.size)  # abbreviate as we will use this a lot
        g = shapes.Group()

        # stop-sign specific bits
        athird = s / 3

        outerOctagon = shapes.Polygon(points=[
            self.x + athird, self.y, self.x, self.y + athird, self.x,
            self.y + (athird * 2), self.x + athird, self.y + s,
            self.x + (athird * 2), self.y + s, self.x + s,
            self.y + (athird * 2), self.x + s, self.y + athird,
            self.x + (athird * 2), self.y
        ],
                                      strokeColor=self.strokeColor,
                                      fillColor=None,
                                      strokeWidth=1)
        g.add(outerOctagon)

        innerOctagon = shapes.Polygon(points=[
            self.x + athird + (s / 75), self.y + (s / 75), self.x + (s / 75),
            self.y + athird + (s / 75), self.x + (s / 75),
            self.y + (athird * 2) - (s / 75), self.x + athird + (s / 75),
            self.y + s - (s / 75), self.x + (athird * 2) - (s / 75),
            (self.y + s) - (s / 75),
            (self.x + s) - (s / 75), self.y + (athird * 2) - (s / 75),
            (self.x + s) - (s / 75), self.y + athird + (s / 75),
            self.x + (athird * 2) - (s / 75), self.y + (s / 75)
        ],
                                      strokeColor=None,
                                      fillColor=self.fillColor,
                                      strokeWidth=0)
        g.add(innerOctagon)

        if self.stopColor:
            g.add(
                shapes.String(self.x + (s * 0.5),
                              self.y + (s * 0.4),
                              'STOP',
                              fillColor=self.stopColor,
                              textAnchor='middle',
                              fontSize=s / 3,
                              fontName="Helvetica-Bold"))

        return g
コード例 #11
0
    def draw(self):
        # general widget bits
        s = float(self.size)  # abbreviate as we will use this a lot
        g = shapes.Group()

        # Triangle specific bits
        ae = s * 0.125  #(ae = 'an eighth')
        triangle = shapes.Polygon(
            points=[self.x, self.y, self.x + s, self.y, self.x, self.y + s],
            fillColor=self.fillColor,
            strokeColor=self.strokeColor,
            strokeWidth=s / 50.)
        g.add(triangle)
        return g
コード例 #12
0
    def draw(self):
        # general widget bits
        s = float(self.size)  # abbreviate as we will use this a lot
        g = shapes.Group()

        # Octagon specific bits
        athird = s / 3

        octagon = shapes.Polygon(points=[
            self.x + athird, self.y, self.x, self.y + athird, self.x,
            self.y + (athird * 2), self.x + athird, self.y + s,
            self.x + (athird * 2), self.y + s, self.x + s,
            self.y + (athird * 2), self.x + s, self.y + athird,
            self.x + (athird * 2), self.y
        ],
                                 strokeColor=self.strokeColor,
                                 fillColor=self.fillColor,
                                 strokeWidth=10)
        g.add(octagon)
        return g
コード例 #13
0
ファイル: Glyphs.py プロジェクト: PapenfussLab/Mungo
 def draw(self):
     # general widget bits
     w = float(self.length)
     h = float(self.height)
     
     g = shapes.Group()
     block = shapes.Rect(x=self.x, y=self.y-h/2,
         width=self.length, height=h, fillColor=self.fillColor,
         strokeColor=self.strokeColor, strokeWidth=self.strokeWidth)
     g.add(block)
     
     point = shapes.Polygon(
         points=[self.x+w, self.y-h/2,
             self.x+w+signum(w)*h/4, self.y,
             self.x+w, self.y+h/2,
             self.x+w, self.y-h/2],
         fillColor=self.fillColor,
         strokeColor=self.strokeColor,
         strokeWidth=self.strokeWidth)
     g.add(point)
     return g