initial commit

This commit is contained in:
Hlars 2023-10-03 08:35:12 +02:00
commit d9ce1244ec
3 changed files with 161 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
*.pdf
.DS_Store

3
README.md Normal file
View File

@ -0,0 +1,3 @@
Label for [resistor box](https://www.thingiverse.com/thing:1959310)
Label size: 44 (48,5mm x 25,4mm) on DIN A4

156
resistor_label.typ Normal file
View File

@ -0,0 +1,156 @@
#import "@preview/cetz:0.1.1"
#let availableColors = (
black: rgb("#000"),
brown: rgb("#563829"),
red: red,
orange: rgb("#FE5000"),
yellow: yellow,
green: rgb("#046d20"),
blue: rgb("#001184"),
violet: rgb("#9400d3"),
grey: rgb("#4B4E53"),
white: rgb("#fff"),
gold: rgb("#FFC42E"),
silver: rgb("#A8A9AD"),
)
#let labelWidth = 25.4mm
#let labelHeight = 48.5mm
#let resistorLabel(resistance, prefix, precision, power, horizontal: false, ..colors) = {
let colors = colors.pos()
assert(colors.all(it => availableColors.keys().contains(it)), message: "Unsupported color: Only " + availableColors.keys().join(", ") + " are supported")
assert((4,5, 6).any(it => it == colors.len()), message: "Only 4, 5 or 6 ring resistors are supported")
box(width: 0.5*labelWidth - 1pt)[#pad(y: 15pt)[
#align(center)[
#set text(size: 10pt)
*$resistance""space.thin""upright(prefix)Omega$* \
#v(4pt)
$precision""space.thin""%$ \
#v(4pt)
$power""space.thin""upright(W)$ \
#cetz.canvas(length: .25*labelWidth, debug: false, {
import cetz.draw: *
set-style(
// Stroke and fill for only rectangles
rect: (stroke: (thickness: .4pt)),
)
let resColor = if colors.len() == 4 {
yellow.lighten(75%)
} else {
blue.lighten(75%)
}
if horizontal == false {
rotate((z: 90deg))
scale((x: 1.5, y: 1.5))
}
line((), (rel: (.2, 0)))
rect((rel: (0, -0.2)), (rel: (1.5, 0.4)), name: "res", fill: resColor)
line("res.right", (rel: (.2, 0)))
set-origin("res.bottom-left")
set-style(
// Stroke and fill for only rectangles
rect: (stroke: (thickness: .1pt)),
)
if colors.len() == 4 {
rect((0.2,0), (.3,.4), fill: availableColors.at(colors.at(0)))
rect((0.45,0), (.55,.4), fill: availableColors.at(colors.at(1)))
rect((0.65,0), (.75,.4), fill: availableColors.at(colors.at(2)))
rect((1.25,0), (1.35,.4), fill: availableColors.at(colors.at(3)))
} else if colors.len() == 5 {
rect((0.2,0), (.3,.4), fill: availableColors.at(colors.at(0)))
rect((0.4,0), (.5,.4), fill: availableColors.at(colors.at(1)))
rect((0.6,0), (.7,.4), fill: availableColors.at(colors.at(2)))
rect((0.8,0), (.9,.4), fill: availableColors.at(colors.at(3)))
rect((1.25,0), (1.35,.4), fill: availableColors.at(colors.at(4)))
} else {
rect((0.2,0), (.3,.4), fill: availableColors.at(colors.at(0)))
rect((0.4,0), (.5,.4), fill: availableColors.at(colors.at(1)))
rect((0.6,0), (.7,.4), fill: availableColors.at(colors.at(2)))
rect((0.8,0), (.9,.4), fill: availableColors.at(colors.at(3)))
rect((1,0), (1.1,.4), fill: availableColors.at(colors.at(4)))
rect((1.25,0), (1.35,.4), fill: availableColors.at(colors.at(5)))
}
})
]
]]
}
#let createLabelPage(start: 1, ..labels) = {
let arr = ()
let label_set = labels.pos()
for i in range(1, 45) {
if i >= start {
if i - start < label_set.len() {
arr.push(label_set.at(i - start))
}
} else {
arr.push("")
}
}
page(paper: "a4", flipped: true, margin: (x: 8.8mm, y: 8mm),)[
#table(
rows: (labelHeight, labelHeight, labelHeight, labelHeight),
columns:(labelWidth, labelWidth, labelWidth, labelWidth, labelWidth, labelWidth, labelWidth, labelWidth, labelWidth, labelWidth, labelWidth),
stroke: 1pt + black,
inset: 0pt,
..arr
)
]
}
#let labelSet(res1, res2) = [
#box(clip: true, width: 100%, height: 100%)[
#stack(dir: ltr)[#res1][#rect(height: 100%, width: 1.5pt, fill: red)][#res2]
]
]
#grid(
columns: (labelWidth, labelWidth),
rows: (auto),
row-gutter: 20pt,
resistorLabel(horizontal: true, 4.7 ,"k", 0.1, 1, "yellow", "brown", "red", "yellow"),
resistorLabel(4.7 ,"k", 0.1, 1, "yellow", "grey", "silver", "red", "yellow"),
resistorLabel(4.7 ,"k", 0.1, 1, "yellow", "brown", "red", "brown", "green", "violet")
)
#box(stroke: 0.1pt + black,)[
#stack(dir: ltr)[#resistorLabel(4.7, "k", 0.1, 1, "yellow", "brown", "red", "yellow")][#rect(height: 2.4cm + 10pt, width: 2pt, fill: red)][#resistorLabel(100, "k", 0.1, 1/4, "yellow", "brown", "red", "yellow", "blue")]
]
#box(stroke: 0.1pt + black, clip: true, width: labelWidth)[
#stack(dir: ltr)[#resistorLabel(4.7, "k", 0.1, 1, "yellow", "brown", "red", "yellow")][#rect(height: 2.4cm + 10pt, width: 2pt, fill: red)][#resistorLabel(100, "k", 0.1, 1/4, "yellow", "brown", "red", "yellow", "blue")]
]
#page(paper: "a4", flipped: true, margin: (x: 8.8mm, y: 8mm),)[
#table(
rows: (labelHeight, labelHeight, labelHeight, labelHeight),
columns:(labelWidth, labelWidth, labelWidth, labelWidth, labelWidth, labelWidth, labelWidth, labelWidth, labelWidth, labelWidth, labelWidth),
fill: gray.lighten(50%), stroke: 1pt + black,
inset: 0pt,
[#box(stroke: 0.1pt + black, clip: true, width: 100%, height: 100%)[
#stack(dir: ltr)[#resistorLabel(4.7, "k", 0.1, 1, "yellow", "brown", "red", "yellow")][#rect(height: 100%, width: 1.5pt, fill: red)][#resistorLabel(100, "k", 0.1, 1/4, "yellow", "brown", "red", "yellow", "blue")]
]],[],[],[],[],labelSet(resistorLabel(4.7, "k", 0.1, 1, "yellow", "brown", "red", "yellow"), resistorLabel(100, "k", 0.1, 1/4, "yellow", "brown", "red", "yellow", "blue")))
]
#createLabelPage(start: 5,
labelSet(
resistorLabel(1, "k", 0.1, 1, "yellow", "brown", "red", "yellow"),
resistorLabel(5, "M", 5, 200, "green", "blue", "red", "red", "gold")
),
labelSet(
resistorLabel(4.7, "k", 0.1, 1, "yellow", "brown", "red", "yellow", "silver"),
resistorLabel(100, "k", 0.1, 1/4, "yellow", "brown", "red", "yellow", "blue")
)
)