Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added methods to quickly generate common series #25

Merged
merged 5 commits into from
Mar 18, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 18 additions & 12 deletions LabelGenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ def __init__(
num_stickers_vertical=8,
)


class StickerRect:
def __init__(self, c: Canvas, layout: PaperConfig, row: int, column: int, mirror: bool):
self.left = layout.left_margin + layout.horizontal_stride * column
Expand Down Expand Up @@ -604,14 +605,17 @@ def render_outlines(c: Canvas, layout: PaperConfig) -> None:

# Resistor values typically come from an "E series of preferred numbers". This is why apparently
# random values such as 22, 39, or 47 are common, but some round numbers like 25, 40, or 50
# are rarely seen. 10% resistors usually come from the E12 series, while 5% resistors usually
# come from to an abridged version of the E24 series.
# are rarely seen. 10% resistors usually come from the E12 series, while 5% resistors usually
# come from an abridged version of the E24 series.
#
# The list constants below can be used with the generate_values function to quickly create sets of
# common resistor values.
E12_VALUES = [ 1.0, 1.2, 1.5, 1.8, 2.2, 2.7, 3.3, 3.9, 4.7, 5.6, 6.8, 8.2 ]
E24_COMMON_VALUES = [ 1.0, 1.2, 1.5, 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 ]
E24_ALL_VALUES = [ 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 ]
E12_VALUES = [1.0, 1.2, 1.5, 1.8, 2.2, 2.7, 3.3, 3.9, 4.7, 5.6, 6.8, 8.2]
E24_COMMON_VALUES = [1.0, 1.2, 1.5, 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]
E24_ALL_VALUES = [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]


# Scales a list of values by a power of 10. The list may be one of the E constants above, or your
# own list of values.
Expand All @@ -621,12 +625,13 @@ def render_outlines(c: Canvas, layout: PaperConfig) -> None:
#
# scale_values(E12_VALUES, 1) -> [ 10, 12, 15, 18, 22, 27, 33, 39, 47, 56, 68, 82 ]
def scale_values(
series: List[float], # the base series of resistor values
power: int # the power of 10 to scale the series by
series: List[float], # the base series of resistor values
power: int # the power of 10 to scale the series by
) -> List[float]:
scalar = 10 ** power
return [scalar * x for x in series]


# Expands a list of values into several lists, each scaled by increasing powers of 10. The list may
# be one of the E constants above, or your own list of values.
#
Expand All @@ -642,12 +647,13 @@ def scale_values(
# [ 100, 120, 150, 180, 220, 270, 330, 390, 470, 560, 680, 820 ] # 10 ** 2 -> x100
# ]
def generate_values(
series: List[float], # the base series of resistor values
first_power: int, # the first power of 10 to scale the series by
last_power: int # the last power of 10 to scale the series by
) -> ResistorList:
series: List[float], # the base series of resistor values
first_power: int, # the first power of 10 to scale the series by
last_power: int # the last power of 10 to scale the series by
) -> List[list[float]]:
Finomnis marked this conversation as resolved.
Show resolved Hide resolved
return [scale_values(series, x) for x in range(first_power, last_power)]


def main() -> None:

# ############################################################################
Expand Down Expand Up @@ -678,7 +684,7 @@ def main() -> None:
]

# ############################################################################
# Alternatively, a set of common resistor values can be generated by the
# Alternatively, a set of common resistor values can be generated by the
# generate_values function.
# ############################################################################
# resistor_values: ResistorList = [ 0, 0.01 ] + generate_values(E24_COMMON_VALUES, 0, 6)
Expand Down
Loading