def addLeaves(path, n, offset, slideRatio, document): # Creates the Leaf Constructors points = dformer.generatePoints(path, slideRatio, 2 * n) pt_pairs = dformer.findPointPairs(points) p = cubicsuperpath.parsePath(path.get('d'))[0] i = 1 for a, b in pt_pairs: # Get center point of leaf slope = dformer.computeSlope(a, b) p_slope = dformer.perpendicularSlope(slope) tmp = offset * math.tan(math.radians(0)) dist = math.sqrt(tmp ** 2 + offset ** 2) ab_MidPoint = dformer.getMidPoint(a, b) c = dformer.computePointAlongLine(p_slope, ab_MidPoint, -dist) ctrl1 = dformer.computePointAlongLine(p_slope, a, -dist) ctrl2 = dformer.computePointAlongLine(p_slope, b, -dist) start_pt = p[i - 1][1] # Check that start_pt is viable while not(dformer.checkRelativeDifference(start_pt[0], a[0]) and dformer.checkRelativeDifference(start_pt[1], a[1])): i += 1 start_pt = p[i - 1][1] begin_idx = i end_pt = p[i][1] # Check that end_pt is viable while not(dformer.checkRelativeDifference(end_pt[0], b[0]) and dformer.checkRelativeDifference(end_pt[1], b[1])): i += 1 end_pt = p[i][1] end_idx = i before = p[:begin_idx] after = p[end_idx:] # Create Leaf before[-1][1] = list(a) leafMidPoint = dformer.getMidPoint(ab_MidPoint, ctrl1) leftSidePoint = dformer.computePointAlongLine(slope, leafMidPoint, -dist/2) before[-1][2] = list(leftSidePoint) curve_at_c = [list(ctrl1), list(c), list(ctrl2)] rightMidPoint = dformer.getMidPoint(ab_MidPoint, ctrl2) rightSidePoint = dformer.computePointAlongLine(dformer.negateSlope(slope), rightMidPoint, -dist/2) after[0][0] = list(rightSidePoint) after[0][1] = list(b) after[0][2] = after[1][0] p = before + [curve_at_c] + after path.set('d', cubicsuperpath.formatPath([p]))
def addNotches(path, n, offset, slideRatio, angle, document): # Creates the Notch Constructors points = dformer.generatePoints(path, slideRatio, 2 * n) pt_pairs = dformer.findPointPairs(points) p = cubicsuperpath.parsePath(path.get('d'))[0] i = 1 for a, b in pt_pairs: # Get center point of tooth slope = dformer.computeSlope(a, b) p_slope = dformer.perpendicularSlope(slope) ac_slope = dformer.rotateSlope(p_slope, 360 - angle) bd_slope = dformer.rotateSlope(p_slope, angle) tmp = offset * math.tan(math.radians(angle)) dist = math.sqrt(tmp ** 2 + offset ** 2) c = dformer.computePointAlongLine(ac_slope, a, -dist) d = dformer.computePointAlongLine(bd_slope, b, -dist) start_pt = p[i - 1][1] # Check that start_pt is viable while not(dformer.checkRelativeDifference(start_pt[0], a[0]) and dformer.checkRelativeDifference(start_pt[1], a[1])): i += 1 start_pt = p[i - 1][1] begin_idx = i end_pt = p[i][1] # Check that end_pt is viable while not(dformer.checkRelativeDifference(end_pt[0], b[0]) and dformer.checkRelativeDifference(end_pt[1], b[1])): i += 1 end_pt = p[i][1] end_idx = i before = p[:begin_idx] after = p[end_idx+1:] # Create Tooth before[-1][1] = list(a) before[-1][2] = list(a) line_to_c = [list(c)] * 3 line_to_d = [list(d)] * 3 line_to_b = [list(b)] * 3 p = before + [line_to_c] + [line_to_d] + [line_to_b] + after path.set('d', cubicsuperpath.formatPath([p]) + 'Z')
def addStitching(path, n, offset, slideRatio, diameter, document): # Creates the Stitch Constructors points = dformer.generatePoints(path, slideRatio, n) parsedPath = cubicsuperpath.parsePath(path.get('d'))[0] i = 1 for p in points: # Find the points and make Stiches start_pt = parsedPath[i - 1][1] while not(dformer.checkRelativeDifference(start_pt[0], p[0]) and dformer.checkRelativeDifference(start_pt[1], p[1])): i += 1 start_pt = parsedPath[i - 1][1] x, y = bezmisc.bezierslopeatt((parsedPath[i-1][0], parsedPath[i-1][1], parsedPath[i-1][2], parsedPath[i][0]), 0) pSlope = dformer.perpendicularSlope((x, y)) index = points.index(p) newPoint = dformer.computePointAlongLine(pSlope, p, offset) if index < len(points) - 1: dformer.drawCircle(newPoint, diameter/2, document)