Esempio n. 1
0
    def draw(self):
        # general widget bits
        s = float(self.size)  # abbreviate as we will use this a lot
        g = shapes.Group()

        # SmileyFace specific bits
        g.add(
            shapes.Circle(cx=self.x + (s / 2),
                          cy=self.y + (s / 2),
                          r=s / 2,
                          fillColor=self.fillColor,
                          strokeColor=self.strokeColor,
                          strokeWidth=max(s / 38., self.strokeWidth)))

        for i in (1, 2):
            g.add(
                shapes.Ellipse(self.x + (s / 3) * i,
                               self.y + (s / 3) * 2,
                               s / 30,
                               s / 10,
                               fillColor=self.strokeColor,
                               strokeColor=self.strokeColor,
                               strokeWidth=max(s / 38., self.strokeWidth)))

        # calculate a pointslist for the mouth
        # THIS IS A HACK! - don't use if there is a 'shapes.Arc'
        centerx = self.x + (s / 2)
        centery = self.y + (s / 2)
        radius = s / 3
        yradius = radius
        xradius = radius
        startangledegrees = 200
        endangledegrees = 340
        degreedelta = 1
        pointslist = []
        a = pointslist.append
        from math import sin, cos, pi
        degreestoradians = pi / 180.0
        radiansdelta = degreedelta * degreestoradians
        startangle = startangledegrees * degreestoradians
        endangle = endangledegrees * degreestoradians
        while endangle < startangle:
            endangle = endangle + 2 * pi
        angle = startangle
        while angle < endangle:
            x = centerx + cos(angle) * radius
            y = centery + sin(angle) * yradius
            a(x)
            a(y)
            angle = angle + radiansdelta

        # make the mouth
        smile = shapes.PolyLine(pointslist,
                                fillColor=self.strokeColor,
                                strokeColor=self.strokeColor,
                                strokeWidth=max(s / 38., self.strokeWidth))
        g.add(smile)

        return g
Esempio n. 2
0
 def testEllipse(self):
     s = shapes.Ellipse(100, 50, 10, 5)
     assert s.getBounds() == (90, 45, 110, 55)