1
0
forked from HEL/circuiteria

added logic gates

This commit is contained in:
2024-05-17 21:19:40 +02:00
parent a9014e03e9
commit 8ec245f36e
12 changed files with 597 additions and 4 deletions

View File

@ -0,0 +1,81 @@
#import "@preview/cetz:0.2.2": draw
#import "gate.typ"
#let draw-shape(id, tl, tr, br, bl, fill, stroke) = {
let (x, y) = bl
let (width, height) = (tr.at(0) - x, tr.at(1) - y)
let r = (x + width, y + height / 2)
let f = draw.group(name: id, {
draw.merge-path(
inset: 0.5em,
fill: fill,
stroke: stroke,
name: id + "-path",
close: true, {
draw.line(bl, tl, r)
}
)
draw.anchor("north", (tl, 50%, r))
draw.anchor("south", (bl, 50%, r))
})
return (f, tl, tr, br, bl)
}
#let gate-buf(
x: none,
y: none,
w: none,
h: none,
inputs: 2,
fill: none,
stroke: black + 1pt,
id: "",
inverted: (),
debug: (
ports: false
)
) = {
gate.gate(
draw-shape: draw-shape,
x: x,
y: y,
w: w,
h: h,
inputs: inputs,
fill: fill,
stroke: stroke,
id: id,
inverted: inverted,
debug: debug
)
}
#let gate-not(x: none,
y: none,
w: none,
h: none,
inputs: 2,
fill: none,
stroke: black + 1pt,
id: "",
inverted: (),
debug: (
ports: false
)
) = {
gate-buf(
x: x,
y: y,
w: w,
h: h,
inputs: inputs,
fill: fill,
stroke: stroke,
id: id,
inverted: inverted + ("out",),
debug: debug
)
}