manim-chess 0.0.1__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
src/pieces.py ADDED
@@ -0,0 +1,246 @@
1
+ import os
2
+ from manim import *
3
+
4
+ class Pawn(Mobject):
5
+ """
6
+ A class to represent a Pawn chess piece using Manim for visualization.
7
+
8
+ Attributes:
9
+ ----------
10
+ piece_size : float
11
+ The size of the chess piece.
12
+ is_white : bool
13
+ A boolean indicating if the piece is white.
14
+
15
+ Methods:
16
+ -------
17
+ create_svg():
18
+ Creates and adds the SVG representation of the pawn to the Mobject.
19
+ """
20
+ def __init__(self, is_white: bool, piece_size=1.1) -> None:
21
+ """
22
+ Initializes the Pawn object with specified color and size.
23
+
24
+ Parameters:
25
+ ----------
26
+ is_white : bool
27
+ Indicates if the pawn is white.
28
+ piece_size : float, optional
29
+ The size of the pawn (default is 1.1).
30
+ """
31
+ super().__init__()
32
+ self.piece_size = piece_size
33
+ self.is_white = is_white
34
+ self.create_svg()
35
+
36
+ def create_svg(self) -> SVGMobject:
37
+ """
38
+ Creates the SVG representation of the pawn and adds it to the Mobject.
39
+ """
40
+ svg_path = os.path.join(os.path.dirname(__file__), 'piece_svgs', 'wP.svg' if self.is_white else 'bP.svg')
41
+ self.add(SVGMobject(svg_path).scale(self.piece_size / 4))
42
+
43
+ class Knight(Mobject):
44
+ """
45
+ A class to represent a Knight chess piece using Manim for visualization.
46
+
47
+ Attributes:
48
+ ----------
49
+ piece_size : float
50
+ The size of the chess piece.
51
+
52
+ Methods:
53
+ -------
54
+ create_svg(is_white):
55
+ Creates and adds the SVG representation of the knight to the Mobject.
56
+ """
57
+ def __init__(self, is_white: bool, piece_size=1.1) -> None:
58
+ """
59
+ Initializes the Knight object with specified color and size.
60
+
61
+ Parameters:
62
+ ----------
63
+ is_white : bool
64
+ Indicates if the knight is white.
65
+ piece_size : float, optional
66
+ The size of the knight (default is 1.1).
67
+ """
68
+ super().__init__()
69
+ self.piece_size = piece_size
70
+ self.create_svg(is_white)
71
+
72
+ def create_svg(self, is_white: bool) -> SVGMobject:
73
+ """
74
+ Creates the SVG representation of the knight and adds it to the Mobject.
75
+
76
+ Parameters:
77
+ ----------
78
+ is_white : bool
79
+ Indicates if the knight is white.
80
+ """
81
+ svg_path = os.path.join(os.path.dirname(__file__), 'piece_svgs', 'wN.svg' if is_white else 'bN.svg')
82
+ self.add(SVGMobject(svg_path).scale(self.piece_size / 4))
83
+
84
+ class Bishop(Mobject):
85
+ """
86
+ A class to represent a Bishop chess piece using Manim for visualization.
87
+
88
+ Attributes:
89
+ ----------
90
+ piece_size : float
91
+ The size of the chess piece.
92
+
93
+ Methods:
94
+ -------
95
+ create_svg(is_white):
96
+ Creates and adds the SVG representation of the bishop to the Mobject.
97
+ """
98
+ def __init__(self, is_white: bool, piece_size=1.1) -> None:
99
+ """
100
+ Initializes the Bishop object with specified color and size.
101
+
102
+ Parameters:
103
+ ----------
104
+ is_white : bool
105
+ Indicates if the bishop is white.
106
+ piece_size : float, optional
107
+ The size of the bishop (default is 1.1).
108
+ """
109
+ super().__init__()
110
+ self.piece_size = piece_size
111
+ self.create_svg(is_white)
112
+
113
+ def create_svg(self, is_white: bool) -> SVGMobject:
114
+ """
115
+ Creates the SVG representation of the bishop and adds it to the Mobject.
116
+
117
+ Parameters:
118
+ ----------
119
+ is_white : bool
120
+ Indicates if the bishop is white.
121
+ """
122
+ svg_path = os.path.join(os.path.dirname(__file__), 'piece_svgs', 'wB.svg' if is_white else 'bB.svg')
123
+ self.add(SVGMobject(svg_path).scale(self.piece_size / 4))
124
+
125
+ class Rook(Mobject):
126
+ """
127
+ A class to represent a Rook chess piece using Manim for visualization.
128
+
129
+ Attributes:
130
+ ----------
131
+ piece_size : float
132
+ The size of the chess piece.
133
+
134
+ Methods:
135
+ -------
136
+ create_svg(is_white):
137
+ Creates and adds the SVG representation of the rook to the Mobject.
138
+ """
139
+ def __init__(self, is_white: bool, piece_size=1.1) -> None:
140
+ """
141
+ Initializes the Rook object with specified color and size.
142
+
143
+ Parameters:
144
+ ----------
145
+ is_white : bool
146
+ Indicates if the rook is white.
147
+ piece_size : float, optional
148
+ The size of the rook (default is 1.1).
149
+ """
150
+ super().__init__()
151
+ self.piece_size = piece_size
152
+ self.create_svg(is_white)
153
+
154
+ def create_svg(self, is_white: bool) -> SVGMobject:
155
+ """
156
+ Creates the SVG representation of the rook and adds it to the Mobject.
157
+
158
+ Parameters:
159
+ ----------
160
+ is_white : bool
161
+ Indicates if the rook is white.
162
+ """
163
+ svg_path = os.path.join(os.path.dirname(__file__), 'piece_svgs', 'wR.svg' if is_white else 'bR.svg')
164
+ self.add(SVGMobject(svg_path).scale(self.piece_size / 4))
165
+
166
+ class Queen(Mobject):
167
+ """
168
+ A class to represent a Queen chess piece using Manim for visualization.
169
+
170
+ Attributes:
171
+ ----------
172
+ piece_size : float
173
+ The size of the chess piece.
174
+
175
+ Methods:
176
+ -------
177
+ create_svg(is_white):
178
+ Creates and adds the SVG representation of the queen to the Mobject.
179
+ """
180
+ def __init__(self, is_white: bool, piece_size=1.1) -> None:
181
+ """
182
+ Initializes the Queen object with specified color and size.
183
+
184
+ Parameters:
185
+ ----------
186
+ is_white : bool
187
+ Indicates if the queen is white.
188
+ piece_size : float, optional
189
+ The size of the queen (default is 1.1).
190
+ """
191
+ super().__init__()
192
+ self.piece_size = piece_size
193
+ self.create_svg(is_white)
194
+
195
+ def create_svg(self, is_white: bool) -> SVGMobject:
196
+ """
197
+ Creates the SVG representation of the queen and adds it to the Mobject.
198
+
199
+ Parameters:
200
+ ----------
201
+ is_white : bool
202
+ Indicates if the queen is white.
203
+ """
204
+ svg_path = os.path.join(os.path.dirname(__file__), 'piece_svgs', 'wQ.svg' if is_white else 'bQ.svg')
205
+ self.add(SVGMobject(svg_path).scale(self.piece_size / 4))
206
+
207
+ class King(Mobject):
208
+ """
209
+ A class to represent a King chess piece using Manim for visualization.
210
+
211
+ Attributes:
212
+ ----------
213
+ piece_size : float
214
+ The size of the chess piece.
215
+
216
+ Methods:
217
+ -------
218
+ create_svg(is_white):
219
+ Creates and adds the SVG representation of the king to the Mobject.
220
+ """
221
+ def __init__(self, is_white: bool, piece_size=1.1) -> None:
222
+ """
223
+ Initializes the King object with specified color and size.
224
+
225
+ Parameters:
226
+ ----------
227
+ is_white : bool
228
+ Indicates if the king is white.
229
+ piece_size : float, optional
230
+ The size of the king (default is 1.1).
231
+ """
232
+ super().__init__()
233
+ self.piece_size = piece_size
234
+ self.create_svg(is_white)
235
+
236
+ def create_svg(self, is_white: bool) -> SVGMobject:
237
+ """
238
+ Creates the SVG representation of the king and adds it to the Mobject.
239
+
240
+ Parameters:
241
+ ----------
242
+ is_white : bool
243
+ Indicates if the king is white.
244
+ """
245
+ svg_path = os.path.join(os.path.dirname(__file__), 'piece_svgs', 'wK.svg' if is_white else 'bK.svg')
246
+ self.add(SVGMobject(svg_path).scale(self.piece_size / 4))