1
0
Fork 0

sparkles: Examples for Point, Path, and Utils

This commit is contained in:
Joost De Cock 2018-08-14 16:07:36 +02:00
parent 5ef66195de
commit 0b8a056d46
35 changed files with 1137 additions and 61 deletions

View file

@ -3,7 +3,7 @@
<head>
<meta charset="UTF-8">
<title>Examples</title>
<script type="text/javascript" src="node_modules/freesewing/dist/browser.js"></script>
<script type="text/javascript" src="freesewing.js"></script>
<script type="text/javascript" src="node_modules/@freesewing/plugin-bundle/dist/browser.js"></script>
<script type="text/javascript" src="dist/browser.js"></script>
<script type="text/javascript" src="node_modules/@freesewing/plugin-theme/dist/browser.js"></script>
@ -19,7 +19,7 @@
var pattern = freesewing.patterns.examples
.with(freesewing.plugins.debug)
.with(freesewing.plugins.theme)
.with(freesewing.plugins.designer)
//.with(freesewing.plugins.designer)
.with(freesewing.plugins.validate)
;
pattern.settings.measurements = freesewing.models.men.manSize36;

View file

@ -1,30 +0,0 @@
import freesewing from "freesewing";
var back = {
draft: function(part) {
// prettier-ignore
let {store, sa, Point, points, Path, paths, Snippet, snippets, options, measurements, final, paperless, macro} = part.shorthand();
// Do your work here :)
points.start = new Point(0, 0);
points.end = new Point(75, 0);
paths.example = new Path()
.move(points.start)
.line(points.end)
.attr("data-text", "This is the front part")
.attr("data-text-class", "center");
// Final?
if (final) {
}
// Paperless?
if (paperless) {
}
return part;
}
};
export default back;

View file

@ -1,23 +0,0 @@
import freesewing from "freesewing";
var front = {
draft: function(part) {
// prettier-ignore
let {store, sa, Point, points, Path, paths, Snippet, snippets, options, measurements, final, paperless, macro} = part.shorthand();
// Building on top of back, just need to change the text
paths.example.attributes.set("data-text", "This is the back part");
// Final?
if (final) {
}
// Paperless?
if (paperless) {
}
return part;
}
};
export default front;

View file

