How to use the paper.Point 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.

github CIDARLAB / 3DuF / src / app / view / render2D / dxfObjectRenderer2D.js View on Github external
// // create geometry
    for(let i = 0; i < entity.vertices.length; i++) {

        if(entity.vertices[i].bulge) {
            //TODO: Figure out what to do with the bugle value
            bulge = entity.vertices[i].bulge;
            startPoint = entity.vertices[i];
            endPoint = (i + 1 < entity.vertices.length) ? entity.vertices[i + 1] : geometry.vertices[0];
            console.log("Start Point:", startPoint);
            console.log("End Point:", endPoint);

        } else {
            let vertex = entity.vertices[i];
            let nextvertex = entity.vertices[(i + 1 < entity.vertices.length) ? i + 1 : 0];
            let point = new paper.Point(vertex.x * 1000, vertex.y * 1000); //Need to convert everything to microns
            let nextpoint = new paper.Point(nextvertex.x * 1000, nextvertex.y * 1000);
            // console.log("Vertex:", point, nextpoint);
            let line = new paper.Path.Line(point, nextpoint);
            path.addChild(line);
        }

    }

}
github alexjlockwood / ShapeShifter / src / app / scripts / paper / util / Transforms.ts View on Github external
// After matrix mapping, we get u1 and v1. Let Θ be the angle between u1 and v1.
  // Then the final scale we want is:
  //
  // Math.min(|u1|sin(Θ),|v1|sin(Θ)) = |u1||v1|sin(Θ) / Math.max(|u1|,|v1|)
  //
  // If Math.max(|u1|,|v1|) = 0, that means either x or y has a scale of 0.
  //
  // For the non-skew case, which is most of the cases, matrix scale is
  // computing exactly the scale on x and y axis, and take the minimal of these two.
  //
  // For the skew case, an unit square will mapped to a parallelogram,
  // and this function will return the minimal height of the 2 bases.
  const { matrix } = paper.project.activeLayer;
  const m = new paper.Matrix(matrix.a, matrix.b, matrix.c, matrix.d, 0, 0);
  const u0 = new paper.Point(0, 1);
  const v0 = new paper.Point(1, 0);
  const u1 = u0.transform(m);
  const v1 = v0.transform(m);
  const sx = Math.hypot(u1.x, u1.y);
  const sy = Math.hypot(v1.x, v1.y);
  const dotProduct = u1.y * v1.x - u1.x * v1.y;
  const maxScale = Math.max(sx, sy);
  return maxScale > 0 ? Math.abs(dotProduct) / maxScale : 0;
}
github CIDARLAB / 3DuF / src / app / library / valve3D.js View on Github external
__drawFlow(params){
        let position = params["position"];
        let gap = params["gap"];
        let radius = params["valveRadius"];
        let color = params["color"];
        let orientation = params["orientation"];
        let rotation = params["rotation"];

        let center = new paper.Point(position[0], position[1]);
        // let h0p0, h0p1, h0p2, h1p0, h1p1, h1p2;
        let circ = new paper.Path.Circle(center, radius);
        //circ.fillColor = color;
        //   if (String(color) == "3F51B5") {
        let cutout = paper.Path.Rectangle({
            from: new paper.Point(position[0] - radius, position[1] - gap / 2),
            to: new paper.Point(position[0] + radius, position[1] + gap / 2)
        });
        //cutout.fillColor = "white";
        let valve = circ.subtract(cutout);
        valve.rotate(rotation, center);
        valve.fillColor = color;
        return valve;


    }
github CIDARLAB / 3DuF / src / app / library / rotaryMixer.js View on Github external
let innercirc = new paper.Path.Circle(center, radius);
        let outercirc = new paper.Path.Circle(center, radius + flowchannelwidth);

        let rotary = outercirc.subtract(innercirc);

        rotarymixer.addChild(rotary);

        let point1 = new paper.Point(px, py - radius - flowchannelwidth);
        let point2 = new paper.Point(px + channellength, py - radius);
        let rectangle = new paper.Path.Rectangle(point1, point2);

        rotarymixer.addChild(rectangle);

        let point3 = new paper.Point(px-channellength, py + radius);
        let point4 = new paper.Point(px, py + radius + flowchannelwidth);
        let rectangle2 = new paper.Path.Rectangle(point3, point4);

        rotarymixer.addChild(rectangle2);

        let rotation = 0;
        if (orientation == "V") {
            rotation = 90;
        }
        else {
            rotation = 0;
        }
        // cutout.fillColor = "white";

        rotarymixer.fillColor = color;

        return rotarymixer.rotate(rotation, px, py);
