summaryrefslogtreecommitdiff
path: root/source/misc/unclassified/paper_covered_fan/fan.py
diff options
context:
space:
mode:
Diffstat (limited to 'source/misc/unclassified/paper_covered_fan/fan.py')
-rwxr-xr-xsource/misc/unclassified/paper_covered_fan/fan.py118
1 files changed, 118 insertions, 0 deletions
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()