@ -4,21 +4,123 @@ import pluginBundle from "@freesewing/plugin-bundle";
import config from "../config/config";
import { version } from "../package.json";
import back from "./back";
import front from "./front";
import pointAttr from "./point.attr";
import pointDist from "./point.dist";
import pointDx from "./point.dx";
import pointDy from "./point.dy";
import pointAngle from "./point.angle";
import pointRotate from "./point.rotate";
import pointCopy from "./point.copy";
import pointFlipX from "./point.flipx";
import pointFlipY from "./point.flipy";
import pointShift from "./point.shift";
import pointShiftTowards from "./point.shifttowards";
import pointShiftFractionTowards from "./point.shiftfractiontowards";
import pointShiftOutwards from "./point.shiftoutwards";
import pointSitsOn from "./point.sitson";
import pointClone from "./point.clone";
import pathOps from "./path.ops";
import pathAttr from "./path.attr";
import pathOffset from "./path.offset";
import pathLength from "./path.length";
import pathStart from "./path.start";
import pathEnd from "./path.end";
import pathClone from "./path.clone";
import pathJoin from "./path.join";
import pathReverse from "./path.reverse";
import pathShiftAlong from "./path.shiftalong";
import pathShiftFractionAlong from "./path.shiftfractionalong";
import utilsLinesCross from "./utils.linescross";
import utilsBeamsCross from "./utils.beamscross";
import utilsBeamCrossesX from "./utils.beamcrossesx";
import utilsBeamCrossesY from "./utils.beamcrossesy";
var pattern = new freesewing.Pattern({ version: version, ...config }).with(
pluginBundle
);
pattern.draft = function() {
this.parts.back = this.draftBack(new pattern.Part());
this.parts.front = this.draftFront(new pattern.Part().copy(this.parts.back));
this.parts.pointAttr = this.draftPointAttr(new pattern.Part());
this.parts.pointDist = this.draftPointDist(new pattern.Part());
this.parts.pointDx = this.draftPointDx(new pattern.Part());
this.parts.pointDy = this.draftPointDy(new pattern.Part());
this.parts.pointAngle = this.draftPointAngle(new pattern.Part());
this.parts.pointRotate = this.draftPointRotate(new pattern.Part());
this.parts.pointCopy = this.draftPointCopy(new pattern.Part());
this.parts.pointFlipX = this.draftPointFlipX(new pattern.Part());
this.parts.pointFlipY = this.draftPointFlipY(new pattern.Part());
this.parts.pointShift = this.draftPointShift(new pattern.Part());
this.parts.pointShiftTowards = this.draftPointShiftTowards(new pattern.Part());
this.parts.pointShiftFractionTowards = this.draftPointShiftFractionTowards(new pattern.Part());
this.parts.pointShiftOutwards = this.draftPointShiftOutwards(new pattern.Part());
this.parts.pointSitsOn = this.draftPointSitsOn(new pattern.Part());
this.parts.pointClone = this.draftPointClone(new pattern.Part());
this.parts.pathOps = this.draftPathOps(new pattern.Part());
this.parts.pathAttr = this.draftPathAttr(new pattern.Part());
this.parts.pathOffset = this.draftPathOffset(new pattern.Part());
this.parts.pathLength = this.draftPathLength(new pattern.Part());
this.parts.pathStart = this.draftPathStart(new pattern.Part());
this.parts.pathEnd = this.draftPathEnd(new pattern.Part());
this.parts.pathClone = this.draftPathClone(new pattern.Part());
this.parts.pathJoin = this.draftPathJoin(new pattern.Part());
this.parts.pathReverse = this.draftPathReverse(new pattern.Part());
this.parts.pathShiftAlong = this.draftPathShiftAlong(new pattern.Part());
this.parts.pathShiftFractionAlong = this.draftPathShiftFractionAlong(new pattern.Part());
this.parts.utilsLinesCross = this.draftUtilsLinesCross(new pattern.Part());
this.parts.utilsBeamsCross = this.draftUtilsBeamsCross(new pattern.Part());
this.parts.utilsBeamCrossesX = this.draftUtilsBeamCrossesX(new pattern.Part());
this.parts.utilsbeamCrossesY = this.draftUtilsBeamCrossesY(new pattern.Part());
return pattern;
};
pattern.draftBack = part => back.draft(part);
pattern.draftFront = part => front.draft(part);
pattern.draftPointAttr = part => pointAttr.draft(part);
pattern.draftPointDist = part => pointDist.draft(part);
pattern.draftPointDx = part => pointDx.draft(part);
pattern.draftPointDy = part => pointDy.draft(part);
pattern.draftPointAngle = part => pointAngle.draft(part);
pattern.draftPointRotate = part => pointRotate.draft(part);
pattern.draftPointCopy = part => pointCopy.draft(part);
pattern.draftPointFlipX = part => pointFlipX.draft(part);
pattern.draftPointFlipY = part => pointFlipY.draft(part);
pattern.draftPointShift = part => pointShift.draft(part);
pattern.draftPointShiftTowards = part => pointShiftTowards.draft(part);
pattern.draftPointShiftFractionTowards = part => pointShiftFractionTowards.draft(part);
pattern.draftPointShiftOutwards = part => pointShiftOutwards.draft(part);
pattern.draftPointSitsOn = part => pointSitsOn.draft(part);
pattern.draftPointClone = part => pointClone.draft(part);
pattern.draftPathOps = part => pathOps.draft(part);
pattern.draftPathAttr = part => pathAttr.draft(part);
pattern.draftPathOffset = part => pathOffset.draft(part);
pattern.draftPathLength = part => pathLength.draft(part);
pattern.draftPathStart = part => pathStart.draft(part);
pattern.draftPathEnd = part => pathEnd.draft(part);
pattern.draftPathClone = part => pathClone.draft(part);
pattern.draftPathJoin = part => pathJoin.draft(part);
pattern.draftPathReverse = part => pathReverse.draft(part);
pattern.draftPathShiftAlong = part => pathShiftAlong.draft(part);
pattern.draftPathShiftFractionAlong = part => pathShiftFractionAlong.draft(part);
pattern.draftUtilsLinesCross = part => utilsLinesCross.draft(part);
pattern.draftUtilsBeamsCross = part => utilsBeamsCross.draft(part);
pattern.draftUtilsBeamCrossesX = part => utilsBeamCrossesX.draft(part);
pattern.draftUtilsBeamCrossesY = part => utilsBeamCrossesY.draft(part);
// Add custom snippet
pattern.on('preRender', function(next) {
this.defs += `
<g id="x">
<path d="M -1.1 -1.1 L 1.1 1.1 M 1.1 -1.1 L -1.1 1.1" class="note"></path>
<circle cy="0" cx="0" r="1.8" class="note"></circle>
</g>
`;
next();
});
export default pattern;

View file

