summaryrefslogtreecommitdiff
path: root/source/misc/unclassified/paper_covered_fan/fan.py
blob: e50ac75942bf299576aa8f1e1986dafb9e59393a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
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()