From c1a44143d9dc9e8b04db5440b29eb35826440fbb Mon Sep 17 00:00:00 2001 From: erjemin Date: Sat, 5 Sep 2026 23:23:42 +0300 Subject: [PATCH] =?UTF-8?q?mod:=20=D1=8F=D0=B4=D1=80=D0=BE=20(12)=20=D0=B2?= =?UTF-8?q?=D0=BC=D0=B5=D1=81=D1=82=D0=BE=20=D1=81=D0=B8=D0=BD=D1=83=D1=81?= =?UTF-8?q?=D0=BE=D0=B8=D0=B4-=D1=87=D0=B5=D1=80=D0=B2=D1=8F=D1=87=D0=BA?= =?UTF-8?q?=D0=BE=D0=B2=20--=20=D1=81=D0=BD=D0=B5=D0=B6=D0=B8=D0=BD=D0=BA?= =?UTF-8?q?=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hypn0/hypn0_site/forms.py | 1 + hypn0/hypn0_site/services/halftone.py | 16 ++++++++++++---- hypn0/hypn0_site/tests.py | 7 ++++++- hypn0/templates/index.html | 10 +++++----- 4 files changed, 24 insertions(+), 10 deletions(-) diff --git a/hypn0/hypn0_site/forms.py b/hypn0/hypn0_site/forms.py index 041a5a7..ea4dd3c 100644 --- a/hypn0/hypn0_site/forms.py +++ b/hypn0/hypn0_site/forms.py @@ -15,6 +15,7 @@ class HalftoneGenerateForm(forms.Form): ("star", "Звезда"), ("cross", "Крестик"), ("line", "Линия"), + ("snowflake", "Снежинка"), ("wave", "Волна"), ("heart", "Сердечко"), ] diff --git a/hypn0/hypn0_site/services/halftone.py b/hypn0/hypn0_site/services/halftone.py index 2096e07..7b348f4 100644 --- a/hypn0/hypn0_site/services/halftone.py +++ b/hypn0/hypn0_site/services/halftone.py @@ -76,9 +76,17 @@ def generate_shape_def(shape: str, radius: int, shape_id: str) -> str: th = max(1, round(r * 0.25)) return f'' - case "wave": - th = max(1.0, r * 0.3) - return f'' + case "snowflake": + points = [] + inner_r = max(0.5, r * 0.25) + for i in range(16): + angle = i * math.pi / 8 - math.pi / 2 + curr_r = r if i % 2 == 0 else inner_r + px = round(curr_r * math.cos(angle), 1) + py = round(curr_r * math.sin(angle), 1) + points.append(f"{px},{py}") + pts_str = " ".join(points) + return f'' case "heart": r_top = round(r * 0.3) @@ -114,7 +122,7 @@ def generate_halftone_svg( - image: PIL Image, файловый объект (BytesIO), байты или путь к файлу - cols: число точек по наибольшей стороне сетки (10-200) - max_radius: максимальный радиус/размер точки (3-20) - - shape: тип фигуры ('circle', 'ring', 'square', 'diamond', 'triangle', 'hexagon', 'star', 'cross', 'line', 'wave', 'heart') + - shape: тип фигуры ('circle', 'ring', 'square', 'diamond', 'triangle', 'hexagon', 'star', 'cross', 'line', 'snowflake', 'heart') - color: основной HEX цвет (например '#a855ff') - opacity: коэффициент непрозрачности (0.0 - 1.0) - blink: интенсивность мерцания (0 - выключено/статичный, 1-10 - скорость) diff --git a/hypn0/hypn0_site/tests.py b/hypn0/hypn0_site/tests.py index 91c0df1..4277724 100644 --- a/hypn0/hypn0_site/tests.py +++ b/hypn0/hypn0_site/tests.py @@ -78,7 +78,7 @@ class HalftoneServiceTests(BaseMediaTestCase): self.assertIn("Generated by Hypn0", svg) def test_generate_shapes(self): - shapes = ["circle", "ring", "square", "diamond", "triangle", "hexagon", "star", "cross", "line", "wave", "heart"] + shapes = ["circle", "ring", "square", "diamond", "triangle", "hexagon", "star", "cross", "line", "snowflake", "heart"] for shape in shapes: svg = generate_halftone_svg(self.img, cols=20, max_radius=5, shape=shape) self.assertIn(" - -