@ -0,0 +1,25 @@
import freesewing from "freesewing";
import { box } from "./shared";
var pathAttrs = {
draft: function(part) {
// prettier-ignore
let {Point, points, Path, paths, Snippet, snippets, macro} = part.shorthand();
points.B = new Point(10, 30);
points.BCp2 = new Point(40, 40);
points.C = new Point(90, 30);
points.CCp1 = new Point(50, -30);
paths.example = new Path()
.move(points.B)
.curve(points.BCp2, points.CCp1, points.C)
.attr('class', 'stroke-xl canvas')
.attr('data-text', 'I am text placed on a path')
.attr('data-text-class', 'center fill-note');
return part;
}
};
export default pathAttrs;

View file

@ -0,0 +1,27 @@
import freesewing from "freesewing";
import { box } from "./shared";
var pathClone = {
draft: function(part) {
// prettier-ignore
let {Point, points, Path, paths, Snippet, snippets, macro} = part.shorthand();
points.A = new Point(45, 60);
points.B = new Point(10, 30);
points.BCp2 = new Point(40, 20);
points.C = new Point(90, 30);
points.CCp1 = new Point(50, -30);
paths.example = new Path()
.move(points.A)
.line(points.B)
.curve(points.BCp2, points.CCp1, points.C);
paths.clone = paths.example.clone()
.attr('class', 'note lashed stroke-xl');
return part;
}
};
export default pathClone;

View file

@ -0,0 +1,25 @@
import freesewing from "freesewing";
import { box } from "./shared";
var pathEnd = {
draft: function(part) {
// prettier-ignore
let {Point, points, Path, paths, Snippet, snippets, macro} = part.shorthand();
points.A = new Point(45, 60);
points.B = new Point(10, 30);
points.BCp2 = new Point(40, 20);
points.C = new Point(90, 30);
points.CCp1 = new Point(50, -30);
paths.example = new Path()
.move(points.A)
.line(points.B)
.curve(points.BCp2, points.CCp1, points.C)
snippets.x = new Snippet('x', paths.example.end());
return part;
}
};
export default pathEnd;

View file

@ -0,0 +1,32 @@
import freesewing from "freesewing";
import { box } from "./shared";
var pathJoin = {
draft: function(part) {
// prettier-ignore
let {Point, points, Path, paths, Snippet, snippets, macro} = part.shorthand();
points.A = new Point(45, 60);
points.B = new Point(10, 30);
points.BCp2 = new Point(40, 20);
points.C = new Point(90, 30);
points.CCp1 = new Point(50, -30);
paths.path1 = new Path()
.move(points.A)
.line(points.B)
.attr('class', 'various');
paths.path2 = new Path()
.move(points.B)
.curve(points.BCp2, points.CCp1, points.C)
.attr('class', 'canvas');
paths.joint = paths.path1.join(paths.path2)
.attr('class', 'note lashed stroke-xl');
return part;
}
};
export default pathJoin;

View file

@ -0,0 +1,43 @@
import freesewing from "freesewing";
import { box } from "./shared";
var pathLength = {
draft: function(part) {
// prettier-ignore
let {Point, points, Path, paths, Snippet, snippets, macro} = part.shorthand();
points.A = new Point(45, 60);
points.B = new Point(10, 30);
points.BCp2 = new Point(40, 20);
points.C = new Point(90, 30);
points.CCp1 = new Point(50, -30);
paths.example = new Path()
.move(points.A)
.line(points.B)
.curve(points.BCp2, points.CCp1, points.C)
macro('pd', {
path: paths.example,
d: -20
});
macro('pd', {
path: new Path()
.move(points.B)
.line(points.A),
d: 10
});
macro('pd', {
path: new Path()
.move(points.B)
.curve(points.BCp2, points.CCp1, points.C),
d: -10
});
return part;
}
};
export default pathLength;

View file

@ -0,0 +1,40 @@
import freesewing from "freesewing";
import { box } from "./shared";
var pathOffset = {
draft: function(part) {
// prettier-ignore
let {Point, points, Path, paths, Snippet, snippets, macro} = part.shorthand();
points.A = new Point(45, 60);
points.B = new Point(10, 30);
points.BCp2 = new Point(40, 20);
points.C = new Point(90, 30);
points.CCp1 = new Point(50, -30);
paths.example = new Path()
.move(points.A)
.line(points.B)
.curve(points.BCp2, points.CCp1, points.C)
.line(points.A)
.close();
paths.offset = paths.example.offset(-10)
.attr('class', 'interfacing');
paths.lineOffset = new Path()
.move(points.A)
.line(points.B).offset(-5)
.attr('class', 'various');
paths.curveOffset = new Path()
.move(points.B)
.curve(points.BCp2, points.CCp1, points.C)
.offset(-5)
.attr('class', 'canvas');
return part;
}
};
export default pathOffset;

View file

