forked from HEL/circuiteria
47 lines
1.2 KiB
Typst
47 lines
1.2 KiB
Typst
// Demonstrates the `(rel: <number>, to: <anchor>)` shorthand for the `y`
|
|
// parameter (analogous to the existing shorthand for `x`).
|
|
#import "/src/lib.typ": circuit, element, util, wire
|
|
|
|
#set page(width: auto, height: auto, margin: .5cm)
|
|
|
|
#circuit({
|
|
// Anchor block: absolute placement.
|
|
element.block(
|
|
x: 0, y: 0, w: 2, h: 1.5,
|
|
id: "A",
|
|
fill: util.colors.orange,
|
|
ports: (east: ((id: "out"),))
|
|
)
|
|
|
|
// X relative, Y absolute (existing feature).
|
|
element.block(
|
|
x: (rel: 1, to: "A.east"), y: 0, w: 2, h: 1.5,
|
|
id: "B",
|
|
fill: util.colors.yellow,
|
|
ports: (west: ((id: "in"),), east: ((id: "out"),))
|
|
)
|
|
|
|
// Both X and Y relative to another element's anchor (new feature).
|
|
element.block(
|
|
x: (rel: 1, to: "B.east"),
|
|
y: (rel: 2, to: "B.south-west"),
|
|
w: 2, h: 1.5,
|
|
id: "C",
|
|
fill: util.colors.green,
|
|
ports: (west: ((id: "in"),))
|
|
)
|
|
|
|
// Y relative only, X absolute.
|
|
element.block(
|
|
x: 0,
|
|
y: (rel: -2.5, to: "A.south-west"),
|
|
w: 2, h: 1.5,
|
|
id: "D",
|
|
fill: util.colors.blue,
|
|
ports: (east: ((id: "out"),))
|
|
)
|
|
|
|
wire.wire("wAB", ("A-port-out", "B-port-in"))
|
|
wire.wire("wBC", ("B-port-out", "C-port-in"), style: "zigzag")
|
|
})
|