whirligig 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 GabeBecker2048
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,36 @@
1
+ Metadata-Version: 2.3
2
+ Name: whirligig
3
+ Version: 0.1.0
4
+ Summary: A fun wheel spinner for python and CLI
5
+ Keywords: wheel,spinner,terminal,ascii,random,picker
6
+ Author: GabeBecker2048
7
+ License: MIT License
8
+
9
+ Copyright (c) 2026 GabeBecker2048
10
+
11
+ Permission is hereby granted, free of charge, to any person obtaining a copy
12
+ of this software and associated documentation files (the "Software"), to deal
13
+ in the Software without restriction, including without limitation the rights
14
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15
+ copies of the Software, and to permit persons to whom the Software is
16
+ furnished to do so, subject to the following conditions:
17
+
18
+ The above copyright notice and this permission notice shall be included in all
19
+ copies or substantial portions of the Software.
20
+
21
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27
+ SOFTWARE.
28
+ Classifier: License :: OSI Approved :: MIT License
29
+ Classifier: Programming Language :: Python :: 3
30
+ Classifier: Environment :: Console
31
+ Classifier: Topic :: Games/Entertainment
32
+ Requires-Python: >=3.9
33
+ Description-Content-Type: text/markdown
34
+
35
+ # whirligig
36
+ A fun wheel spinner for python and CLI
@@ -0,0 +1,2 @@
1
+ # whirligig
2
+ A fun wheel spinner for python and CLI
@@ -0,0 +1,22 @@
1
+ [project]
2
+ name = "whirligig"
3
+ version = "0.1.0"
4
+ description = "A fun wheel spinner for python and CLI"
5
+ readme = "README.md"
6
+ license = { file = "LICENSE" }
7
+ authors = [
8
+ { name = "GabeBecker2048" },
9
+ ]
10
+ requires-python = ">=3.9"
11
+ dependencies = []
12
+ keywords = ["wheel", "spinner", "terminal", "ascii", "random", "picker"]
13
+ classifiers = [
14
+ "License :: OSI Approved :: MIT License",
15
+ "Programming Language :: Python :: 3",
16
+ "Environment :: Console",
17
+ "Topic :: Games/Entertainment",
18
+ ]
19
+
20
+ [build-system]
21
+ requires = ["uv_build>=0.8.24,<0.9.0"]
22
+ build-backend = "uv_build"
@@ -0,0 +1,3 @@
1
+ from whirligig.spinner import spin
2
+
3
+ __all__ = ["spin"]
@@ -0,0 +1,137 @@
1
+ from math import sin, cos, pi
2
+ from copy import deepcopy
3
+ import os
4
+ import random
5
+ import time
6
+
7
+ WHEEL_RADIUS = 10
8
+ DELAY = 0.1
9
+
10
+ class Colors:
11
+ """ ANSI color codes """
12
+ RESET = "\033[0m"
13
+ colors = [
14
+ "\033[0;31m",
15
+ "\033[0;32m",
16
+ "\033[0;33m",
17
+ "\033[0;34m",
18
+ "\033[0;35m",
19
+ "\033[0;36m",
20
+ "\033[0;37m",
21
+ "\033[1;31m",
22
+ "\033[1;32m",
23
+ "\033[1;33m",
24
+ "\033[1;34m",
25
+ "\033[1;35m",
26
+ "\033[1;36m",
27
+ ]
28
+
29
+
30
+ class Wheel:
31
+ def __init__(self, radius, labels) -> None:
32
+ self.r = radius
33
+ self.d = radius*2
34
+ self.labels = labels
35
+ self.m = [" " * (self.d+1)] * (self.d+1)
36
+ self.num_labels = len(labels)
37
+ self.angles = [pi/(self.num_labels/2) * p for p in range(self.num_labels)]
38
+ self.points = []
39
+ for i in range(self.num_labels):
40
+ p = self.get_coords(i, self.r)
41
+ self[p] = "*"
42
+ self.points.append(p)
43
+
44
+ def __setitem__(self, key: tuple[int, int], value: str) -> None:
45
+ x, y = key
46
+ lrow = list(self.m[y])
47
+ lrow[x] = value
48
+ self.m[y] = "".join(lrow)
49
+
50
+ def __getitem__(self, key: tuple[int, int]) -> str:
51
+ x, y = key
52
+ return self.m[y][x]
53
+
54
+ def __str__(self) -> str:
55
+ return "\n".join(self.m)
56
+
57
+ def add_labels(self, inplace = False):
58
+ wheel = self if inplace else deepcopy(self)
59
+
60
+ # adds whitespace
61
+ whitespace = " " * (len(max(wheel.labels, key=len)) + 1)
62
+ for y in range(len(wheel.m)):
63
+ wheel.m[y] = wheel.m[y].replace(" ", " ").replace("*", " * ")
64
+ wheel.m[y] = whitespace + wheel.m[y] + whitespace
65
+
66
+ # adds labels
67
+ for label, point in zip(wheel.labels, wheel.points):
68
+ x, y = point
69
+ if x<wheel.r or (x==wheel.r and y<wheel.r):
70
+ for i in range(len(label)):
71
+ ix = x-len(label) + i + len(whitespace) + (x * 2)
72
+ wheel[ix, y] = label[i]
73
+ elif x>wheel.r or (x==wheel.r and y>wheel.r):
74
+ for i in range(len(label)):
75
+ ix = x+3 + i + len(whitespace) + (x * 2)
76
+ wheel[ix, y] = label[i]
77
+
78
+ # adds color
79
+ for y in range(len(wheel.m)):
80
+ for i, label in enumerate(wheel.labels):
81
+ wheel.m[y] = wheel.m[y].replace(f" {label} *", f" {Colors.colors[i%len(Colors.colors)]}{label} *{Colors.RESET}")
82
+ wheel.m[y] = wheel.m[y].replace(f"* {label} ", f"{Colors.colors[i%len(Colors.colors)]}* {label}{Colors.RESET} ")
83
+
84
+ return wheel
85
+
86
+ # given an angle and a scaler, returns a tuple of coords to the point
87
+ def get_coords(self, idx: int, scaler: int) -> tuple[int, int]:
88
+ a = self.angles[idx]
89
+ return round(cos(a)*scaler) + self.r, round(sin(a)*scaler) + self.r
90
+
91
+ # given an angle and the circle array, we return a deepcopy with a line drawn from the center
92
+ def draw_line(self, idx: int):
93
+ c = deepcopy(self)
94
+ for line_scaler in range(1, c.r):
95
+ p = c.get_coords(idx, line_scaler)
96
+ c[p] = "*"
97
+ return c
98
+
99
+
100
+ # clears the screen
101
+ def clear() -> None:
102
+ if os.name == 'nt':
103
+ os.system('cls')
104
+ else:
105
+ os.system('clear')
106
+
107
+ # clears the screen, prints the circle, waits DELAY
108
+ def display(wheel: Wheel, i=-1) -> None:
109
+ wheel = wheel.draw_line(i)
110
+ wheel = wheel.add_labels()
111
+ clear()
112
+ print(wheel)
113
+ if i != -1:
114
+ print(f"You got {Colors.colors[i%len(Colors.colors)]}{wheel.labels[i]}{Colors.RESET}!")
115
+ time.sleep(DELAY)
116
+
117
+ ## THE MAIN FUNCTION ##
118
+ # given a list, this function will create and print a spinning wheel ASCII animation
119
+ def spin(labels: list[str], w_radius=WHEEL_RADIUS):
120
+ wheel = Wheel(w_radius, labels)
121
+
122
+ # full rotations
123
+ for j in range(random.randint(2, 5)):
124
+ for i in range(wheel.num_labels):
125
+ display(wheel, i=i)
126
+
127
+ # actual choice
128
+ for i in range(random.randint(1, wheel.num_labels)):
129
+ display(wheel, i=i)
130
+
131
+
132
+ if __name__ == "__main__":
133
+ dice_roll = [str(i+1) for i in range(6)]
134
+ clock = [str((i+2)%12 + 1) for i in range(12)]
135
+ alphabet = list(map(chr, range(ord('a'), ord('z')+1)))
136
+ coin_flip = ["heads", "tails"]
137
+ spin(random.choice([dice_roll, clock, alphabet, coin_flip]))