@ -0,0 +1,57 @@
import freesewing from "freesewing";
import { box } from "./shared";
var pathOps = {
draft: function(part) {
// prettier-ignore
let {Point, points, Path, paths, Snippet, snippets, macro} = part.shorthand();
box(part);
points.A = new Point(10, 10)
.attr('data-text', 'Move to point A')
.attr('data-text-class', 'center text-xs');
points.B = new Point(70, 30);
points.BCp2 = new Point(40, 10);
points.C = new Point(90, -50);
points.CCp1 = new Point(125, -30);
paths.example = new Path()
.move(points.A)
.line(points.B)
.curve(points.BCp2, points.CCp1, points.C)
.close();
paths.handle1 = new Path().move(points.B).line(points.BCp2).attr('class', 'note dashed');
paths.handle2 = new Path().move(points.C).line(points.CCp1).attr('class', 'note dashed');
snippets.A = new Snippet('notch', points.A);
snippets.B = new Snippet('notch', points.B);
snippets.C = new Snippet('notch', points.C);
snippets.Bcp2 = new Snippet('x', points.BCp2);
snippets.Ccp1 = new Snippet('x', points.CCp1);
paths.textLine = new Path()
.move(points.A)
.line(points.B)
.attr('data-text', 'Line to point B')
.attr('data-text-class', 'center text-xs');
paths.textCurve = new Path()
.move(points.B)
.curve(points.BCp2, points.CCp1, points.C)
.attr('data-text', 'Curve to point C, using BCp2 and CCp1 as control points')
.attr('data-text-class', 'center text-xs');
paths.textClose = new Path()
.move(points.A)
.line(points.C)
.attr('data-text', 'Close path')
.attr('data-text-class', 'center text-xs');
return part;
}
};
export default pathOps;

View file

@ -0,0 +1,26 @@
import freesewing from "freesewing";
import { box } from "./shared";
var pathReverse = {
draft: function(part) {
// prettier-ignore
let {Point, points, Path, paths, Snippet, snippets, macro} = part.shorthand();
points.B = new Point(10, 30);
points.BCp2 = new Point(40, 20);
points.C = new Point(90, 30);
points.CCp1 = new Point(50, -30);
paths.example = new Path()
.move(points.B)
.curve(points.BCp2, points.CCp1, points.C)
.attr('data-text', 'I am the original path');
paths.reverse = paths.example.reverse()
.attr('data-text', 'I am the reversed path');
return part;
}
};
export default pathReverse;

View file

@ -0,0 +1,35 @@
import freesewing from "freesewing";
import { box } from "./shared";
var pathShiftAlong = {
draft: function(part) {
// prettier-ignore
let {Point, points, Path, paths, Snippet, snippets, macro} = part.shorthand();
points.A = new Point(45, 60);
points.B = new Point(10, 30);
points.BCp2 = new Point(40, 20);
points.C = new Point(90, 30);
points.CCp1 = new Point(50, -30);
paths.example = new Path()
.move(points.A)
.line(points.B)
.curve(points.BCp2, points.CCp1, points.C);
points.X1 = paths.example.shiftAlong(20)
.attr('data-text', 'Shifted 2cm along this path')
.attr('data-text-class', 'center');
points.X2 = paths.example.shiftAlong(90)
.attr('data-text', 'Shifted 9cm along this path')
.attr('data-text-class', 'center');
snippets.Xl = new Snippet('x', points.X1);
snippets.X2 = new Snippet('x', points.X2);
return part;
}
};
export default pathShiftAlong;

View file

@ -0,0 +1,35 @@
import freesewing from "freesewing";
import { box } from "./shared";
var pathShiftFractionAlong = {
draft: function(part) {
// prettier-ignore
let {Point, points, Path, paths, Snippet, snippets, macro} = part.shorthand();
points.A = new Point(45, 60);
points.B = new Point(10, 30);
points.BCp2 = new Point(40, 20);
points.C = new Point(90, 30);
points.CCp1 = new Point(50, -30);
paths.example = new Path()
.move(points.A)
.line(points.B)
.curve(points.BCp2, points.CCp1, points.C);
points.X1 = paths.example.shiftFractionAlong(0.25)
.attr('data-text', 'Shifted 20% along this path')
.attr('data-text-class', 'center');
points.X2 = paths.example.shiftFractionAlong(0.9)
.attr('data-text', 'Shifted 90% along this path')
.attr('data-text-class', 'center');
snippets.Xl = new Snippet('x', points.X1);
snippets.X2 = new Snippet('x', points.X2);
return part;
}
};
export default pathShiftFractionAlong;

View file

