"""Thread strips: one horizontal, seamless tile per thread look (greyscale, gradient-mapped by the app). Black = dark edge (THREAD_DARK), mid grey = thread colour, white = highlight. Source units are 4x px. Every shape sits inside the tile (or repeats exactly at its edges), so the strip tiles left to right. """ from svg_common import grey, num, svg_document SOURCE_SCALE = 4 def _band(length, height, band_height, lightness, opacity=1.0, shift=0.0): """A full-length horizontal band, centred (plus `shift`) in the strip.""" top = (height - band_height) / 2 + shift return (f'') def _dash(length, height, dash_length): """One round-ended dash, centred in the tile (a CSS dash plus its round caps).""" visible = dash_length + height return (f'') def _twisted_strand(length, height, strand_width, slant): """One slanted strand of a twisted rope, centred in the tile, with a soft shine line.""" middle_x, middle_y = length / 2, height / 2 reach_y = height / 2 - strand_width / 2 start = f"{num(middle_x - slant)},{num(middle_y + reach_y)}" end = f"{num(middle_x + slant)},{num(middle_y - reach_y)}" return (f'' f'') def dashed_line(length, height): return _dash(length, height, length * 10 / 16) def neon_tube(length, height): return (_band(length, height, height, 0.5, 0.25) + _band(length, height, height * 0.56, 0.5, 0.3) + _band(length, height, height * 0.31, 0.5) + _band(length, height, height * 0.12, 1.0, 0.8)) def twine(length, height): return _band(length, height, height, 0.0) + _twisted_strand(length, height, height * 0.6, length * 0.2) def rope(length, height): return _band(length, height, height, 0.0) + _twisted_strand(length, height, height * 0.46, length * 0.24) def vine(length, height): return _band(length, height, height, 0.5) + _band(length, height, height * 0.2, 1.0, 0.25, -height * 0.18) def kite_string(length, height): return _band(length, height, height, 0.0, 0.25) + _band(length, height, height / 2, 0.5) def glossy_tube(length, height): return (_band(length, height, height, 0.0) + _band(length, height, height * 0.58, 0.5) + _band(length, height, height * 0.2, 1.0, 0.56, -height * 0.12)) def cord(length, height): return _band(length, height, height, 0.0) + _band(length, height, height / 2, 0.5) def dashed_amber(length, height): return _dash(length, height, length * 6 / 10) # thread look -> (maker, drawn width in px, repeat length in px) THREAD_LOOKS = { "dashed_line": (dashed_line, 3, 16), "neon_tube": (neon_tube, 8, 8), "twine": (twine, 4, 8), "rope": (rope, 5.5, 6), "vine": (vine, 3, 12), "kite_string": (kite_string, 6, 8), "glossy_tube": (glossy_tube, 6, 8), "cord": (cord, 4, 8), "dashed_amber": (dashed_amber, 2.5, 10), } from threads_more import MORE_THREAD_LOOKS # noqa: E402 (second batch) THREAD_LOOKS.update(MORE_THREAD_LOOKS) def make_thread_strip(look): """Return (svg_text, meta) for a thread look.""" maker, width_px, repeat_px = THREAD_LOOKS[look] length, height = round(repeat_px * SOURCE_SCALE), round(width_px * SOURCE_SCALE) # whole numbers: importers round sizes return svg_document(length, height, maker(length, height)), {"strip_size": [length, height], "width": width_px}