1
0
Fork 0
freesewing/packages/tutorial/src/bib.js

229 lines
6.9 KiB
JavaScript
Raw Normal View History

export default function (part) {
2019-05-30 21:19:06 +02:00
let {
Point,
points,
Path,
paths,
measurements,
options,
macro,
complete,
snippets,
Snippet,
2021-04-24 10:16:31 +02:00
paperless,
2019-08-03 15:03:33 +02:00
} = part.shorthand()
2019-05-30 21:19:06 +02:00
// Construct the neck opening
2019-08-03 15:03:33 +02:00
let tweak = 1
let target = (measurements.head * options.neckRatio) / 4
2019-08-03 15:03:33 +02:00
let delta
2019-05-30 21:19:06 +02:00
do {
points.right = new Point((tweak * measurements.head) / 10, 0)
points.bottom = new Point(0, (tweak * measurements.head) / 12)
2019-08-03 15:03:33 +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)
2019-05-30 21:19:06 +02:00
paths.neck = new Path()
.move(points.right)
2019-08-03 15:03:33 +02:00
.curve(points.rightCp1, points.bottomCp2, points.bottom)
2019-05-30 21:19:06 +02:00
2019-08-03 15:03:33 +02:00
delta = paths.neck.length() - target
if (delta > 0) tweak = tweak * 0.99
else tweak = tweak * 1.02
} while (Math.abs(delta) > 1)
2019-05-30 21:19:06 +02:00
2019-08-03 15:03:33 +02:00
points.rightCp2 = points.rightCp1.flipY()
points.bottomCp1 = points.bottomCp2.flipX()
2019-05-30 21:19:06 +02:00
2019-08-03 15:03:33 +02:00
points.left = points.right.flipX()
points.leftCp1 = points.rightCp2.flipX()
points.leftCp2 = points.rightCp1.flipX()
2019-05-30 21:19:06 +02:00
2019-08-03 15:03:33 +02:00
points.top = points.bottom.flipY()
points.topCp1 = points.bottomCp2.flipY()
points.topCp2 = points.bottomCp1.flipY()
2019-05-30 21:19:06 +02:00
// Construct the outline
let width = measurements.head * options.widthRatio
let length = measurements.head * options.lengthRatio
2019-08-03 15:03:33 +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)
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)
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()
2019-05-30 21:19:06 +02:00
// Round the end of the straps
2019-08-03 15:03:33 +02:00
let strap = points.edgeTop.dy(points.top)
2019-05-30 21:19:06 +02:00
2019-08-03 15:03:33 +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)
2019-05-30 21:19:06 +02:00
2019-08-03 15:03:33 +02:00
macro('round', {
2019-05-30 21:19:06 +02:00
from: points.edgeTop,
to: points.tipRight,
via: points.tipRightTop,
2021-04-24 10:16:31 +02:00
prefix: 'tipRightTop',
2019-08-03 15:03:33 +02:00
})
macro('round', {
2019-05-30 21:19:06 +02:00
from: points.tipRight,
to: points.top,
via: points.tipRightBottom,
2021-04-24 10:16:31 +02:00
prefix: 'tipRightBottom',
2019-08-03 15:03:33 +02:00
})
2019-05-30 21:19:06 +02:00
// Rotate straps so they don't overlap
let rotateThese = [
2019-08-03 15:03:33 +02:00
'edgeTopLeftCp',
'edgeTop',
'tipRight',
'tipRightTop',
'tipRightTopStart',
'tipRightTopCp1',
'tipRightTopCp2',
'tipRightTopEnd',
'tipRightBottomStart',
'tipRightBottomCp1',
'tipRightBottomCp2',
'tipRightBottomEnd',
'tipRightBottom',
'top',
2021-04-24 10:16:31 +02:00
'topCp2',
2019-08-03 15:03:33 +02:00
]
2019-05-30 21:19:06 +02:00
while (points.tipRightBottomStart.x > -1) {
2019-08-03 15:03:33 +02:00
for (let p of rotateThese) points[p] = points[p].rotate(1, points.edgeLeft)
2019-05-30 21:19:06 +02:00
}
// Add points to anchor snaps on
2019-08-03 15:03:33 +02:00
points.snapLeft = points.top.shiftFractionTowards(points.edgeTop, 0.5)
2019-05-30 21:19:06 +02:00
// Mirror points to the other side
2019-08-03 15:03:33 +02:00
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()
2019-05-30 21:19:06 +02:00
// Round the bottom of the bib
// Radius is fixed, but you could use an option for it)
2019-08-03 15:03:33 +02:00
macro('round', {
2019-05-30 21:19:06 +02:00
from: points.topLeft,
to: points.bottomRight,
via: points.bottomLeft,
radius: points.bottomRight.x / 4,
2021-04-24 10:16:31 +02:00
prefix: 'bottomLeft',
2019-08-03 15:03:33 +02:00
})
macro('round', {
2019-05-30 21:19:06 +02:00
from: points.bottomLeft,
to: points.topRight,
via: points.bottomRight,
radius: points.bottomRight.x / 4,
2021-04-24 10:16:31 +02:00
prefix: 'bottomRight',
2019-08-03 15:03:33 +02:00
})
2019-05-30 21:19:06 +02:00
// Construct the path
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(points.edgeRightCp, points.edgeTopRightCp, points.tipLeftTopStart)
.curve(points.tipLeftTopCp1, points.tipLeftTopCp2, points.tipLeftTopEnd)
2019-08-03 15:03:33 +02:00
.curve(points.tipLeftBottomCp1, points.tipLeftBottomCp2, points.tipLeftBottomEnd)
2019-05-30 21:19:06 +02:00
.curve(points.topCp1, points.rightCp2, points.right)
.curve(points.rightCp1, points.bottomCp2, points.bottom)
.curve(points.bottomCp1, points.leftCp2, points.left)
.curve(points.leftCp1, points.topCp2, points.tipRightBottomEnd)
2019-08-03 15:03:33 +02:00
.curve(points.tipRightBottomCp2, points.tipRightBottomCp1, points.tipRightBottomStart)
.curve(points.tipRightTopCp2, points.tipRightTopCp1, points.tipRightTopStart)
2019-05-30 21:19:06 +02:00
.curve(points.edgeTopLeftCp, points.edgeLeftCp, points.edgeLeft)
.close()
2019-08-03 15:03:33 +02:00
.attr('class', 'fabric')
2019-05-30 21:19:06 +02:00
// Complete?
if (complete) {
// Add the snaps
snippets.snapStud = new Snippet('snap-stud', points.snapLeft)
snippets.snapSocket = new Snippet('snap-socket', points.snapRight).attr('opacity', 0.5)
2019-05-30 21:19:06 +02:00
// Add the bias tape
paths.bias = paths.seam
.offset(-5)
2019-08-03 15:03:33 +02:00
.attr('class', 'various dashed')
.attr('data-text', 'finishWithBiasTape')
.attr('data-text-class', 'center fill-various')
2019-05-30 21:19:06 +02:00
// Add the title
2019-08-03 15:03:33 +02:00
points.title = points.bottom.shift(-90, 45)
macro('title', {
2019-05-30 21:19:06 +02:00
at: points.title,
nr: 1,
2021-04-24 10:16:31 +02:00
title: 'bib',
2019-08-03 15:03:33 +02:00
})
2019-05-30 21:19:06 +02:00
// Add the scalebox
2019-08-03 15:03:33 +02:00
points.scalebox = points.title.shift(-90, 55)
macro('scalebox', { at: points.scalebox })
2019-05-30 21:19:06 +02:00
// Add the logo
2019-08-03 15:03:33 +02:00
points.logo = new Point(0, 0)
snippets.logo = new Snippet('logo', points.logo)
2019-05-30 21:19:06 +02:00
// Paperless?
if (paperless) {
// Add dimensions
2019-08-03 15:03:33 +02:00
macro('hd', {
2019-05-30 21:19:06 +02:00
from: points.bottomLeftStart,
to: points.bottomRightEnd,
2021-04-24 10:16:31 +02:00
y: points.bottomLeft.y + 15,
2019-08-03 15:03:33 +02:00
})
macro('vd', {
2019-06-01 16:09:49 +02:00
from: points.bottomRightStart,
to: points.bottom,
2021-04-24 10:16:31 +02:00
x: points.bottomRight.x + 15,
2019-08-03 15:03:33 +02:00
})
macro('vd', {
2019-06-01 16:09:49 +02:00
from: points.bottomRightStart,
to: points.right,
2021-04-24 10:16:31 +02:00
x: points.bottomRight.x + 30,
2019-08-03 15:03:33 +02:00
})
macro('vd', {
2019-06-01 16:09:49 +02:00
from: points.bottomRightStart,
to: points.tipLeftTopStart,
2021-04-24 10:16:31 +02:00
x: points.bottomRight.x + 45,
2019-08-03 15:03:33 +02:00
})
macro('hd', {
2019-06-01 16:09:49 +02:00
from: points.left,
to: points.right,
2021-04-24 10:16:31 +02:00
y: points.left.y + 25,
2019-08-03 15:03:33 +02:00
})
macro('ld', {
2019-06-01 16:09:49 +02:00
from: points.tipLeftBottomEnd,
to: points.tipLeftTopStart,
2021-04-24 10:16:31 +02:00
d: -15,
2019-08-03 15:03:33 +02:00
})
2019-05-30 21:19:06 +02:00
}
}
2019-08-03 15:03:33 +02:00
return part
2019-05-30 21:19:06 +02:00
}