Skip to content

Commit

Permalink
feat: add buf, not, mux and decode gates
Browse files Browse the repository at this point in the history
  • Loading branch information
Bnyro committed Feb 7, 2024
1 parent c6b4f4d commit 035cf0f
Show file tree
Hide file tree
Showing 2 changed files with 119 additions and 2 deletions.
35 changes: 34 additions & 1 deletion components.typ
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,21 @@

/// Logic gates

// BUF gate
// type: node, fillable
#let buf-gate = {
parts.buf-gate-body
parts.logic-gate-legs-single
}

// NOT gate
// type: node, fillable
#let not-gate = {
parts.buf-gate-body
parts.not-circle
parts.logic-gate-legs-single
}

/// AND gate
/// type: node, fillable
#let and-gate = {
Expand Down Expand Up @@ -227,6 +242,20 @@
parts.xor-bar
}

/// MUX gate
/// type: node, fillable
#let mux-gate = {
parts.mux-gate-body
parts.logic-gate-legs-mux
}

/// DEC gate
/// type: node, fillable
#let dec-gate = {
parts.dec-gate-body
parts.logic-gate-legs-dec
}

#let path = (
// Resistive bipoles
"short": short,
Expand All @@ -250,10 +279,14 @@
"op amp": op-amp,

// Logic gates
"buf gate": buf-gate,
"not gate": not-gate,
"and gate": and-gate,
"nand gate": nand-gate,
"or gate": or-gate,
"nor gate": nor-gate,
"xor gate": xor-gate,
"xnor gate": xnor-gate
"xnor gate": xnor-gate,
"mux gate": mux-gate,
"dec gate": dec-gate
)
86 changes: 85 additions & 1 deletion parts.typ
Original file line number Diff line number Diff line change
@@ -1,5 +1,77 @@
#import "../typst-canvas/draw.typ": *
#import "utils.typ": anchors

#let mux-gate-body = {
line(
(-0.5, 0.8),
(-0.5, -0.8),
(0.5, -0.6),
(0.5, 0.6),
(-0.5, 0.8)
)
anchors((
"bin 1": (-0.5, 0.25),
"in 1": (rel: (-0.5, 0)),
"bin 2": (-0.5, -0.25),
"in 2": (rel: (-0.5, 0)),
"bsel": (0, 0.7),
"sel": (rel: (0, 0.3)),
"bout": (0.5, 0),
"out": (rel: (0.5, 0)),
"north": (0, 1),
"south": (rel: (0, -1)),
"east": "out",
"west": ("in 1", "|-", "center"),
"left": ("bin 1", "|-", "center"),
"right": "bout"
))
}

#let dec-gate-body = {
line(
(-0.5, 0.6),
(-0.5, -0.6),
(0.5, -0.8),
(0.5, 0.8),
(-0.5, 0.6)
)
anchors((
"bin": (-0.5, 0),
"in": (rel: (-0.5, 0)),
"bout 1": (0.5, 0.25),
"out 1": (rel: (0.5, 0)),
"bout 2": (0.5, -0.25),
"out 2": (rel: (0.5, 0)),
"north": (0, 0.5),
"south": (rel: (0, -1)),
"east": (0.5, 0),
"west": ("in", "|-", "center"),
"left": ("bin", "|-", "center"),
"right": (0.5, 0)
))
}

#let buf-gate-body = {
line(
(-0.5, 0.5),
(-0.5, -0.5),
(0.5, 0),
(-0.5, 0.5)
)
anchors((
"bin": (-0.5, 0),
"in": (rel: (-0.5, 0)),
"bout": (0.5, 0),
"out": (rel: (0.5, 0)),
"north": (0, 0.5),
"south": (rel: (0, -1)),
"east": "out",
"west": ("in", "|-", "center"),
"left": ("bin", "|-", "center"),
"right": "bout"
))
}

#let and-gate-body = {
merge-path(close: true, {
arc((0,0), -90deg, 90deg, radius: 0.5, name: "curve", anchor: "origin")
Expand Down Expand Up @@ -75,4 +147,16 @@

#let logic-gate-legs = for a in ("in 1", "in 2", "out") {
line("b" + a, a)
}
}

#let logic-gate-legs-single = for a in ("in", "out") {
line("b" + a, a)
}

#let logic-gate-legs-mux = for a in ("in 1", "in 2", "out", "sel") {
line("b" + a, a)
}

#let logic-gate-legs-dec = for a in ("in", "out 1", "out 2") {
line("b" + a, a)
}

0 comments on commit 035cf0f

Please sign in to comment.