Skip to content

Commit

Permalink
Update the examples to use the draw API
Browse files Browse the repository at this point in the history
  • Loading branch information
sgenoud committed Feb 14, 2023
1 parent 8cc4625 commit 6a2d332
Show file tree
Hide file tree
Showing 6 changed files with 225 additions and 227 deletions.
21 changes: 10 additions & 11 deletions packages/replicad-docs/examples/birdhouse.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@ const defaultParams = {
hookHeight: 10.0,
};

/** @typedef { typeof import("replicad") } replicadLib */
/** @type {function(replicadLib, typeof defaultParams): any} */
const { drawCircle, draw, makePlane } = replicad;

function main(
{ Sketcher, sketchCircle },
r,
{ width: inputWidth, height, thickness, holeDia, hookHeight }
) {
const length = inputWidth;
const width = inputWidth * 0.9;

const tobleroneShape = new Sketcher("XZ", -length / 2)
.movePointerTo([-width / 2, 0])
const tobleroneShape = draw([-width / 2, 0])
.lineTo([0, height])
.lineTo([width / 2, 0])
.close()
.sketchOnPlane("XZ", -length / 2)
.extrude(length)
.shell(thickness, (f) => f.parallelTo("XZ"))
.fillet(thickness / 2, (e) =>
Expand All @@ -28,17 +28,15 @@ function main(
.either([(f) => f.inPlane("XY"), (f) => f.inPlane("XY", height)])
);

const hole = sketchCircle(holeDia / 2, {
plane: "YZ",
origin: [-length / 2, 0, height / 3],
}).extrude(length);
const hole = drawCircle(holeDia / 2)
.sketchOnPlane(makePlane("YZ").translate([-length / 2, 0, height / 3]))
.extrude(length);

const base = tobleroneShape.cut(hole);
const body = base.clone().fuse(base.rotate(90));

const hookWidth = length / 2;
const hook = new Sketcher("XZ")
.movePointerTo([0, hookHeight / 2])
const hook = draw([0, hookHeight / 2])
.smoothSplineTo([hookHeight / 2, 0], -45)
.lineTo([hookWidth / 2, 0])
.line(-hookWidth / 4, hookHeight / 2)
Expand All @@ -47,6 +45,7 @@ function main(
endFactor: 0.6,
})
.closeWithMirror()
.sketchOnPlane("XZ")
.extrude(thickness)
.translate([0, thickness / 2, height - thickness / 2]);

Expand Down
22 changes: 11 additions & 11 deletions packages/replicad-docs/examples/bottle.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ const defaultParams = {
thickness: 30,
};

/** @typedef { typeof import("replicad") } replicadLib */
/** @type {function(replicadLib, typeof defaultParams): any} */
const { draw, makeCylinder, makeOffset, FaceFinder } = replicad;

const main = (
{ Sketcher, FaceSketcher, makeCylinder, makeOffset, FaceFinder },
r,
{ width: myWidth, height: myHeight, thickness: myThickness }
) => {
let shape = new Sketcher()
.movePointerTo([-myWidth / 2, 0])
let shape = draw([-myWidth / 2, 0])
.vLine(-myThickness / 4)
.threePointsArc(myWidth, 0, myWidth / 2, -myThickness / 4)
.vLine(myThickness / 4)
.closeWithMirror()
.sketchOnPlane()
.extrude(myHeight)
.fillet(myThickness / 12);

Expand All @@ -40,16 +40,16 @@ const main = (
.find(shape.clone(), { unique: true });

const bottomThreadFace = makeOffset(neckFace, -0.01 * myNeckRadius).faces[0];
const baseThreadSketch = new FaceSketcher(bottomThreadFace)
.movePointerTo([0.75, 0.25])
const baseThreadSketch = draw([0.75, 0.25])
.halfEllipse(2, 0.5, 0.1)
.close();
.close()
.sketchOnFace(bottomThreadFace, "bounds");

const topThreadFace = makeOffset(neckFace, 0.05 * myNeckRadius).faces[0];
const topThreadSketch = new FaceSketcher(topThreadFace)
.movePointerTo([0.75, 0.25])
const topThreadSketch = draw([0.75, 0.25])
.halfEllipse(2, 0.5, 0.05)
.close();
.close()
.sketchOnFace(topThreadFace, "bounds");

const thread = baseThreadSketch.loftWith(topThreadSketch);

Expand Down
14 changes: 7 additions & 7 deletions packages/replicad-docs/examples/cadquery-cycloidal-gear.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const { drawCircle, drawParametricFunction } = replicad;

const hypocycloid = (t, r1, r2) => {
return [
(r1 - r2) * Math.cos(t) + r2 * Math.cos((r1 / r2) * t - t),
Expand All @@ -22,14 +24,12 @@ const defaultParams = {
height: 15,
};

/** @typedef { typeof import("replicad") } replicadLib */
/** @type {function(replicadLib, typeof defaultParams): any} */
const main = ({ sketchCircle, sketchParametricFunction }, { height }) => {
const base = sketchParametricFunction((t) =>
gear(2 * Math.PI * t, 6, 1)
).extrude(height, { twistAngle: 90 });
const main = (r, { height }) => {
const base = drawParametricFunction((t) => gear(2 * Math.PI * t, 6, 1))
.sketchOnPlane()
.extrude(height, { twistAngle: 90 });

const hole = sketchCircle(2).extrude(height);
const hole = drawCircle(2).sketchOnPlane().extrude(height);

return base.cut(hole);
};
Loading

0 comments on commit 6a2d332

Please sign in to comment.