| 1 |
.PS |
| 2 |
# cbresistor.m4 |
| 3 |
# https://tex.stackexchange.com/questions/709339/create-command-with-decoration-in-tikz |
| 4 |
# https://www.google.com/search?client=firefox-b-d&q=resistor+color+code |
| 5 |
cct_init |
| 6 |
divert(-1) |
| 7 |
|
| 8 |
`cbresistor(linespec, keys) |
| 9 |
keys: |
| 10 |
lgth=expr; wdth=expr; |
| 11 |
body=body attributes, e.g. shaded "green" |
| 12 |
type=A|B; pinched body shape |
| 13 |
colors=color:color:...; |
| 14 |
Up to 6 colors, a color may be nul ' |
| 15 |
define(`cbresistor',`eleminit_(`$1') |
| 16 |
pushkeys_(`$2',`lgth:dimen_/2; wdth:dimen_/5; body::N; colors::N; type::N')dnl |
| 17 |
{line to rvec_(max(0,rp_len/2-m4lgth/2),0) thick linethick*3/2; M4cbW: Here |
| 18 |
ifelse(m4type,B, |
| 19 |
`[L:rotbox(m4lgth*3/23, m4wdth, shaded "darkgray" m4body,r=m4wdth/20) |
| 20 |
C:rotbox(m4lgth*17/23, m4wdth*9/10, shaded "darkgray" m4body) \ |
| 21 |
with .W at L.E |
| 22 |
R:rotbox(m4lgth*3/23, m4wdth, shaded "darkgray" m4body,r=m4wdth/20) \ |
| 23 |
with .W at C.E] with .L.W at Here; move to last [].R.E', |
| 24 |
`rotbox(m4lgth, m4wdth, shaded "darkgray" m4body) with .W at Here') |
| 25 |
ifelse(m4colors,,,`define(`m4bw',(m4lgth/23))dnl |
| 26 |
definergbcolor(silver,0.75,0.75,0.75) |
| 27 |
definergbcolor(gold,1,215/255,0) |
| 28 |
stacksplit_(`cbrstack',m4colors,:)stackreverse_(`cbrstack')dnl |
| 29 |
stackargs_(`m4pos',22,17,12,7,5,2)dnl |
| 30 |
stackdo_(`cbrstack',`ifelse(cbrstack,nul,, |
| 31 |
`{ move to M4cbW+vec_(m4pos*m4bw-m4bw/2,0) |
| 32 |
define(`m4ctr',ifelse(m4type,B,eval((m4pos>3)*(m4pos<20)),0))dnl |
| 33 |
line m4colorfix(outlined,cbrstack) thick m4bw*1.8/(1bp__) \ |
| 34 |
from rvec_(0,-ifelse(m4ctr,1,0.9*)m4wdth/2) \ |
| 35 |
to rvec_(0, ifelse(m4ctr,1,0.9*)m4wdth/2) |
| 36 |
ifelse(ifelse(cbrstack,silver,1,cbrstack,gold,1),1, |
| 37 |
`line outlined rgbstring(0.8,0.8,0.8) thick last line.thick \ |
| 38 |
from 0.2 along_(last line) to 0.4 along_(last line) |
| 39 |
line outlined "white" thick last line.thick \ |
| 40 |
from 0.25 along_(2nd last line) to 0.3 along_(2nd last line)') |
| 41 |
}') |
| 42 |
popdef(`m4pos')') stackdo_(`m4pos')') |
| 43 |
line to rvec_(max(0,rp_len/2-m4lgth/2),0) thick linethick*3/2} |
| 44 |
popdef(`m4lgth',`m4wdth',`m4body',`m4colors',`m4type')dnl |
| 45 |
line to rvec_(rp_len,0) invis ') |
| 46 |
|
| 47 |
divert(0)dnl |
| 48 |
|
| 49 |
linewid = 3/2*linewid |
| 50 |
ifsvg(definergbcolor(Dandelion,0.95,0.65,0.2)) |
| 51 |
ifsvg(definergbcolor(Peach,0.76,0.5,0.1)) |
| 52 |
|
| 53 |
define(`dpr', |
| 54 |
`{ cbresistor(,type=B; |
| 55 |
body=m4colorfix(shaded,Dandelion) m4colorfix(outlined,Peach); |
| 56 |
colors=`$2') } |
| 57 |
{iflatex(`sprintf("\SI{%g}{\ohm}",`$1')')ifsvg("``$1'svg_Omega'") \ |
| 58 |
at last line.end+(10bp__,-5bp__) rjust} |
| 59 |
move right_ moveht*5/6; down_ ') |
| 60 |
|
| 61 |
define(`elen_',(3/2*linewid)) |
| 62 |
define(`dimen_',(5/4*linewid)) |
| 63 |
[] |
| 64 |
[ down_ |
| 65 |
foreach_(`pair',`dpr(patsubst(pair,-,`,'):nul:black:silver)', |
| 66 |
10-brown:black, |
| 67 |
12-brown:red, |
| 68 |
15-brown:green, |
| 69 |
18-brown:gray, |
| 70 |
22-red:red, |
| 71 |
27-red:Violet, |
| 72 |
33-orange:orange, |
| 73 |
39-orange:white, |
| 74 |
47-yellow:Violet, |
| 75 |
56-green:blue, |
| 76 |
68-blue:gray, |
| 77 |
82-gray:red) |
| 78 |
dpr(100,brown:black:nul:brown:gold) |
| 79 |
{"iflatex(\SI{5}{\percent},5 %)" at last line.end+(10bp__,-15bp__) rjust} |
| 80 |
] with .nw at last [].ne+(30bp__,0) |
| 81 |
|
| 82 |
.PE |