@ -0,0 +1,25 @@
import freesewing from "freesewing";
import { box } from "./shared";
var pathStart = {
draft: function(part) {
// prettier-ignore
let {Point, points, Path, paths, Snippet, snippets, macro} = part.shorthand();
points.A = new Point(45, 60);
points.B = new Point(10, 30);
points.BCp2 = new Point(40, 20);
points.C = new Point(90, 30);
points.CCp1 = new Point(50, -30);
paths.example = new Path()
.move(points.A)
.line(points.B)
.curve(points.BCp2, points.CCp1, points.C)
snippets.x = new Snippet('x', paths.example.start());
return part;
}
};
export default pathStart;

View file

@ -0,0 +1,36 @@
import freesewing from "freesewing";
import { box } from "./shared";
var pointAngle = {
draft: function(part) {
// prettier-ignore
let {Point, points, Path, paths, Snippet, snippets} = part.shorthand();
box(part, 80, 80);
points.sun = new Point(40, 40);
points.moon1 = new Point(70, 40).attr('data-text', '0').attr('data-text-class', 'text-xl');
points.moon2 = new Point(40, 10).attr('data-text', 90).attr('data-text-class', 'text-xl');
points.moon3 = new Point(10, 40).attr('data-text', 180).attr('data-text-class', 'text-xl');
points.moon4 = new Point(40, 70).attr('data-text', 270).attr('data-text-class', 'text-xl');
points.moon5 = points.moon1.rotate(-45, points.sun);
points.moon5.attr('data-text', points.sun.angle(points.moon5)).attr('data-text-class', 'text-xl');
paths.moon1 = new Path().move(points.sun).line(points.moon1).attr('class', 'dashed note');
paths.moon2 = new Path().move(points.sun).line(points.moon2).attr('class', 'dashed note');
paths.moon3 = new Path().move(points.sun).line(points.moon3).attr('class', 'dashed note');
paths.moon4 = new Path().move(points.sun).line(points.moon4).attr('class', 'dashed note');
paths.moon5 = new Path().move(points.sun).line(points.moon5).attr('class', 'dashed note');
snippets.notch = new Snippet("notch", points.sun);
snippets.notch1 = new Snippet("x", points.moon1);
snippets.notch2 = new Snippet("x", points.moon2);
snippets.notch3 = new Snippet("x", points.moon3);
snippets.notch4 = new Snippet("x", points.moon4);
snippets.notch5 = new Snippet("x", points.moon5);
return part;
}
};
export default pointAngle;

View file

@ -0,0 +1,22 @@
import freesewing from "freesewing";
import { box } from "./shared";
var pointAttr = {
draft: function(part) {
// prettier-ignore
let {Point, points, Snippet, snippets} = part.shorthand();
box(part);
points.anchor = new Point(50, 25)
.attr("data-text", "Hello world!\nThis is\na line break.")
.attr("data-text-class", "text-xl center")
.attr("data-text-lineheight", 10);
snippets.notch = new Snippet("x", points.anchor);
return part;
}
};
export default pointAttr;

View file

@ -0,0 +1,23 @@
import freesewing from "freesewing";
import { box } from "./shared";
var pointClone = {
draft: function(part) {
// prettier-ignore
let {Point, points, Snippet, snippets} = part.shorthand();
box(part);
points.A= new Point(50, 25)
.attr('data-text', 'Point A')
.attr('data-text-class', 'text-xl')
.attr('data-text-fill-opacity', '0.5');
points.B = points.A.clone().attr('data-text', 'Point B');
snippets.x = new Snippet("x", points.A);
return part;
}
};
export default pointClone;

View file

@ -0,0 +1,20 @@
import freesewing from "freesewing";
import { box } from "./shared";
var pointCopy = {
draft: function(part) {
// prettier-ignore
let {Point, points, Snippet, snippets} = part.shorthand();
box(part);
points.A= new Point(50, 25).attr('data-text', 'Point A').attr('data-text-class', 'text-xl');
points.B = points.A.copy().attr('data-text', 'Point B');
snippets.x = new Snippet("x", points.A);
return part;
}
};
export default pointCopy;

View file

@ -0,0 +1,26 @@
import freesewing from "freesewing";
import { box } from "./shared";
var pointDist = {
draft: function(part) {
// prettier-ignore
let {Point, points, Snippet, snippets, macro} = part.shorthand();
box(part);
points.from = new Point(10, 10);
points.to = new Point(90, 40);
macro('ld', {
from: points.from,
to: points.to
});
snippets.notch1 = new Snippet("x", points.from);
snippets.notch2 = new Snippet("x", points.to);
return part;
}
};
export default pointDist;

View file

@ -0,0 +1,27 @@
import freesewing from "freesewing";
import { box } from "./shared";
var pointDx = {
draft: function(part) {
// prettier-ignore
let {Point, points, Snippet, snippets, macro} = part.shorthand();
box(part);
points.from = new Point(10, 10);
points.to = new Point(90, 40);
macro('hd', {
from: points.from,
to: points.to,
y: 25
});
snippets.notch1 = new Snippet("x", points.from);
snippets.notch2 = new Snippet("x", points.to);
return part;
}
};
export default pointDx;

