def update(self, params): self.set_background_color(params["Background Color"]) self.path1 = pyribbed.Polyline() self.path2 = pyribbed.Polyline() twists = params["Twists"] offset = params["Twist Offset"] baseRadius = params["Base Radius"] apexRadius = params["Apex Radius"] segments = 1000 for i in xrange(segments + 1): t = float(i) / segments radius = (self.ellipse_pos(1, apexRadius - baseRadius, t)[1] + baseRadius) angle = 2 * pi * t * twists + offset pos = self.ellipse_pos(params["Width"], params["Height"], t) dir = self.ellipse_norm(params["Width"], params["Height"], t) p1 = cos(angle) * dir + Vector(0, 0, sin(angle)) p2 = cos(angle + pi) * dir + Vector(0, 0, sin(angle + pi)) p1 *= radius p2 *= radius p1 += pos p2 += pos self.path1.push_back(p1) self.path2.push_back(p2) # Sweep radii ribRad = params["Rib Radius"] self.ribCross = self.circle(Vector(0, 0, 0), Vector(ribRad, 0, 0), Vector(0, ribRad, 0), 0.0, 2.0 * math.pi, 8) railRad = params["Rail Radius"] self.railCross = self.circle(Vector(0, 0, 0), Vector(railRad, 0, 0), Vector(0, railRad, 0), 0.0, 2.0 * math.pi, 8) self.rail1 = sweep(self.railCross, self.path1) self.rail2 = sweep(self.railCross, self.path2) bend = params["Rib Bend"] def ribParams(end0, frenet0, end1, frenet1, t): mag = 2.0 * t - 1.0 return (end0 + mag * bend * (frenet0.binormal), end1 + mag * bend * (frenet1.binormal)) numRibs = params["Num. Ribs"] self.ribsRails = pyribbed.hermite_ribbed_surface( self.path1, (0.02, 0.98), self.path2, (0.02, 0.98), ribParams, numRibs, self.ribCross) for rib in self.ribsRails: self.instance(rib) self.instance(self.rail1) self.instance(self.rail2) self.light(Vector(50, 50, 50), Vector(1, 1, 1), 1) self.light(Vector(-50, -50, -50), Vector(0.4, 0.1, 1), 0.1)
def circle(self, center, xVec, yVec, startAngle, endAngle, samples): sc = pyribbed.Polyline() for i in xrange(samples): t = float(i) / float(samples - 1) angle = t * (endAngle - startAngle) + startAngle sample = math.cos(angle) * xVec + math.sin(angle) * yVec sc.push_back(center + sample) return sc