KCL stdlib has a function `patternTransform` which works for 3D solids. This adds a similar function `patternTransform2d` which, as you might have guessed, is like `patternTransform` but for 2D. I know. I'm really, really really good at naming things. This shares almost all of its implementation with 3D patterns via 💖the power of traits💖 This will assist with https://github.com/KittyCAD/modeling-app/issues/4543
46 lines
51 KiB
Markdown
46 lines
51 KiB
Markdown
---
|
|
title: "patternTransform2d"
|
|
excerpt: "Just like patternTransform, but works on 2D sketches not 3D solids."
|
|
layout: manual
|
|
---
|
|
|
|
Just like patternTransform, but works on 2D sketches not 3D solids.
|
|
|
|
|
|
|
|
```js
|
|
patternTransform2d(total_instances: u32, transform_function: FunctionParam, solid_set: SketchSet) -> [Sketch]
|
|
```
|
|
|
|
|
|
### Arguments
|
|
|
|
| Name | Type | Description | Required |
|
|
|----------|------|-------------|----------|
|
|
| `total_instances` | `u32` | | Yes |
|
|
| `transform_function` | `FunctionParam` | | Yes |
|
|
| `solid_set` | [`SketchSet`](/docs/kcl/types/SketchSet) | A sketch or a group of sketches. | Yes |
|
|
|
|
### Returns
|
|
|
|
[`[Sketch]`](/docs/kcl/types/Sketch)
|
|
|
|
|
|
### Examples
|
|
|
|
```js
|
|
// Each instance will be shifted along the X axis.
|
|
fn transform = (id) => {
|
|
return { translate: [4 * id, 0] }
|
|
}
|
|
|
|
// Sketch 4 circles.
|
|
sketch001 = startSketchOn('XZ')
|
|
|> circle({ center: [0, 0], radius: 2 }, %)
|
|
|> patternTransform2d(4, transform, %)
|
|
```
|
|
|
|

|
|
|
|
|