PrinterKit | Wiki

2D Shape Operators

Use the following operators on shapes or shape groups.

Operator Action
- Difference
& Intersect
\ Rotate
* Scale
>> Translate
| Union
~ Xor

Translate

The translate operator ">>" returns a new shape moved by a vector (x,y) or scalar x.

rect = Rect(1,6)
rect1 = rect >> Vec2(-1,0)
rect2 = rect >> Vec2(1,0)
group = group(rect1,rect2)
length =  1.0
shape = extrude(group, length)
render(shape)

alt text

Scale

The scale operator "*" returns a new shape scaled by a vector (x,y) or scalar x.

circle = Circle(2,64)
circle1 = circle * 0.75
circle2 = circle * 1.25
circle1 = circle1 >> Vec2(-3,0)
circle2 = circle2 >> Vec2(3,0)
group = group(circle1, circle2)
length =   1.0
shape = extrude(group, length)
render(shape)

alt text

Rotate

The rotate operator "\" returns a new shape rotated by a specified number of radians. You and use the constants PI (half rotation) or TAU (full rotation)

rect1 = Rect(1,6)
rect2 = rect1 / (PI * 0.25)
rect1 = rect1 >> Vec2(-2,0)
rect2 = rect2 >> Vec2(2,0)
group = group(rect1, rect2)
length =   1.0
shape = extrude(group, length)
render(shape)

alt text

Union

The union operator "|" combines shapes into a resulting shape group.

rect1 = Rect(1,6)
rect2 = Rect(6,1)
circle = Circle(2,64)
result = rect1 | rect2 | circle
length = 1.0
shape = extrude(result, length)
render(shape)

alt text

Difference

The difference operator "-" subtracts one shape or shape group from another.

rect1 = Rect(1,6)
rect2 = Rect(6,1)
circle = Circle(2,64)
result = circle - rect1 - rect2
length = 1.0
shape = extrude(result, length)
render(shape)

alt text

Intersect

The intersect operator "&" returns where shapes overlap.

rect1 = Rect(1,6)
rect2 = Rect(6,1)
result = rect1 & rect2
length = 1.0
shape = extrude(result, length)
render(shape)

alt text

XOR

The XOR operator "~" returns where shapes do not overlap.

rect1 = Rect(1,6)
rect2 = Rect(6,1)
result = rect1 ~ rect2
length = 1.0
shape = extrude(result, length)
render(shape)

alt text