How to use the paper.CompoundPath function in paper

To help you get started, we’ve selected a few paper examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ecomfe / fonteditor / demo / js / paper-boolean.js View on Github external
function contoursdivide(contours1, spliter, operation) {
    let path1 = new paper.CompoundPath(contours1);
    let path2 = new paper.Path({
        segments: [
            [spliter[0].x, spliter[0].y],
            [spliter[1].x, spliter[1].y]
        ],
        closed: false
    });

    let intersections = path1.getIntersections(path2); // 分割
    intersections.forEach(function (ins) {
        console.log(ins.getPoint());
        let result = ins.split();
        // console.log(result);
    });
    let a = 0;
    path1.children.forEach(function (path) {
github CIDARLAB / 3DuF / src / app / library / llChamber.js View on Github external
__renderControl(params){
        let rendered = new paper.CompoundPath();
        let position = params["position"];
        let px = position[0];
        let py = position[1];
        let l = params["length"];
        let w = params["width"];
        let rotation = params["rotation"];
        let color = params["color"];
        // let radius = params["cornerRadius"];

        let numArray = params["numberOfChambers"];
        let spacing = params["spacing"];

        let topchannel = new paper.Path.Rectangle({
            point: new paper.Point(px, py + 0.2*l - w/2),
            size:[ (numArray )*(w)  + (numArray+1) * spacing, w],
        });
github ecomfe / fonteditor / src / graphics / pathSplitBySegment.js View on Github external
function getPath(contours) {
            // 根据contours获取paper.Path对象
            var d = contours2svg(contours);
            return new paper.CompoundPath(d);
        }
github alexjlockwood / ShapeShifter / src / app / scripts / toolmode / util / PaperUtil.ts View on Github external
}
      // TODO: convert trim path properties to/from stroke dash array
      // TODO: deal with fill and stroke opacity!!!!!
      const { trimPathStart, trimPathEnd, trimPathOffset, fillAlpha, strokeAlpha } = layer;
      item.data = {
        trimPathStart,
        trimPathEnd,
        trimPathOffset,
        fillAlpha,
        strokeAlpha,
      };
      return item;
    }
    if (layer instanceof ClipPathLayer) {
      const pathStr = layer.pathData ? layer.pathData.getPathString() : '';
      const item = new paper.CompoundPath(pathStr);
      item.clipMask = true;
      return item;
    }
    if (layer instanceof GroupLayer) {
      const item = new paper.Group();
      item.applyMatrix = false;
      const { pivotX, pivotY, scaleX, scaleY, translateX, translateY, rotation } = layer;
      item.data = {
        pivotX,
        pivotY,
        scaleX,
        scaleY,
        translateX,
        translateY,
        rotation,
      };
github CIDARLAB / 3DuF / src / app / library / pump3D.js View on Github external
__drawFlow(params){
        let valve;
        let cutout;
        let circ;
        let center;
        let ret = new paper.CompoundPath();

        let position = params["position"];
        let gap = params["gap"];
        let radius = params["valveRadius"];
        let color = params["color"];
        let rotation = params["rotation"];
        let spacing = params["spacing"];
        let channelwidth = params["flowChannelWidth"];

        center = new paper.Point(position[0], position[1]);
        // let h0p0, h0p1, h0p2, h1p0, h1p1, h1p2;
        circ = new paper.Path.Circle(center, radius);
        //circ.fillColor = color;
        //   if (String(color) == "3F51B5") {
        cutout = paper.Path.Rectangle({
            from: new paper.Point(position[0] - radius, position[1] - gap / 2),
github techninja / cncserver / src / components / core / drawing / cncserver.drawing.base.js View on Github external
if (path.includes('{')) {
        // If this fails the paper error will bubble up to the implementor.
        path = cncserver.drawing.base.layers.temp.importJSON(path);
      } else {
        // D string, create the compound path directly
        return base.setName(new CompoundPath(path));
      }
    }

    // If the passed object already is compounnd, return it directly.
    if (path instanceof CompoundPath) {
      return base.setName(path);
    }

    // Standard path, create a compound path from it.
    return base.setName(new CompoundPath({
      children: [path],
      fillColor: path.fillColor,
      strokeColor: path.strokeColor,
    }));
  };
github CIDARLAB / 3DuF / src / app / library / pump3D.js View on Github external
__drawControl(params){
        let circ;
        let position = params["position"];
        let radius = params["valveRadius"];
        let color = params["color"];
        let rotation = params["rotation"];
        let spacing = params["spacing"];

        console.log("Spacing:", spacing);

        let ret = new paper.CompoundPath();

        let center = new paper.Point(position[0], position[1]);

        circ = new paper.Path.Circle(center, radius);
        ret.addChild(circ);

        let topcenter = new paper.Point(position[0], position[1] - spacing);
        circ = new paper.Path.Circle(topcenter, radius);
        ret.addChild(circ);


        let bottomcenter = new paper.Point(position[0], position[1] + spacing);
        circ = new paper.Path.Circle(bottomcenter, radius);
        ret.addChild(circ);

        ret.rotate(rotation, center);
github CIDARLAB / 3DuF / src / app / library / ytree.js View on Github external
let color = params["color"];
        let stagelength = params["stageLength"];
        let px = position[0];
        let py = position[1];

        let levels = Math.ceil(Math.log2(leafs));
        let isodd = false; //This is used to figure out how many lines have to be made
        if (leafs % 2 == 0) {
            isodd = false;
        } else {
            isodd = true;
        }
        let w = spacing * (leafs / 2 + 1);
        let l = (levels + 1) * stagelength;

        var treepath = new paper.CompoundPath();

        this.__generateYTwig(treepath, px, py, cw, stagelength, w, 1, levels);


        //Draw the tree

        treepath.fillColor = color;
        let rotation = 0;
        if (orientation == "H" && direction == "OUT") {
            rotation = 180;
        } else if (orientation == "V" && direction == "IN") {
            rotation = 270;
        } else if (orientation == "V" && direction == "OUT") {
            rotation = 90;
        }
        return treepath.rotate(rotation, px, py);
github CIDARLAB / 3DuF / src / app / library / pump.js View on Github external
let rec;
        let position = params["position"];
        let px = position[0];
        let py = position[1];
        let l = params["length"];
        let w = params["width"];
        let color = params["color"];
        let rotation = params["rotation"];
        let spacing = params["spacing"];

        let startX = px - w / 2;
        let startY = py - l / 2;
        let endX = px + w / 2;
        let endY = py + l / 2;

        let ret = new paper.CompoundPath();

        let startPoint = new paper.Point(startX, startY);
        let endPoint = new paper.Point(endX, endY);


        rec = paper.Path.Rectangle({
            from: startPoint,
            to: endPoint,
            radius: 0,
            fillColor: color,
            strokeWidth: 0
        });

        ret.addChild(rec);

        let topcenter = new paper.Point(px, py - spacing);
github CIDARLAB / 3DuF / src / app / library / alignmentMarks.js View on Github external
__drawFlow(params) {
        let position = params["position"];
        let width = params["width"];
        let length = params["length"];
        let color = params["color"];
        let center = new paper.Point(position[0], position[1]);
        let ret = new paper.CompoundPath();
        let topleftpoint = new paper.Point(position[0] - width, position[1] - length);
        let bottomrightpoint = new paper.Point(position[0] + width, position[1] + length);

        let topleftrect = new paper.Path.Rectangle(topleftpoint, center);

        ret.addChild(topleftrect);

        let bottomrightrect = new paper.Path.Rectangle(position, bottomrightpoint);

        ret.addChild(bottomrightrect);

        ret.fillColor = color;
        return ret;
    }