transform
The transform macro allows you to rotate/scale/translate points and/or paths.
It is provided by the transform plugin, which is part of core-plugins (so it is available by default).
Signature
macro('transform', {
String transform,
Number x, y,
Number angle,
Point c,
Boolean clone,
Array points,
Array paths,
String or Function prefix,
})
Example
- Preview
- Code
- X-Ray
({ Point, points, Path, paths, macro, part }) => {
points.from = new Point(0,0)
points.cp1 = new Point(10,20)
points.cp2 = new Point(60,20)
points.to = new Point(70,0)
points.center = new Point(35,5)
paths.example = new Path()
.move(points.from)
.curve(points.cp1, points.cp2, points.to)
macro('transform', {
transform: 'rotate',
c: points.center,
angle: 145,
clone: true,
paths: ['example'],
prefix: 'rotate\_',
})
macro('transform', {
transform: 'scale',
clone: true,
x: 0.6,
c: points.center,
paths: ['example'],
prefix: 'scale\_',
})
macro('transform', {
transform: 'translate',
clone: true,
x: 20,
y: 10,
paths: ['example'],
prefix: (n, t) => `translated_${t}_${n}`
})
paths.rotate_example.addText('rotate','note center')
paths.rotate_example.addClass('note')
paths.scale_example.addText('scale','canvas center')
paths.scale_example.addClass('canvas')
paths.translated_path_example.addText('translate','lining center')
paths.translated_path_example.addClass('lining')
return part
}
Examples of the transform macro
Configuration
| Property | Default | Type | Description |
|---|---|---|---|
transform | string | String indicating the action to perform. Must be one of: rotate, scale, or translate | |
clone | true | bool | Whether to clone transformed points and/or paths |
points | array | An array of pointnames, the names of Points in the points array to transform | |
paths | array | An array of pathnames, the names of Paths in the paths array to transform | |
prefix | transformed | string | One of:
|
c | new Point(0,0) | Point | The point used to rotate around (or scale from) |
angle | 0 | float | The angle of rotation, used with the rotate option |
x | 0 | float | How far to move in the X direction in the translate option orHow much to scale in the X direction in the scale option |
y | 0 | float | How far to move in the Y direction in the translate option orHow much to scale in the Y direction in the scale option |
Notes
When using the scale option, a center point is recommended. The macro does not automatically calculate the center point
for the arrays of points and paths. If omitted, a default of new Point(0,0) will be used.