View file

@ -0,0 +1,27 @@
import freesewing from "freesewing";
import { box } from "./shared";
var pointDy = {
draft: function(part) {
// prettier-ignore
let {Point, points, Snippet, snippets, macro} = part.shorthand();
box(part);
points.from = new Point(10, 10);
points.to = new Point(90, 40);
macro('vd', {
from: points.to,
to: points.from,
x: 50
});
snippets.notch1 = new Snippet("x", points.from);
snippets.notch2 = new Snippet("x", points.to);
return part;
}
};
export default pointDy;

View file

@ -0,0 +1,58 @@
import freesewing from "freesewing";
import { box } from "./shared";
var pointFlipX = {
draft: function(part) {
// prettier-ignore
let {Point, points, Path, paths, Snippet, snippets, macro} = part.shorthand();
box(part);
points.top = new Point(50, 10);
points.out1 = new Point(70, 30);
points.in1 = new Point(55, 35);
points.out2 = new Point(75, 50);
points.in2 = new Point(60, 55);
points.out3 = new Point(80, 70);
points.in3 = new Point(55, 70);
points.trunkOut = new Point(55, 80);
points.trunkIn = new Point(50, 80);
points._out1 = points.out1.flipX(points.top);
points._in1 = points.in1.flipX(points.top);
points._out2 = points.out2.flipX(points.top);
points._in2 = points.in2.flipX(points.top);
points._out3 = points.out3.flipX(points.top);
points._in3 = points.in3.flipX(points.top);
points._trunkOut = points.trunkOut.flipX(points.top);
points.bottom = new Point(50, 80);
paths.tree = new Path()
.move(points.top)
.line(points.out1)
.line(points.in1)
.line(points.out2)
.line(points.in2)
.line(points.out3)
.line(points.in3)
.line(points.trunkOut)
.line(points._trunkOut)
.line(points._in3)
.line(points._out3)
.line(points._in2)
.line(points._out2)
.line(points._in1)
.line(points._out1)
.close();
paths.mirror = new Path()
.move(points.top)
.line(points.bottom)
.attr('class', 'note dashed');
return part;
}
};
export default pointFlipX;

View file

@ -0,0 +1,83 @@
import freesewing from "freesewing";
import { box } from "./shared";
var pointFlipX = {
draft: function(part) {
// prettier-ignore
let {Point, points, Path, paths, Snippet, snippets, macro} = part.shorthand();
box(part);
points.start = new Point(0, 50);
points.churchTowerWallLeft = new Point(10, 50);
points.churchTowerRoofLeft = new Point(10, 30);
points.churchTowerTop = new Point(15, 10);
points.churchTowerRoofRight = new Point(20, 30);
points.churchRoofRight = new Point(50, 30);
points.churchWallRight = new Point(50, 50);
points.houseWallLeft = new Point(65, 50);
points.houseRoofLeft = new Point(65, 35);
points.houseRoofTop = new Point(75, 25);
points.houseRoofRight = new Point(85, 35);
points.houseWallRight = new Point(85, 50);
points.end = new Point(95, 50);
points.mirror = new Point(0,60);
points.mirrorLineEnd = new Point(95,60);
points._start = points.start.flipY(points.mirror);
points._churchTowerWallLeft = points.churchTowerWallLeft.flipY(points.mirror);
points._churchTowerRoofLeft = points.churchTowerRoofLeft.flipY(points.mirror);
points._churchTowerTop = points.churchTowerTop.flipY(points.mirror);
points._churchTowerRoofRight = points.churchTowerRoofRight.flipY(points.mirror);
points._churchRoofRight = points.churchRoofRight.flipY(points.mirror);
points._churchWallRight = points.churchWallRight.flipY(points.mirror);
points._houseWallLeft = points.houseWallLeft.flipY(points.mirror);
points._houseRoofLeft = points.houseRoofLeft.flipY(points.mirror);
points._houseRoofTop = points.houseRoofTop.flipY(points.mirror);
points._houseRoofRight = points.houseRoofRight.flipY(points.mirror);
points._houseWallRight = points.houseWallRight.flipY(points.mirror);
points._end = points.end.flipY(points.mirror);
paths.skylineTop = new Path()
.move(points.start)
.line(points.churchTowerWallLeft)
.line(points.churchTowerRoofLeft)
.line(points.churchTowerTop)
.line(points.churchTowerRoofRight)
.line(points.churchRoofRight)
.line(points.churchWallRight)
.line(points.houseWallLeft)
.line(points.houseRoofLeft)
.line(points.houseRoofTop)
.line(points.houseRoofRight)
.line(points.houseWallRight)
.line(points.end)
;
paths.skylineBottom = new Path()
.move(points._start)
.line(points._churchTowerWallLeft)
.line(points._churchTowerRoofLeft)
.line(points._churchTowerTop)
.line(points._churchTowerRoofRight)
.line(points._churchRoofRight)
.line(points._churchWallRight)
.line(points._houseWallLeft)
.line(points._houseRoofLeft)
.line(points._houseRoofTop)
.line(points._houseRoofRight)
.line(points._houseWallRight)
.line(points._end)
;
paths.mirrorLine = new Path()
.move(points.mirror)
.line(points.mirrorLineEnd)
.attr('class', 'note dashed');
return part;
}
};
export default pointFlipX;

