コード例 #1
0
    def paint_text(self, parent_offset, surface):
        mid = len(self.line.current)/2
        midvalues = self.line.current[mid:mid+2]
        if len(midvalues) < 2:
            # not enough control points to figure out where to put text
            return
        midsrc, middst = midvalues
        angle = ((middst - midsrc).angle() % (2*math.pi))

        if 1*(2*math.pi)/4 < angle < 3*(2*math.pi)/4:
            angle += math.pi
            angle %= 2*math.pi

        t = self.rendered_text
        text_centering_vector = Point((-t.get_width()/2, -t.get_height()))
        text_centering_length = text_centering_vector.norm()
        text_centering_angle = text_centering_vector.angle()

        rt, coors = rotate_surface(t, angle)

        # coors[0] is where the original topleft is in the
        # rotated surface:
        topleft = coors[0]

        desired_topleft = midsrc + from_polar(text_centering_angle+angle,
                                              text_centering_length)
                
        pos = tuple(desired_topleft - topleft + parent_offset)
        surface.blit(rt, map(int, pos))
コード例 #2
0
ファイル: guilib.py プロジェクト: SapphireDensetsu/enough
def n_point_regular_polygon(n, radius, center, phase=0):
    twopi = 2*math.pi
    for i in xrange(n):
        angle = twopi/n*i + phase
        yield from_polar(angle, radius) + center