2021-10-17 18:26:00 +02:00
---
2021-08-25 16:09:31 +02:00
title: Creating the closure
2024-11-18 11:05:16 +01:00
sidebar_position: 91
2021-10-17 18:26:00 +02:00
---
2021-08-25 16:09:31 +02:00
Things are starting to look good, but we can't fit the bib over the baby's head like this.
2023-01-06 19:29:29 -08:00
So we must create a closure. We'll let the straps overlap at the end, and put in a snap
2022-10-11 15:06:54 +02:00
later.
2021-08-25 16:09:31 +02:00
2022-10-11 01:37:09 +02:00
## Using macros
2021-08-25 16:09:31 +02:00
2022-10-11 01:37:09 +02:00
To round the straps, we'll use something new: **a macro**. To use macros, we
need the `macro` method, which we can destructure to get access to it.
2021-08-25 16:09:31 +02:00
2022-10-11 01:37:09 +02:00
Macros are little helpers that automate things that would otherwise get rather
2023-01-06 19:29:29 -08:00
tedious. There are macros to add titles to our pattern, or grainline
2022-10-11 01:37:09 +02:00
indicators, a scalebox, and there's a macro to round corners. The `round`
macro.
2021-08-25 16:09:31 +02:00
2025-05-19 17:20:45 -07:00
:::note
You can find more information on the `round` macro in [the macros docs](/reference/macros/round/).
:::
2022-10-11 01:37:09 +02:00
We need a half circle here, but the `round` macro works on 90° angles, so
2025-05-19 08:05:49 +02:00
we'll use it twice. As such, we'll add some points to guide the macro, and
2022-10-11 01:37:09 +02:00
then put it to work.
Like our neck opening, we've only drawn half since we can simply copy the
points to the other side.
<Example tutorial caption="Now the straps overlap. Which doesn't work for a pattern as it would make it impossible to cut it out of a single piece of fabric. So let's deal with the overlap next.">
2024-03-16 21:06:19 +00:00
```design/src/bib.mjs
2023-01-06 19:29:29 -08:00
function draftBib({
Path,
Point,
paths,
points,
2021-08-25 16:09:31 +02:00
measurements,
options,
2024-03-16 21:06:19 +00:00
// highlight-start
2022-10-11 01:37:09 +02:00
macro,
2024-03-16 21:06:19 +00:00
// highlight-end
2022-10-11 01:37:09 +02:00
part,
}) {
2021-08-25 16:09:31 +02:00
2025-05-19 08:05:49 +02:00
/*
* Construct the quarter neck opening
*/
2022-10-11 01:37:09 +02:00
let tweak = 1
2025-05-19 08:05:49 +02:00
let target = (measurements.head * options.neckRatio) /4
2022-10-11 01:37:09 +02:00
let delta
do {
2025-05-19 08:05:49 +02:00
points.right = new Point(
2025-05-19 17:20:45 -07:00
tweak * measurements.head / 10,
2025-05-19 08:05:49 +02:00
0
)
points.bottom = new Point(
2025-05-19 17:20:45 -07:00
0,
2025-05-19 08:05:49 +02:00
tweak * measurements.head / 12
)
2025-05-19 17:20:45 -07:00
2025-05-19 08:05:49 +02:00
points.rightCp1 = points.right.shift(
2025-05-19 17:20:45 -07:00
90,
2025-05-19 08:05:49 +02:00
points.bottom.dy(points.right) / 2
)
points.bottomCp2 = points.bottom.shift(
2025-05-19 17:20:45 -07:00
0,
2025-05-19 08:05:49 +02:00
points.bottom.dx(points.right) / 2
)
2025-05-19 17:20:45 -07:00
2025-05-19 08:05:49 +02:00
paths.quarterNeck = new Path()
.move(points.right)
.curve(
2025-05-19 17:20:45 -07:00
points.rightCp1,
points.bottomCp2,
2025-05-19 08:05:49 +02:00
points.bottom
)
.hide()
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
*/
2022-10-11 01:37:09 +02:00
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()
2021-08-25 16:09:31 +02:00
2025-05-19 08:05:49 +02:00
paths.neck = new Path()
.move(points.top)
.curve(points.topCp2, points.leftCp1, points.left)
.curve(points.leftCp2, points.bottomCp1, points.bottom)
.curve(points.bottomCp2, points.rightCp1, points.right)
.curve(points.rightCp2, points.topCp1, points.top)
.close()
.addClass('fabric')
/*
* Drawing the bib outline
*/
const width = measurements.head * options.widthRatio
const length = measurements.head * options.lengthRatio
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)
/*
* Shape the straps
*/
2022-10-11 01:37:09 +02:00
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
2025-05-19 08:05:49 +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()
2024-03-20 00:49:55 +00:00
2025-05-19 08:05:49 +02:00
// highlight-start
// Round the straps
const strap = points.edgeTop.dy(points.top)
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)
macro("round", {
id: "tipRightTop",
from: points.edgeTop,
to: points.tipRight,
via: points.tipRightTop,
hide: false
})
macro("round", {
id: "tipRightBottom",
from: points.tipRight,
to: points.top,
via: points.tipRightBottom,
hide: false
})
// highlight-end
2024-09-29 07:14:59 +02:00
2025-05-19 08:05:49 +02:00
/*
* Now, adapt our `rect` path so it's no longer a rectangle:
*/
2024-03-20 00:49:55 +00:00
paths.rect = new Path()
2025-05-19 08:05:49 +02:00
.move(points.edgeTop)
.curve(points.edgeTopLeftCp, points.edgeLeftCp, points.edgeLeft)
.line(points.bottomLeft)
.line(points.bottomRight)
.line(points.edgeRight)
.curve(points.edgeRightCp, points.edgeTopRightCp, points.edgeTop)
.close()
return part
2022-10-11 01:37:09 +02:00
}
```
</Example>
2024-03-20 00:49:55 +00:00
2024-09-29 07:14:59 +02:00
Notice that we always draw our path at the end after we've manipulated our points.