2022-10-11 01:37:09 +02:00
|
|
|
---
|
|
|
|
title: Completing our pattern
|
|
|
|
order: 260
|
|
|
|
---
|
|
|
|
|
|
|
|
When we say we're going to *complete* our pattern, we mean we're going to add
|
|
|
|
things like a title and a scalebox and so on.
|
|
|
|
|
|
|
|
These things or not always wanted on a pattern. For example, if you're cutting
|
|
|
|
out patterns with a laser cutter, or tracing them with a projects, you
|
|
|
|
typically only want to have the pattern outline.
|
|
|
|
|
|
|
|
## The complete setting
|
|
|
|
|
|
|
|
Users can indicate their desire to have either a bare-bones pattern, or rather
|
2023-01-06 19:29:29 -08:00
|
|
|
when that's completed with all bells and whistles with [the
|
2022-10-11 01:37:09 +02:00
|
|
|
`complete` setting](/reference/settings/complete).
|
|
|
|
|
2023-01-06 19:29:29 -08:00
|
|
|
To make sure we respect the user's choice, we must wrap all of these
|
2022-10-11 01:37:09 +02:00
|
|
|
embellishments in a code block that only executes when the `complete` setting
|
|
|
|
is *truthy*.
|
|
|
|
|
|
|
|
To access the setting, we can destructure it:
|
|
|
|
|
|
|
|
```mjs
|
2023-01-06 19:29:29 -08:00
|
|
|
function draftBib({
|
|
|
|
Path,
|
|
|
|
Point,
|
|
|
|
paths,
|
|
|
|
points,
|
2022-10-11 01:37:09 +02:00
|
|
|
measurements,
|
|
|
|
options,
|
|
|
|
macro,
|
|
|
|
// highlight-start
|
|
|
|
complete,
|
|
|
|
// highlight-end
|
|
|
|
part,
|
|
|
|
}) {
|
2023-01-06 19:29:29 -08:00
|
|
|
|
2022-10-11 01:37:09 +02:00
|
|
|
// Our earlier work is not shown for brevety
|
|
|
|
|
|
|
|
// highlight-start
|
|
|
|
if (complete) {
|
|
|
|
// Complete pattern here
|
|
|
|
}
|
|
|
|
// highlight-end
|
|
|
|
|
|
|
|
return part
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
## Adding snippets
|
|
|
|
|
2023-01-06 19:29:29 -08:00
|
|
|
Snippets are little re-useable things to embellish our pattern with.
|
2022-10-11 01:37:09 +02:00
|
|
|
Things like buttons or buttonholes, a logo, or snaps.
|
|
|
|
|
|
|
|
To use them, much like points and paths, we need to destructure both
|
2022-12-29 06:25:01 -08:00
|
|
|
the `Snippet` constructor as well as the `snippets` object to hold
|
2022-10-11 01:37:09 +02:00
|
|
|
our snippets:
|
|
|
|
|
|
|
|
```mjs
|
2023-01-06 19:29:29 -08:00
|
|
|
function draftBib({
|
|
|
|
Path,
|
|
|
|
Point,
|
|
|
|
paths,
|
|
|
|
points,
|
2022-10-11 01:37:09 +02:00
|
|
|
measurements,
|
|
|
|
options,
|
|
|
|
macro,
|
|
|
|
complete,
|
|
|
|
// highlight-start
|
|
|
|
Snippet,
|
|
|
|
snippets,
|
|
|
|
// highlight-end
|
|
|
|
part,
|
|
|
|
}) {
|
2023-01-06 19:29:29 -08:00
|
|
|
|
2022-10-11 01:37:09 +02:00
|
|
|
// Our earlier work is not shown for brevety
|
|
|
|
|
|
|
|
if (complete) {
|
|
|
|
// Complete pattern here
|
|
|
|
}
|
|
|
|
|
|
|
|
return part
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
We'll be using them below to add a `snap-stud`, `snap-socket`, and a `logo`
|
|
|
|
snippet.
|
|
|
|
|
|
|
|
<Note>
|
|
|
|
You can find all possible snippets in [our documentation](/reference/api/snippet/).
|
|
|
|
</Note>
|
|
|
|
|
2022-10-11 15:06:54 +02:00
|
|
|
## The completed design
|
2022-10-11 01:37:09 +02:00
|
|
|
|
2022-10-11 15:06:54 +02:00
|
|
|
Let's put this and few other things together to complete our design:
|
2022-10-11 01:37:09 +02:00
|
|
|
|
2022-10-11 15:06:54 +02:00
|
|
|
<Example tutorial caption="Almost done. But there's one more thing the user can ask for: a **paperless** pattern">
|
2022-10-11 01:37:09 +02:00
|
|
|
```js
|
2023-01-06 19:29:29 -08:00
|
|
|
function draftBib({
|
|
|
|
Path,
|
|
|
|
Point,
|
|
|
|
paths,
|
|
|
|
points,
|
2022-10-11 01:37:09 +02:00
|
|
|
measurements,
|
|
|
|
options,
|
|
|
|
macro,
|
|
|
|
// highlight-start
|
|
|
|
complete,
|
|
|
|
snippets,
|
|
|
|
Snippet,
|
|
|
|
// highlight-end
|
|
|
|
part,
|
|
|
|
}) {
|
|
|
|
|
|
|
|
// Construct the quarter neck opening
|
|
|
|
let tweak = 1
|
|
|
|
let target = (measurements.head * options.neckRatio) /4
|
|
|
|
let delta
|
|
|
|
do {
|
|
|
|
points.right = new Point(tweak * measurements.head / 10, 0)
|
|
|
|
points.bottom = new Point(0, tweak * measurements.head / 12)
|
2023-01-06 19:29:29 -08:00
|
|
|
|
2022-10-11 01:37:09 +02:00
|
|
|
points.rightCp1 = points.right.shift(90, points.bottom.dy(points.right)/2)
|
|
|
|
points.bottomCp2 = points.bottom.shift(0, points.bottom.dx(points.right)/2)
|
2023-01-06 19:29:29 -08:00
|
|
|
|
2022-10-11 01:37:09 +02:00
|
|
|
paths.quarterNeck = new Path()
|
|
|
|
.move(points.right)
|
|
|
|
.curve(points.rightCp1, points.bottomCp2, points.bottom)
|
|
|
|
.hide() // Add this line
|
2023-01-06 19:29:29 -08:00
|
|
|
|
2022-10-11 01:37:09 +02:00
|
|
|
delta = paths.quarterNeck.length() - target
|
|
|
|
if (delta > 0) tweak = tweak * 0.99
|
|
|
|
else tweak = tweak * 1.02
|
|
|
|
} while (Math.abs(delta) > 1)
|
|
|
|
|
|
|
|
// Construct the complete neck opening
|
|
|
|
points.rightCp2 = points.rightCp1.flipY()
|
|
|
|
points.bottomCp1 = points.bottomCp2.flipX()
|
|
|
|
points.left = points.right.flipX()
|
|
|
|
points.leftCp1 = points.rightCp2.flipX()
|
|
|
|
points.leftCp2 = points.rightCp1.flipX()
|
|
|
|
points.top = points.bottom.flipY()
|
|
|
|
points.topCp1 = points.bottomCp2.flipY()
|
|
|
|
points.topCp2 = points.bottomCp1.flipY()
|
|
|
|
|
2023-01-06 19:29:29 -08:00
|
|
|
// Drawing the bib outline
|
2022-10-11 01:37:09 +02:00
|
|
|
const width = measurements.head * options.widthRatio
|
|
|
|
const length = measurements.head * options.lengthRatio
|
2023-01-06 19:29:29 -08:00
|
|
|
|
2022-10-11 01:37:09 +02:00
|
|
|
points.topLeft = new Point(
|
|
|
|
width / -2,
|
|
|
|
points.top.y - (width / 2 - points.right.x)
|
|
|
|
)
|
|
|
|
points.topRight = points.topLeft.shift(0, width)
|
|
|
|
points.bottomLeft = points.topLeft.shift(-90, length)
|
|
|
|
points.bottomRight = points.topRight.shift(-90, length)
|
2023-01-06 19:29:29 -08:00
|
|
|
|
2022-10-11 01:37:09 +02:00
|
|
|
// Shape the straps
|
|
|
|
points.edgeLeft = new Point(points.topLeft.x, points.left.y)
|
|
|
|
points.edgeRight = new Point(points.topRight.x, points.right.y)
|
|
|
|
points.edgeTop = new Point(0, points.topLeft.y)
|
2023-01-06 19:29:29 -08:00
|
|
|
|
2022-10-11 01:37:09 +02:00
|
|
|
points.edgeLeftCp = points.edgeLeft.shiftFractionTowards(points.topLeft, 0.5)
|
|
|
|
points.edgeRightCp = points.edgeLeftCp.flipX()
|
|
|
|
points.edgeTopLeftCp = points.edgeTop.shiftFractionTowards(
|
|
|
|
points.topLeft,
|
|
|
|
0.5
|
|
|
|
)
|
|
|
|
points.edgeTopRightCp = points.edgeTopLeftCp.flipX()
|
2023-01-06 19:29:29 -08:00
|
|
|
|
2022-10-11 01:37:09 +02:00
|
|
|
// Round the straps
|
|
|
|
const strap = points.edgeTop.dy(points.top)
|
2023-01-06 19:29:29 -08:00
|
|
|
|
2022-10-11 01:37:09 +02:00
|
|
|
points.tipRight = points.edgeTop.translate(strap / 2, strap / 2)
|
|
|
|
points.tipRightTop = new Point(points.tipRight.x, points.edgeTop.y)
|
|
|
|
points.tipRightBottom = new Point(points.tipRight.x, points.top.y)
|
2023-01-06 19:29:29 -08:00
|
|
|
|
2022-10-11 01:37:09 +02:00
|
|
|
macro("round", {
|
|
|
|
from: points.edgeTop,
|
|
|
|
to: points.tipRight,
|
|
|
|
via: points.tipRightTop,
|
|
|
|
prefix: "tipRightTop",
|
|
|
|
})
|
|
|
|
macro("round", {
|
|
|
|
from: points.tipRight,
|
|
|
|
to: points.top,
|
|
|
|
via: points.tipRightBottom,
|
|
|
|
prefix: "tipRightBottom",
|
|
|
|
})
|
|
|
|
const rotateThese = [
|
|
|
|
"edgeTopLeftCp",
|
|
|
|
"edgeTop",
|
|
|
|
"tipRight",
|
|
|
|
"tipRightTop",
|
|
|
|
"tipRightTopStart",
|
|
|
|
"tipRightTopCp1",
|
|
|
|
"tipRightTopCp2",
|
|
|
|
"tipRightTopEnd",
|
|
|
|
"tipRightBottomStart",
|
|
|
|
"tipRightBottomCp1",
|
|
|
|
"tipRightBottomCp2",
|
|
|
|
"tipRightBottomEnd",
|
|
|
|
"tipRightBottom",
|
|
|
|
"top",
|
|
|
|
"topCp2"
|
|
|
|
]
|
|
|
|
while (points.tipRightBottomStart.x > -1) {
|
|
|
|
for (const p of rotateThese) points[p] = points[p].rotate(1, points.edgeLeft)
|
|
|
|
}
|
2023-01-06 19:29:29 -08:00
|
|
|
|
2022-10-11 01:37:09 +02:00
|
|
|
// Snap anchor
|
|
|
|
points.snapLeft = points.top.shiftFractionTowards(points.edgeTop, 0.5)
|
|
|
|
|
|
|
|
// Add points for second strap
|
|
|
|
points.edgeTopRightCp = points.edgeTopLeftCp.flipX()
|
|
|
|
points.topCp1 = points.topCp2.flipX()
|
|
|
|
points.tipLeftTopStart = points.tipRightTopStart.flipX()
|
|
|
|
points.tipLeftTopCp1 = points.tipRightTopCp1.flipX()
|
|
|
|
points.tipLeftTopCp2 = points.tipRightTopCp2.flipX()
|
|
|
|
points.tipLeftTopEnd = points.tipRightTopEnd.flipX()
|
|
|
|
points.tipLeftBottomStart = points.tipRightBottomStart.flipX()
|
|
|
|
points.tipLeftBottomCp1 = points.tipRightBottomCp1.flipX()
|
|
|
|
points.tipLeftBottomCp2 = points.tipRightBottomCp2.flipX()
|
|
|
|
points.tipLeftBottomEnd = points.tipRightBottomEnd.flipX()
|
|
|
|
points.snapRight = points.snapLeft.flipX()
|
|
|
|
|
|
|
|
// Round the bottom corners
|
|
|
|
macro("round", {
|
|
|
|
from: points.topLeft,
|
|
|
|
to: points.bottomRight,
|
|
|
|
via: points.bottomLeft,
|
|
|
|
radius: points.bottomRight.x / 4,
|
|
|
|
prefix: "bottomLeft"
|
|
|
|
})
|
|
|
|
macro("round", {
|
|
|
|
from: points.bottomLeft,
|
|
|
|
to: points.topRight,
|
|
|
|
via: points.bottomRight,
|
|
|
|
radius: points.bottomRight.x / 4,
|
|
|
|
prefix: "bottomRight"
|
|
|
|
})
|
|
|
|
|
|
|
|
// Create one path for the bib outline
|
|
|
|
paths.seam = new Path()
|
|
|
|
.move(points.edgeLeft)
|
|
|
|
.line(points.bottomLeftStart)
|
|
|
|
.curve(points.bottomLeftCp1, points.bottomLeftCp2, points.bottomLeftEnd)
|
|
|
|
.line(points.bottomRightStart)
|
|
|
|
.curve(points.bottomRightCp1, points.bottomRightCp2, points.bottomRightEnd)
|
|
|
|
.line(points.edgeRight)
|
|
|
|
.curve(
|
2023-01-06 19:29:29 -08:00
|
|
|
points.edgeRightCp,
|
|
|
|
points.edgeTopRightCp,
|
2022-10-11 01:37:09 +02:00
|
|
|
points.tipLeftTopStart
|
|
|
|
)
|
|
|
|
.curve(
|
2023-01-06 19:29:29 -08:00
|
|
|
points.tipLeftTopCp1,
|
|
|
|
points.tipLeftTopCp2,
|
2022-10-11 01:37:09 +02:00
|
|
|
points.tipLeftTopEnd
|
|
|
|
)
|
|
|
|
.curve(
|
|
|
|
points.tipLeftBottomCp1,
|
|
|
|
points.tipLeftBottomCp2,
|
|
|
|
points.tipLeftBottomEnd
|
|
|
|
)
|
|
|
|
.curve(
|
2023-01-06 19:29:29 -08:00
|
|
|
points.topCp1,
|
|
|
|
points.rightCp2,
|
2022-10-11 01:37:09 +02:00
|
|
|
points.right
|
|
|
|
)
|
|
|
|
.curve(
|
2023-01-06 19:29:29 -08:00
|
|
|
points.rightCp1,
|
|
|
|
points.bottomCp2,
|
2022-10-11 01:37:09 +02:00
|
|
|
points.bottom
|
|
|
|
)
|
|
|
|
.curve(
|
2023-01-06 19:29:29 -08:00
|
|
|
points.bottomCp1,
|
|
|
|
points.leftCp2,
|
2022-10-11 01:37:09 +02:00
|
|
|
points.left
|
|
|
|
)
|
|
|
|
.curve(
|
2023-01-06 19:29:29 -08:00
|
|
|
points.leftCp1,
|
|
|
|
points.topCp2,
|
2022-10-11 01:37:09 +02:00
|
|
|
points.tipRightBottomEnd
|
|
|
|
)
|
|
|
|
.curve(
|
|
|
|
points.tipRightBottomCp2,
|
|
|
|
points.tipRightBottomCp1,
|
|
|
|
points.tipRightBottomStart
|
|
|
|
)
|
|
|
|
.curve(
|
|
|
|
points.tipRightTopCp2,
|
|
|
|
points.tipRightTopCp1,
|
|
|
|
points.tipRightTopStart
|
|
|
|
)
|
|
|
|
.curve(
|
2023-01-06 19:29:29 -08:00
|
|
|
points.edgeTopLeftCp,
|
|
|
|
points.edgeLeftCp,
|
2022-10-11 01:37:09 +02:00
|
|
|
points.edgeLeft
|
|
|
|
)
|
|
|
|
.close()
|
|
|
|
.addClass("fabric")
|
|
|
|
|
2022-10-11 15:06:54 +02:00
|
|
|
// highlight-start
|
|
|
|
if (complete) {
|
|
|
|
/*
|
2023-01-06 19:29:29 -08:00
|
|
|
* Let's add the points where
|
2022-10-11 15:06:54 +02:00
|
|
|
* the closure's snaps should go.
|
|
|
|
*/
|
|
|
|
// Add snaps
|
|
|
|
points.snapLeft = points.top
|
|
|
|
.shiftFractionTowards(points.edgeTop, 0.5)
|
|
|
|
points.snapRight = points.snapLeft
|
|
|
|
.flipX()
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Now, let's use our newfound snippet powers
|
|
|
|
* to add the snaps to these points.
|
|
|
|
* First the left snap (the stud part)
|
|
|
|
*/
|
|
|
|
snippets.snapStud = new Snippet(
|
2023-01-06 19:29:29 -08:00
|
|
|
'snap-stud',
|
2022-10-11 15:06:54 +02:00
|
|
|
points.snapLeft
|
|
|
|
)
|
2022-10-11 01:37:09 +02:00
|
|
|
|
2022-10-11 15:06:54 +02:00
|
|
|
/*
|
|
|
|
* The right snap (the socket part)
|
|
|
|
* should go on the back of the fabric.
|
|
|
|
* To try to make that more obvious to the user
|
|
|
|
* let's set its `opacity` attribute to 0.5
|
|
|
|
* this way it will be semi-transparent.
|
|
|
|
*/
|
|
|
|
snippets.snapSocket = new Snippet(
|
2023-01-06 19:29:29 -08:00
|
|
|
'snap-socket',
|
2022-10-11 15:06:54 +02:00
|
|
|
points.snapRight
|
|
|
|
).attr('opacity', 0.5)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Another snippet we should add is our logo.
|
|
|
|
* A logo is not required, but we love skully.
|
|
|
|
*/
|
|
|
|
// Add a logo
|
|
|
|
points.logo = new Point(0, 0)
|
|
|
|
snippets.logo = new Snippet(
|
2023-01-06 19:29:29 -08:00
|
|
|
"logo",
|
2022-10-11 15:06:54 +02:00
|
|
|
points.logo
|
|
|
|
)
|
2022-10-11 01:37:09 +02:00
|
|
|
|
2022-10-11 15:06:54 +02:00
|
|
|
/*
|
|
|
|
* We already know how to use macros
|
|
|
|
* This one adds a title to our part
|
|
|
|
*/
|
|
|
|
// Add a title
|
|
|
|
points.title = points.bottom
|
|
|
|
.shift(-90, 45)
|
|
|
|
macro("title", {
|
|
|
|
at: points.title,
|
|
|
|
nr: 1,
|
|
|
|
title: "bib",
|
|
|
|
scale: 0.7
|
|
|
|
})
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This macro adds a scalebox to our part
|
|
|
|
*/
|
|
|
|
// Add a scalbox
|
|
|
|
points.scalebox = points.title
|
|
|
|
.shift(-90, 55)
|
|
|
|
macro(
|
2023-01-06 19:29:29 -08:00
|
|
|
"scalebox",
|
2022-10-11 15:06:54 +02:00
|
|
|
{ at: points.scalebox }
|
|
|
|
)
|
2022-10-11 01:37:09 +02:00
|
|
|
|
2022-10-11 15:06:54 +02:00
|
|
|
/*
|
|
|
|
* Our bib should be finished with bias tape.
|
|
|
|
* To add it, we're using Path.offset()
|
|
|
|
* You will learn to LOVE this methid
|
|
|
|
* when designing pattern with seam allowance
|
|
|
|
* as it draws a path parallel to another one
|
|
|
|
*/
|
|
|
|
paths.bias = paths.seam
|
|
|
|
.offset(-5)
|
|
|
|
.addClass("various dashed")
|
|
|
|
.addText(
|
2023-01-06 19:29:29 -08:00
|
|
|
"finishWithBiasTape",
|
2022-10-11 15:06:54 +02:00
|
|
|
"center fill-various"
|
|
|
|
)
|
2022-10-11 01:37:09 +02:00
|
|
|
|
2022-10-11 15:06:54 +02:00
|
|
|
}
|
|
|
|
// highlight-end
|
2022-10-11 01:37:09 +02:00
|
|
|
|
2022-10-11 15:06:54 +02:00
|
|
|
return part
|
|
|
|
}
|
2022-10-11 01:37:09 +02:00
|
|
|
```
|
2022-10-11 15:06:54 +02:00
|
|
|
</Example>
|