View file

@ -0,0 +1,27 @@
import freesewing from "freesewing";
import { box } from "./shared";
var pointRotate = {
draft: function(part) {
// prettier-ignore
let {Point, points, Path, paths, Snippet, snippets} = part.shorthand();
box(part, 80, 80);
points.sun = new Point(40, 40);
snippets.sun = new Snippet("notch", points.sun);
points.moon = new Point(70, 40);
let angle = 0;
let step = 360 / 36;
for(let i=1; i<37; i++) {
let angle = step * i;
points[`moon${i}`] = points.moon.rotate(angle, points.sun);
paths[`moon${i}`] = new Path().move(points.sun).line(points[`moon${i}`]);
snippets[`moon${i}`] = new Snippet("x", points[`moon${i}`]);
}
return part;
}
};
export default pointRotate;

View file

@ -0,0 +1,29 @@
import freesewing from "freesewing";
import { box } from "./shared";
var pointShift = {
draft: function(part) {
// prettier-ignore
let {Point, points, Snippet, snippets, macro} = part.shorthand();
box(part);
points.A = new Point(90, 40).attr('data-text', 'Point A');
points.B = points.A.shift(155, 70)
.attr('data-text', "Point B is point A shifted 7cm\nat a 155 degree angle")
.attr('data-text-lineheight', 6);
snippets.A = new Snippet("x", points.A);
snippets.B = new Snippet("x", points.B);
macro('ld', {
from: points.B,
to: points.A,
d: -10
});
return part;
}
};
export default pointShift;

View file

@ -0,0 +1,43 @@
import freesewing from "freesewing";
import { box } from "./shared";
var pointShiftFractionTowards = {
draft: function(part) {
// prettier-ignore
let {Point, points, Path, paths, Snippet, snippets, macro} = part.shorthand();
box(part);
points.A = new Point(90, 70).attr('data-text', 'Point A');
points.B = new Point(10, 10).attr('data-text', 'Point B');
points.C = points.A.shiftFractionTowards(points.B, 0.5)
.attr('data-text', "Point C is point A shifted 50%\nin the direction of point B")
.attr('data-text-class', "center")
.attr('data-text-lineheight', 6);
snippets.A = new Snippet("x", points.A);
snippets.B = new Snippet("x", points.B);
snippets.C = new Snippet("x", points.C);
paths.direction = new Path()
.move(points.A)
.line(points.B)
.attr('class', 'note dashed');
macro('ld', {
from: points.C,
to: points.A,
d: -10
});
macro('ld', {
from: points.B,
to: points.A,
d: 20
});
return part;
}
};
export default pointShiftFractionTowards;

View file

@ -0,0 +1,36 @@
import freesewing from "freesewing";
import { box } from "./shared";
var pointShiftOutwards = {
draft: function(part) {
// prettier-ignore
let {Point, points, Path, paths, Snippet, snippets, macro} = part.shorthand();
box(part);
points.A = new Point(90, 70).attr('data-text', 'Point A');
points.B = new Point(10, 10).attr('data-text', 'Point B');
points.C = points.A.shiftOutwards(points.B, 30)
.attr('data-text', "Point C is point A shifted 3cm\nbeyond point B")
.attr('data-text-lineheight', 6);
snippets.A = new Snippet("x", points.A);
snippets.B = new Snippet("x", points.B);
snippets.C = new Snippet("x", points.C);
paths.direction = new Path()
.move(points.A)
.line(points.C)
.attr('class', 'note dashed');
macro('ld', {
from: points.C,
to: points.B,
d: -10
});
return part;
}
};
export default pointShiftOutwards;

View file

