2021-10-17 18:26:00 +02:00
|
|
|
---
|
|
|
|
title: Pattern.sample()
|
|
|
|
---
|
2021-08-25 16:09:31 +02:00
|
|
|
|
2022-09-20 18:09:28 +02:00
|
|
|
The `Pattern.sample()` method will _sample_ the pattern which means
|
|
|
|
to draft multiple variants of the same pattern, and stack them on
|
|
|
|
top of each other.
|
|
|
|
|
|
|
|
<Note>This method is chainable as it returns the Pattern object</Note>
|
|
|
|
|
2022-02-19 08:04:25 +01:00
|
|
|
Under the hood, this method will call one of
|
2022-12-08 20:40:31 -08:00
|
|
|
[Pattern.sampleOption()](/reference/api/pattern/sampleoption),
|
|
|
|
[Pattern.sampleMeasurement()](/reference/api/pattern/samplemeasurement), or
|
|
|
|
[Pattern.sampleModels()](/reference/api/pattern/samplemodels) to sample
|
2022-09-20 18:09:28 +02:00
|
|
|
an option, a measurement, or different models respectively.
|
2021-08-25 16:09:31 +02:00
|
|
|
|
2022-02-19 08:04:25 +01:00
|
|
|
Unlike those three methods where you pass the relevant info to to the method,
|
2022-09-20 18:09:28 +02:00
|
|
|
this `Pattern.sample()` method will instead read the `settings.sample`
|
|
|
|
object to determine what needs to be done.
|
2021-08-25 16:09:31 +02:00
|
|
|
|
2022-09-20 18:09:28 +02:00
|
|
|
The `settings.sample` object can hold the following properties:
|
2021-08-25 16:09:31 +02:00
|
|
|
|
2022-02-20 14:44:38 +01:00
|
|
|
- **type**: One of `option`, `measurement`, or `models`
|
|
|
|
- **option**: An option name as defined in the pattern config file (only used when `type` is option).
|
|
|
|
- **measurement**: A measurement name as defined in the pattern config file (only used when `type` is measurement).
|
2022-09-20 18:09:28 +02:00
|
|
|
- **models**: A plain object of different models where the key is the model name and the value an object with the required measurements.
|
2021-08-25 16:09:31 +02:00
|
|
|
|
2021-09-25 17:05:18 +02:00
|
|
|
See the specific sample methods below for more details:
|
|
|
|
|
2022-12-08 20:40:31 -08:00
|
|
|
- [Pattern.sampleOption()](/reference/api/pattern/sampleoption)
|
|
|
|
- [Pattern.sampleMeasurement()](/reference/api/pattern/samplemeasurement)
|
|
|
|
- [Pattern.sampleModels()](/reference/api/pattern/samplemodels)
|
2021-09-25 17:05:18 +02:00
|
|
|
|
|
|
|
## Pattern.sample() signature
|
|
|
|
|
|
|
|
```js
|
|
|
|
Pattern pattern.sample()
|
2022-02-19 08:04:25 +01:00
|
|
|
```
|
2021-09-25 17:05:18 +02:00
|
|
|
|
|
|
|
## Pattern.sample() example
|
|
|
|
|
|
|
|
```js
|
2022-09-20 18:09:28 +02:00
|
|
|
import { Aaron } from "@freesewing/aaron"
|
|
|
|
import { cisFemaleAdult } from "@freesewing/models"
|
2021-09-25 17:05:18 +02:00
|
|
|
|
|
|
|
const pattern = new Aaron({
|
2022-09-20 18:09:28 +02:00
|
|
|
sample: {
|
|
|
|
models: cisFemaleAdult
|
|
|
|
}
|
2021-09-25 17:05:18 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
const svg = pattern.sample().render()
|
2022-02-19 08:04:25 +01:00
|
|
|
```
|