Skip to content

Instantly share code, notes, and snippets.

@ndbroadbent
Last active October 30, 2022 05:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ndbroadbent/b33a2d72a13549d01c39d10a96b97880 to your computer and use it in GitHub Desktop.
Save ndbroadbent/b33a2d72a13549d01c39d10a96b97880 to your computer and use it in GitHub Desktop.
E24 Resistor Pack Ring Binder HTML / CSS
<!DOCTYPE HTML>
<html>
<head>
</head>
<body>
{% assign series = "1.0#1.1#1.2#1.3#1.5#1.6#1.8#2.0#2.2#2.4#2.7#3.0#3.3#3.6#3.9#4.3#4.7#5.1#5.6#6.2#6.8#7.5#8.2#9.1" | split: '#' %}
{% assign band_colors = "black,brown,red,orange,yellow,green,blue,violet,grey,white" | split: ',' %}
{% assign multiplier_colors = "silver,gold,black,brown,red,orange,yellow,green,blue,violet,grey,white" | split: ',' %}
{% assign band_colors_abbr = "blk,brn,red,orn,ylw,grn,blu,vlt,gry,wht" | split: ',' %}
{% assign multiplier_colors_abbr = "slv,gld,blk,brn,red,orn,ylw,grn,blu,vlt,gry,wht" | split: ',' %}
{% assign max_multiplier_index = 7 %}
{% assign per_page = 9 %}
{% for multiplier_index in (0..max_multiplier_index) %}
{% assign multiplier_color = multiplier_colors[multiplier_index] %}
{% assign multiplier = 0.01 %}
{% for exponent in (0..multiplier_index) %}
{% assign multiplier = multiplier | times: 10 %}
{% endfor %}
{% if multiplier_index == 0 %}
<!-- This resistor kit just has 0 ohms and 0.51 ohms before starting with the gold band -->
{% assign band_series = "0#5.1#nil" | split: '#' %}
{% else %}
{% assign band_series = series %}
{% endif %}
{% assign length = band_series | size %}
{% assign pages = length | times: 1.0 | divided_by: per_page | ceil %}
{% for page in (1..pages) %}
{% assign offset = page | minus: 1 | times: per_page %}
{% assign remaining = length | minus: offset %}
<div class="wrapper">
<table>
{% tablerow factor in band_series cols:3 limit:per_page offset:offset %}
{% if factor == 'nil' %}
<div class="header"></div>
{% else %}
{% assign unit = "Ω" %}
{% assign ohms = factor | times: multiplier %}
{% if ohms >= 1000000000 %}
{% assign ohms = ohms | divided_by: 1000000000.0 %}
{% assign unit = "GΩ" %}
{% else %}
{% if ohms >= 1000000 %}
{% assign ohms = ohms | divided_by: 1000000.0 %}
{% assign unit = "MΩ" %}
{% else %}
{% if ohms >= 1000 %}
{% assign ohms = ohms | divided_by: 1000.0 %}
{% assign unit = "KΩ" %}
{% endif %}
{% endif %}
{% endif %}
{% assign rounded_ohms = ohms | round %}
{% if ohms == rounded_ohms %}{% assign ohms = rounded_ohms %}{% endif %}
<div class="header">
<h2>{{ ohms }}{{ unit }}</h2>
<div class="resistor-and-text">
<div class="resistor">
{% assign band_1 = factor | floor %}
{% assign band_2 = factor | times: 10 | modulo: 10 | round %}
<div class="band band-1 band-value-{{ band_1 }}"></div>
{% if ohms > 0 %}
<div class="band band-2 band-value-{{ band_2 }}"></div>
<div class="band band-3 band-multiplier-{{ multiplier_index }}"></div>
<div class="band band-4 band-value-gold"></div>
{% endif %}
</div>
<div class="resistor-colors-text">
{{ band_colors[band_1] }}
{% if ohms > 0 %}
{{ band_colors[band_2] }} {{ multiplier_colors[multiplier_index] }}
{% endif %}
</div>
</div>
</div>
{% endif %}
{% endtablerow %}
{% if remaining <= 3 %}
<tr></tr>
{% endif %}
{% if remaining <= 6 %}
<tr></tr>
{% endif %}
</table>
</div>
{% endfor %}
{% endfor %}
</body>
</html>
* {
box-sizing: border-box
}
.wrapper {
page-break-before: always;
width: 100%;
height: 100vh;
}
table {
width: 100%;
height: calc(100%);
}
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
tr {
height: 33%;
table-layout: fixed;
width: 100%;
}
td {
text-align: center;
vertical-align: top;
width: 33%;
}
.header {
display: flex;
justify-content: space-between;
align-items: flex-start;
flex-direction: row;
padding: 4px 12px;
h2 {
margin: 0;
font-size: 42px;
}
}
.resistor-and-text {
margin-top: 7px;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.resistor {
zoom: 1.2;
position: relative;
width: 75px;
height: 20px;
border-radius: 10px;
background-color: #e9e7df;
border: 1px solid #555;
.band {
position: absolute;
top: 0;
bottom: 0;
width: 8px;
height: 100%;
background-color: #888;
}
.band-1 { left: 10px; }
.band-2 { left: 25px; }
.band-3 { left: 40px; }
.band-4 { left: 55px; }
.band-value-0, .band-multiplier-2 { background-color: black; } // black
.band-value-1, .band-multiplier-3 { background-color: #8F3A16; } // brown
.band-value-2, .band-multiplier-4 { background-color: #EB3223; } // red
.band-value-3, .band-multiplier-5 { background-color: #F7C243; } // orange
.band-value-4, .band-multiplier-6 { background-color: #FFFD55; } // yellow
.band-value-5, .band-multiplier-7 { background-color: #4FAD5C; } // green
.band-value-6, .band-multiplier-8 { background-color: #2D71BB; } // blue
.band-value-7, .band-multiplier-9 { background-color: #68389B; } // violet
.band-value-8, .band-multiplier-10 { background-color: #808080; } // gray
.band-value-9, .band-multiplier-11 { background-color: white; } // white
.band-value-silver, .band-multiplier-0 { background: rgb(121,121,121); background: linear-gradient(90deg, rgba(121,121,121,1) 0%, rgba(195,195,195,1) 50%, rgba(121,121,121,1) 100%); }
.band-value-gold, .band-multiplier-1 { background: rgb(244,183,67); background: linear-gradient(90deg, rgba(244,183,67,1) 0%, rgba(242,230,83,1) 50%, rgba(244,183,67,1) 100%); }
}
.resistor-colors-text {
margin-top: 1px;
color: #444;
font-size: 10px;
}
Copyright 2022 Nathan Broadbent. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy of this PDF document, software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE PDF AND SOFTWARE ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment