forked from HEL/circuiteria
added logic gates
This commit is contained in:
81
src/elements/logic/buf.typ
Normal file
81
src/elements/logic/buf.typ
Normal 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
|
||||
)
|
||||
}
|
Reference in New Issue
Block a user