@ -0,0 +1,37 @@
import freesewing from "freesewing";
import { box } from "./shared";
var pointShiftTowards = {
draft: function(part) {
// prettier-ignore
let {Point, points, Path, paths, Snippet, snippets, macro} = part.shorthand();
box(part);
points.A = new Point(90, 70).attr('data-text', 'Point A');
points.B = new Point(10, 10).attr('data-text', 'Point B');
points.C = points.A.shiftTowards(points.B, 35)
.attr('data-text', "Point C is point A shifted 3.5cm\nin the direction of point B")
.attr('data-text-class', "center")
.attr('data-text-lineheight', 6);
snippets.A = new Snippet("x", points.A);
snippets.B = new Snippet("x", points.B);
snippets.C = new Snippet("x", points.C);
paths.direction = new Path()
.move(points.A)
.line(points.B)
.attr('class', 'note dashed');
macro('ld', {
from: points.C,
to: points.A,
d: -10
});
return part;
}
};
export default pointShiftTowards;

View file

@ -0,0 +1,25 @@
import freesewing from "freesewing";
import { box } from "./shared";
var pointDx = {
draft: function(part) {
// prettier-ignore
let {Point, points, Snippet, snippets, macro} = part.shorthand();
box(part);
let s;
for(let i=0; i<10; i++) {
points[`a${i}`] = new Point(i * 10, 40);
points[`b${i}`] = new Point(i * 10, i * 8);
if(points[`a${i}`].sitsOn(points[`b${i}`])) s = 'notch';
else s = 'x';
snippets[`b${i}`] = new Snippet(s, points[`b${i}`]);
snippets[`a${i}`] = new Snippet(s, points[`a${i}`]);
}
return part;
}
};
export default pointDx;

View file

@ -0,0 +1,13 @@
/**
* This draws a (diagonal in a) box
* with with w and height h with a non-visible line.
* This is to force our examples parts to a certain size
*/
export function box(part, w = 100, h = 50) {
part.paths.box = new part.Path()
.move(new part.Point(0, 0))
.line(new part.Point(w, h))
.attr("class", "hidden");
return part;
}

View file

@ -0,0 +1,31 @@
import freesewing from "freesewing";
import { box } from "./shared";
var utilsBeamCrossesX = {
draft: function(part) {
// prettier-ignore
let {debug, Point, points, Path, paths, Snippet, snippets, utils} = part.shorthand();
points.A = new Point(10, 10);
points.B = new Point(50, 40);
paths.AB = new Path()
.move(points.A)
.line(points.B);
snippets.X = new Snippet('x', utils.beamCrossesX(
points.A,
points.B,
40)
);
paths.help = new Path()
.move(new Point(40,0))
.line(new Point(40,50))
.attr('class', 'note dashed');
return part;
}
};
export default utilsBeamCrossesX;

View file

@ -0,0 +1,30 @@
import freesewing from "freesewing";
var utilsBeamCrossesY = {
draft: function(part) {
// prettier-ignore
let {debug, Point, points, Path, paths, Snippet, snippets, utils} = part.shorthand();
points.A = new Point(10, 10);
points.B = new Point(50, 40);
paths.AB = new Path()
.move(points.A)
.line(points.B);
snippets.X = new Snippet('x', utils.beamCrossesY(
points.A,
points.B,
30)
);
paths.help = new Path()
.move(new Point(0,30))
.line(new Point(50,30))
.attr('class', 'note dashed');
return part;
}
};
export default utilsBeamCrossesY;

View file

@ -0,0 +1,32 @@
import freesewing from "freesewing";
import { box } from "./shared";
var utilsBeamsCross = {
draft: function(part) {
// prettier-ignore
let {debug, Point, points, Path, paths, Snippet, snippets, utils} = part.shorthand();
points.A = new Point(10, 10);
points.B = new Point(50, 40);
points.C = new Point(45, 20);
points.D = new Point(60, 15);
paths.AB = new Path()
.move(points.A)
.line(points.B);
paths.CD = new Path()
.move(points.C)
.line(points.D);
snippets.X = new Snippet('x', utils.beamsCross(
points.A,
points.B,
points.C,
points.D)
);
return part;
}
};
export default utilsBeamsCross;

View file

@ -0,0 +1,32 @@
import freesewing from "freesewing";
import { box } from "./shared";
var utilsLinesCross = {
draft: function(part) {
// prettier-ignore
let {debug, Point, points, Path, paths, Snippet, snippets, utils} = part.shorthand();
points.A = new Point(10, 10);
points.B = new Point(50, 40);
points.C = new Point(15, 30);
points.D = new Point(60, 15);
paths.AB = new Path()
.move(points.A)
.line(points.B);
paths.CD = new Path()
.move(points.C)
.line(points.D);
snippets.X = new Snippet('x', utils.linesCross(
points.A,
points.B,
points.C,
points.D)
);
return part;
}
};
export default utilsLinesCross;