2D Shape Transform Functions
Use the following functions to modify shapes or shape groups.
Name | Function Signature |
---|---|
backplate | backplate(Shape2d shape, float distance) |
border | border(Shape2d shape, float wallThickness) |
copyAt | copyAt(Shape2d shape, Vec2 position) |
flip | flip(Shape2d shape, string flipMode) |
grid | grid(Shape2d shape, int columnCount, int rowCount, Vec2 stepSize) |
hull | hull(Shape2d shape) |
morph | morph(Shape2d shape, float distance) |
radial | radial(Shape2d shape, float radius, int placeCount) |
rotate | rotate(Shape2d shape, float angle) |
round | round(Shape2d shape, float distance, int circlePoints) |
scale | scale(Shape2d shape, Vec2 factor) |
smooth | smooth(Shape2d shape, float smoothAmount) |
translate | translate(Shape2d shape, Vec2 amount) |
The following boolean 2D functions are supported.
Name | Function Signature |
---|---|
diff | diff(Shape2d... shapes1, Shape2d... shapes2) |
intersect | intersect(Shape2d.. shapes1, Shape2d... shapes2) |
sym_diff | sym_diff(Shape2d... shapes1, Shape2d... shapes2) |
union | union(Shape2d... shapes) |
Backplate
Remove interior cutouts and expand shape by a specified amount
ring = Ring(3,2)
expansion = 0.5
back = backplate(ring, expansion)
g = group(ring >> vec(-4,0), back >> vec(4,0))
shape = extrude(g, 1)
render(shape)
Border
Transform shape into a border with a given wall thickness
svg = Svg("leaf-4", 4, 4)
wallThickness = 0.1
outline = border(svg, wallThickness)
g = group(svg >> vec(-2.5,0), outline >> vec(2.5,0))
shape = extrude(g, 1)
render(shape)
Flip
Flip a shape along its' center x or y axis
surface = Square(4) - (Square(4) >> vec(1,1))
surface_x = flip(surface, "x")
surface_y = flip(surface, "y")
surface_xy = flip(surface, "xy")
g = group(surface,
surface_x >> vec(5,0),
surface_y >> vec(0,5),
surface_xy >> vec(5,5))
shape = extrude(g, 1)
render(shape)
Grid
Place a shape in a grid of rows and columns
hex = Hexagon(1)
g = grid(hex, 4, 3, vec(2.5,2.5))
shape = extrude(g, 1)
render(shape)
Hull
Calculate the convex hull of a group of shapes
g1 = group(Circle(0.25) >> vec(-3,0),
Circle(0.25) >> vec(3,0),
Circle(0.25) >> vec(0,3))
g2 = hull(g1)
g = group(g1 >> vec(-4,0),
g2 >> vec(4,0))
shape = extrude(g, 1)
render(shape)
Morph
Dialate or erode a shape
g1 = group(Square(2) >> vec(-1.2,0),
Hexagon(1) >> vec(1.2,0))
expansion = 0.5
g2 = morph(g1, expansion)
g = group(g1 >> vec(-3,0),
g2 >> vec(3,0))
shape = extrude(g, 1)
render(shape)
Radial
Place a shape around a circle of a given radius
item = Hexagon(1) - (Rect(1.5,0.5) >> vec(1,0))
g = radial(item, 3, 6)
shape = extrude(g, 1)
render(shape)
Rotate
Rotate a shape in radians
r1 = Rect(4,1)
r2 = rotate(r1, TAU * 0.25)
g = group(r1 >> vec(-2,0),
r2 >> vec(2,0))
shape = extrude(g, 1)
render(shape)
Round
Round a shape's corners
sq = Square(3)
expansion = 0.5
g = group(sq >> vec(-2.5,0), round(sq, expansion) >> vec(2.5,0))
shape = extrude(g, 1)
render(shape)
Scale
Scale a shape by a scaling factor. Scaling can be uniform or use a Vec2 that has different X and Y scaling values.
svg1 = Svg("leaf-4",2,2)
svg2 = scale(svg1, vec(2,1.2))
g = group(svg1 >> vec(-2,0), svg2 >> vec(2,0))
shape = extrude(g, 1)
render(shape)
Smooth
Smooth a shape to reduce the amount of jagged lines.
svg1 = Svg("leaf-4",3,3,1)
svg2 = smooth(svg1,0.6)
g = group(svg1 >> vec(-2,0), svg2 >> vec(2,0))
shape = extrude(g, 1)
render(shape)
Translate
Translate a shape in the X and Y directions.
r = Rect(3,2)
g = group(translate(r, vec(-2,0)), translate(r, vec(2,0)))
shape = extrude(g, 1)
render(shape)