def shade(self, stroke): delta_t = self.thickness_max - self.thickness_min fac = pow(self.k2 - self.k1, -1) for svert in stroke: curvatures = svert.first_svertex.curvatures c1 = abs(curvatures[4]) if curvatures is not None else None curvatures = svert.second_svertex.curvatures c2 = abs(curvatures[4]) if curvatures is not None else None if (c1 or c2) is None: svert.attribute.thickness = (0.0, 0.0) continue if None not in {c1, c2}: Kr = c1 + svert.t2d * (c2 - c1) else: Kr = c1 if c1 is not None else c2 if self.thickness_min <= Kr <= self.thickness_max: self.thickness_min + delta_t * (Kr - self.k1) * fac else: bound(self.thickness_min, Kr, self.thickness_max) svert.attribute.thickness = (Kr / 2, Kr / 2)
def curvature(self, stroke): for K in stroke_curvature(iter(stroke)): K = bound(-5, x, 5) / 3 t = (1.0 - K) * self.thickness.min + K * self.thickness.max t = 0.0 if t < 1e-6 else t if t < 1: t /= 10 yield round(1.0 - t, 5)
def shade(self, stroke): it = Interface0DIterator(stroke) delta_threshold = self.threshold_max - self.threshold_min delta_thickness = self._thicknessMax - self._thicknessMin for svert in it: c = self._func(it) c = bound(self.threshold_min, c, self.threshold_max) t = (self.threshold_max - c) / delta_threshold * delta_thickness + self._thicknessMin svert.attribute.thickness = (t / 2.0, t / 2.0)
def __call__(self, i1, i2): sv1a = i1.first_fedge.first_svertex.point_2d sv1b = i1.last_fedge.second_svertex.point_2d sv2a = i2.first_fedge.first_svertex.point_2d sv2b = i2.last_fedge.second_svertex.point_2d if (sv1a - sv2a).length < 1e-6: dir1 = sv1a - sv1b dir2 = sv2b - sv2a elif (sv1b - sv2b).length < 1e-6: dir1 = sv1b - sv1a dir2 = sv2a - sv2b elif (sv1a - sv2b).length < 1e-6: dir1 = sv1a - sv1b dir2 = sv2a - sv2b elif (sv1b - sv2a).length < 1e-6: dir1 = sv1b - sv1a dir2 = sv2b - sv2a else: return False denom = dir1.length * dir2.length if denom < 1e-6: return False x = (dir1 * dir2) / denom return acos(bound(-1.0, x, 1.0)) > self.angle
def shade(self, stroke): for svert in stroke: alpha = svert.attribute.alpha alpha = bound(self.__min, alpha * svert.point.y * 0.0025, self.__max) svert.attribute.alpha = alpha