-
Notifications
You must be signed in to change notification settings - Fork 12
/
components.typ
259 lines (222 loc) · 4.16 KB
/
components.typ
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
#import "../typst-canvas/draw.typ": *
#import "parts.typ"
#import "utils.typ": anchors
#let geographical-anchors(pts) = {
assert(type(pts) == "array" and pts.len() == 8, message: "Invalid format for geographical anchor positions " + repr(pts))
let headings = ("west", "north west", "north", "north east", "east", "south east", "south", "south west")
for i in range(0, 8) {
anchor(headings.at(i), pts.at(i))
}
}
/// Resistive bipoles
/// Short circuit
/// type: path-style
/// nodename: shortshape
/// class: default
#let short = {
line((-0.5, 0), (0.5, 0))
anchors((
north: (0,0),
south: (0,0),
label: (0,0),
annotation: (0,0),
))
}
/// Resistor
/// type: path-style
/// nodename: resistorshape
/// Aliases: american resistor
/// Class: resistors
#let R = {
let step = 1/6
let height = 5/14
let sgn = -1
line(
(-0.5, 0),
(rel: (step/2, height/2)),
..for _ in range(5) {
((rel: (step, height * sgn)),)
sgn *= -1
},
(0.5, 0),
fill: none
)
anchors((
north: (0, height/2),
south: (0, -height/2),
label: (0, height),
annotation: "south"
))
}
// Capacitors and inductors
// Diodes and such
// Sources and generators
/// American Current Source
/// type: path-style, fillable
/// nodename: isourceAMshape
/// aliases: american current source
/// class: sources
#let isourceAM = {
circle((0,0), radius: 0.5, name: "c")
line(((-0.3, 0)), (rel: (0.6, 0)), mark-end: ">", fill: black)
anchors((
north: (0, 0.5),
south: (0, -0.5),
label: (0, 0.7),
annotation: (0, -0.7),
))
}
/// Arrows
/// Arrow for current and voltage
/// type: node
#let currarrow = {
line(
(0.05, 0),
(-0.05, -0.05),
(-0.05, 0.05),
close: true,
fill: black
)
anchors((
north: (0, 0.05),
south: (0, -0.05),
east: (0.05, 0),
west: (-0.05, 0),
))
}
/// Terminal shapes
/// Unconnected terminal
/// type: node
#let ocirc = {
circle((0, 0), radius: 0.05, stroke: black)
anchors((
north: (0, 0.05),
south: (0, -0.05),
east: (0.05, 0),
west: (-0.05, 0),
))
}
/// Connected terminal
/// type: node
#let circ = {
fill(black)
ocirc
}
/// Diamond-square terminal
/// type: node
#let diamondpole = {
fill(black)
anchors((
north: (0, 0.05),
south: (0, -0.05),
east: (0.05, 0),
west: (-0.05, 0),
))
line(
"north",
"east",
"south",
"west",
close: true
)
}
/// Square-shape terminal
/// type: node
#let squarepole = {
fill(black)
rect(
(-0.05, -0.05),
(0.05, 0.05)
)
anchors((
north: (0, 0.05),
south: (0, -0.05),
east: (0.05, 0),
west: (-0.05, 0),
))
}
/// Amplifiers
/// Operational amplifier
#let op-amp = {
line(
(0.8, 0),
(-0.8, -1),
(-0.8, 1),
close: true
)
anchors((
north: (0, 1),
south: (0, -1),
east: (1, 0),
west: (-1, 0),
))
}
/// Logic gates
/// AND gate
/// type: node, fillable
#let and-gate = {
parts.and-gate-body
parts.logic-gate-legs
}
/// NAND gate
/// type: node, fillable
#let nand-gate = {
parts.and-gate-body
parts.not-circle
// circle((rel: (0.1, 0), to: "bout"), radius: 0.1)
// anchor("bout", (rel: (0.1, 0)))
parts.logic-gate-legs
}
/// OR gate
/// type: node, fillable
#let or-gate = {
parts.or-gate-body
parts.logic-gate-legs
}
/// NOR gate
/// type: node, fillable
#let nor-gate = {
parts.or-gate-body
parts.not-circle
parts.logic-gate-legs
}
/// XOR gate
/// type: node, fillable
#let xor-gate = {
parts.or-gate-body
parts.logic-gate-legs
parts.xor-bar
}
/// XNOR gate
/// type: node, fillable
#let xnor-gate = {
parts.or-gate-body
parts.not-circle
parts.logic-gate-legs
parts.xor-bar
}
#let path = (
// Resistive bipoles
"short": short,
"R": R,
// Sources and generators
"isourceAM": isourceAM,
)
#let node = (
// Arrows
"currarrow": currarrow,
//Terminal Shapes
"circ": circ,
"ocirc": ocirc,
"diamondpole": diamondpole,
"squarepole": squarepole,
// Amplifiers
"op amp": op-amp,
// Logic gates
"and gate": and-gate,
"nand gate": nand-gate,
"or gate": or-gate,
"nor gate": nor-gate,
"xor gate": xor-gate,
"xnor gate": xnor-gate
)