github CIDARLAB / 3DuF / src / app / library / mux.js View on Github external
//Draw 2 leafs
        //left leaf
        let lstartx = px - 0.5 * (cw + spacing);
        let lendx = lstartx + cw;
        let lstarty = py + stagelength + cw;
        let lendy = lstarty + stagelength;

        // //right leaf
        let rstartx = px + 0.5 * (spacing - cw);
        let rendx = rstartx + cw;
        let rstarty = py + stagelength + cw;
        let rendy = rstarty + stagelength;

        if(drawleafs){
            startPoint = new paper.Point(lstartx, lstarty);
            endPoint = new paper.Point(lendx, lendy);
            rec = paper.Path.Rectangle({
                from: startPoint,
                to: endPoint,
                radius: 0,
                strokeWidth: 0
            });
            treepath.addChild(rec);

            startPoint = new paper.Point(rstartx, rstarty);
            endPoint = new paper.Point(rendx, rendy);
            rec = paper.Path.Rectangle({
                from: startPoint,
                to: endPoint,
                radius: 0,
                strokeWidth: 0
github CIDARLAB / 3DuF / src / app / library / mux.js View on Github external
let rstarty = py + stagelength + cw;
        let rendy = rstarty + stagelength;

        if(drawleafs){
            startPoint = new paper.Point(lstartx, lstarty);
            endPoint = new paper.Point(lendx, lendy);
            rec = paper.Path.Rectangle({
                from: startPoint,
                to: endPoint,
                radius: 0,
                strokeWidth: 0
            });
            treepath.addChild(rec);

            startPoint = new paper.Point(rstartx, rstarty);
            endPoint = new paper.Point(rendx, rendy);
            rec = paper.Path.Rectangle({
                from: startPoint,
                to: endPoint,
                radius: 0,
                strokeWidth: 0
            });
            treepath.addChild(rec);

        }


        //Horizontal bar
        let hstartx = px - 0.5 * (cw + spacing);
        let hendx = rendx;
        let hstarty = py + stagelength;
        let hendy = hstarty + cw;
github CIDARLAB / 3DuF / src / app / view / render2D / dxfSolidObjectRenderer2D.js View on Github external
function calculateBulgeThroughPoint(startpoint, endpoint, bulgevalue) {
    let throughpoint = 0;

    let start = new paper.Point(startpoint.x, startpoint.y);
    let end = new paper.Point(endpoint.x, endpoint.y);
    let angle = 4 * Math.atan(bulgevalue);


    /*
    https://math.stackexchange.com/questions/9365/endpoint-of-a-line-knowing-slope-start-and-distance
     */
    let epsilon = angle/4;

    let midpoint = new paper.Point(startpoint.x/2 + endpoint.x/2,
        startpoint.y/2 + endpoint.y/2);

    let p = new paper.Point(startpoint.x, startpoint.y).getDistance(midpoint) * bulgevalue;

    let slope = (endpoint.y - startpoint.y)/(endpoint.x - startpoint.x);

    let chordvector = end.subtract(start);
github CIDARLAB / 3DuF / src / app / library / llChamber.js View on Github external
radius: 0
            });

            rendered.addChild(rec);

        }

        let topchannel = new paper.Path.Rectangle({
            point: new paper.Point(px, py - w),
            size:[ (numArray )*(w)  + (numArray+1) * spacing, w],
        });

        rendered.addChild(topchannel);

        let bottomchannel = new paper.Path.Rectangle({
            point: new paper.Point(px, py + l),
            size:[ (numArray )*(w)  + (numArray+1) * spacing, w],
        });

        rendered.addChild(bottomchannel);

        rendered.fillColor = color;
        return rendered.rotate(rotation, px, py);

    }
github CIDARLAB / 3DuF / src / app / library / llChamber.js View on Github external
let rec;

        for(let i = 0; i < numArray; i++){
            rec = new paper.Path.Rectangle({
                point: new paper.Point(px  + (i+1)*spacing + i*w, py-1),
                size: [w, l +2],
                radius: 0
            });

            rendered.addChild(rec);

        }

        let topchannel = new paper.Path.Rectangle({
            point: new paper.Point(px, py - w),
            size:[ (numArray )*(w)  + (numArray+1) * spacing, w],
        });

        rendered.addChild(topchannel);

        let bottomchannel = new paper.Path.Rectangle({
            point: new paper.Point(px, py + l),
            size:[ (numArray )*(w)  + (numArray+1) * spacing, w],
        });

        rendered.addChild(bottomchannel);

        rendered.fillColor = color;
        return rendered.rotate(rotation, px, py);
    }
github CIDARLAB / 3DuF / src / app / view / render2D / dxfSolidObjectRenderer2D.js View on Github external
function calculateBulgeThroughPoint(startpoint, endpoint, bulgevalue) {
    let throughpoint = 0;

    let start = new paper.Point(startpoint.x, startpoint.y);
    let end = new paper.Point(endpoint.x, endpoint.y);
    let angle = 4 * Math.atan(bulgevalue);


    /*
    https://math.stackexchange.com/questions/9365/endpoint-of-a-line-knowing-slope-start-and-distance
     */
    let epsilon = angle/4;

    let midpoint = new paper.Point(startpoint.x/2 + endpoint.x/2,
        startpoint.y/2 + endpoint.y/2);

    let p = new paper.Point(startpoint.x, startpoint.y).getDistance(midpoint) * bulgevalue;

    let slope = (endpoint.y - startpoint.y)/(endpoint.x - startpoint.x);