Esempio n. 1
0
    def shade(self, stroke):
        # determine the pivot of scaling and rotation operations
        if self.pivot == 'START':
            pivot = stroke[0].point
        elif self.pivot == 'END':
            pivot = stroke[-1].point
        elif self.pivot == 'CENTER':
            # minor rounding errors here, because
            # given v = Vector(a, b), then (v / n) != Vector(v.x / n, v.y / n)
            pivot = (1 / len(stroke)) * sum((svert.point for svert in stroke), Vector((0.0, 0.0)))
        elif self.pivot == 'ABSOLUTE':
            pivot = Vector((self.pivot_x, self.pivot_y))
        elif self.pivot == 'PARAM':
            if self.pivot_u < stroke[0].u:
                pivot = stroke[0].point
            else:
                for prev, svert in pairwise(stroke):
                    if self.pivot_u < svert.u:
                        break
                pivot = svert.point + (svert.u - self.pivot_u) * (prev.point - svert.point)

        # apply scaling and rotation operations
        for svert in stroke:
            p = (svert.point - pivot)
            x = p.x * self.scale.x
            y = p.y * self.scale.y
            p.x = x * self.cos_theta - y * self.sin_theta
            p.y = x * self.sin_theta + y * self.cos_theta
            svert.point = p + pivot
        stroke.update_length()
Esempio n. 2
0
    def shade(self, stroke):
        # determine the pivot of scaling and rotation operations
        if self.pivot == 'START':
            pivot = stroke[0].point
        elif self.pivot == 'END':
            pivot = stroke[-1].point
        elif self.pivot == 'CENTER':
            # minor rounding errors here, because
            # given v = Vector(a, b), then (v / n) != Vector(v.x / n, v.y / n)
            pivot = (1 / len(stroke)) * sum(
                (svert.point for svert in stroke), Vector((0.0, 0.0)))
        elif self.pivot == 'ABSOLUTE':
            pivot = Vector((self.pivot_x, self.pivot_y))
        elif self.pivot == 'PARAM':
            if self.pivot_u < stroke[0].u:
                pivot = stroke[0].point
            else:
                for prev, svert in pairwise(stroke):
                    if self.pivot_u < svert.u:
                        break
                pivot = svert.point + (svert.u - self.pivot_u) * (prev.point -
                                                                  svert.point)

        # apply scaling and rotation operations
        for svert in stroke:
            p = (svert.point - pivot)
            x = p.x * self.scale.x
            y = p.y * self.scale.y
            p.x = x * self.cos_theta - y * self.sin_theta
            p.y = x * self.sin_theta + y * self.cos_theta
            svert.point = p + pivot
        stroke.update_length()
Esempio n. 3
0
def iter_stroke_vertices(stroke, epsilon=1e-6):
    yield stroke[0]
    for prev, svert in pairwise(stroke):
        if (prev.point - svert.point).length > epsilon:
            yield svert
Esempio n. 4
0
def iter_stroke_vertices(stroke, epsilon=1e-6):
    yield stroke[0]
    for prev, svert in pairwise(stroke):
        if (prev.point - svert.point).length > epsilon:
            yield svert