From e54fafdcfcfd2947fcd96a7d1e392be573ae2edb Mon Sep 17 00:00:00 2001 From: Elena ``of Valhalla'' Grandi Date: Wed, 16 Aug 2023 19:38:46 +0200 Subject: Script to generate a fan pattern --- source/misc/unclassified/index.rst | 13 +++ source/misc/unclassified/paper_covered_fan/fan.py | 118 +++++++++++++++++++++ .../misc/unclassified/paper_covered_fan/index.rst | 26 +++++ 3 files changed, 157 insertions(+) create mode 100644 source/misc/unclassified/index.rst create mode 100755 source/misc/unclassified/paper_covered_fan/fan.py create mode 100644 source/misc/unclassified/paper_covered_fan/index.rst (limited to 'source/misc/unclassified') diff --git a/source/misc/unclassified/index.rst b/source/misc/unclassified/index.rst new file mode 100644 index 0000000..8a3ccdd --- /dev/null +++ b/source/misc/unclassified/index.rst @@ -0,0 +1,13 @@ +************** + Unclassified +************** + +Things in this chapter may be moved elsewhere if a more suitable +chapter is addded. + +.. toctree:: + :maxdepth: 2 + :caption: Contents: + + paper_covered_fan/index + diff --git a/source/misc/unclassified/paper_covered_fan/fan.py b/source/misc/unclassified/paper_covered_fan/fan.py new file mode 100755 index 0000000..e50ac75 --- /dev/null +++ b/source/misc/unclassified/paper_covered_fan/fan.py @@ -0,0 +1,118 @@ +#!/usr/bin/env python3 + +import math + +import hazwaz +import svgwrite + + +# 1 cm in px +cm = 37.795276 + +LINE_STYLE = { + 'stroke': svgwrite.utils.rgb(0, 0, 0), + 'stroke_width': 0.5, + 'fill': 'none' + } + +FOLD_LINE_STYLE = { + 'stroke': svgwrite.utils.rgb(0, 0, 0), + 'stroke_width': 0.5, + 'fill': 'none', + 'stroke-dasharray': "5,5", + } + +class Fan(hazwaz.MainCommand): + """ + Draw a fan cover + """ + + def add_arguments(self, parser): + parser.add_argument( + "-o", "--outer_radius", + type=float, + default=25.0, + help="Outer radius of the fan sticks (cm)", + ) + parser.add_argument( + "-i", "--inner_radius", + type=float, + default=10.0, + help="Outer radius of the fan sticks (cm)", + ) + parser.add_argument( + "-w", "--folded_width", + type=float, + default=2.0, + help="Width of the outer sticks (and folded fan) at the top", + ) + parser.add_argument( + "-s", "--sticks", + type=int, + default=12, + help="Number of sticks (excluding the outer ones)." + ) + + def main(self): + self.sections = self.args.sticks * 2 + 3 + self.alpha = self.args.folded_width / self.args.outer_radius + self.angle = self.alpha * self.sections + + size = str(self.args.outer_radius * 2 + 2) + "cm" + dest = dest = svgwrite.Drawing( + filename="fan.svg", + size=(size, size), + profile="full", + ) + fan = self.draw_fan(dest) + dest.save() + + def draw_fan(self, dest): + c = (self.args.outer_radius + 1 )* cm + a = self.alpha + r_o = self.args.outer_radius + r_i = self.args.inner_radius + + grp = dest.g() + grp.add(dest.circle( + center=(c, c), + r=r_o * cm, + ** LINE_STYLE + )) + grp.add(dest.circle( + center=(c, c), + r=r_i * cm, + ** LINE_STYLE + )) + grp.add(dest.line( + start=(c + r_i * cm, c), + end=(c + r_o * cm, c), + ** LINE_STYLE + )) + for i in range(1, self.sections): + grp.add(dest.line( + start=( + c + (math.cos(a * - i) * r_i) * cm, + c + (math.sin(a * - i) * r_i) * cm + ), + end=( + c + (math.cos(a * - i) * r_o) * cm, + c + (math.sin(a * - i) * r_o) * cm + ), + ** FOLD_LINE_STYLE + )) + grp.add(dest.line( + start=( + c + (math.cos(a * - self.sections) * r_i) * cm, + c + (math.sin(a * - self.sections) * r_i) * cm + ), + end=( + c + (math.cos(a * - self.sections) * r_o) * cm, + c + (math.sin(a * - self.sections) * r_o) * cm + ), + ** LINE_STYLE + )) + dest.add(grp) + +if __name__ == "__main__": + Fan().run() diff --git a/source/misc/unclassified/paper_covered_fan/index.rst b/source/misc/unclassified/paper_covered_fan/index.rst new file mode 100644 index 0000000..83e7af1 --- /dev/null +++ b/source/misc/unclassified/paper_covered_fan/index.rst @@ -0,0 +1,26 @@ +Paper Covered Fan +================= + +.. figure:: + :align: center + +.. only:: html + + .. contents:: + + +Materials +--------- + +You need: + +* A fan + + +Instructions +------------ + + +See also +-------- + -- cgit v1.2.3