ConsoleLib 1.3.3__tar.gz → 1.3.4__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.
- {consolelib-1.3.3 → consolelib-1.3.4}/ConsoleLib/__init__.py +147 -100
- {consolelib-1.3.3 → consolelib-1.3.4}/ConsoleLib.egg-info/PKG-INFO +1 -1
- {consolelib-1.3.3 → consolelib-1.3.4}/PKG-INFO +1 -1
- {consolelib-1.3.3 → consolelib-1.3.4}/pyproject.toml +1 -1
- {consolelib-1.3.3 → consolelib-1.3.4}/ConsoleLib.egg-info/SOURCES.txt +0 -0
- {consolelib-1.3.3 → consolelib-1.3.4}/ConsoleLib.egg-info/dependency_links.txt +0 -0
- {consolelib-1.3.3 → consolelib-1.3.4}/ConsoleLib.egg-info/top_level.txt +0 -0
- {consolelib-1.3.3 → consolelib-1.3.4}/README.md +0 -0
- {consolelib-1.3.3 → consolelib-1.3.4}/setup.cfg +0 -0
|
@@ -10,7 +10,9 @@ import time
|
|
|
10
10
|
import subprocess as CMD
|
|
11
11
|
import math
|
|
12
12
|
import random
|
|
13
|
-
|
|
13
|
+
import threading
|
|
14
|
+
from typing import Optional, Iterator, List, Tuple, Union
|
|
15
|
+
|
|
14
16
|
class Colors:
|
|
15
17
|
RESET = "\033[0m"
|
|
16
18
|
BOLD = "\033[1m"
|
|
@@ -53,19 +55,25 @@ class Colors:
|
|
|
53
55
|
BG_BRIGHT_MAGENTA = "\033[105m"
|
|
54
56
|
BG_BRIGHT_CYAN = "\033[106m"
|
|
55
57
|
BG_BRIGHT_WHITE = "\033[107m"
|
|
58
|
+
|
|
56
59
|
@staticmethod
|
|
57
60
|
def rgb(r, g, b):
|
|
58
61
|
return f"\033[38;2;{r};{g};{b}m"
|
|
62
|
+
|
|
59
63
|
@staticmethod
|
|
60
64
|
def bg_rgb(r, g, b):
|
|
61
65
|
return f"\033[48;2;{r};{g};{b}m"
|
|
66
|
+
|
|
62
67
|
@staticmethod
|
|
63
68
|
def colorize(text, color, reset=True):
|
|
64
69
|
reset_code = Colors.RESET if reset else ""
|
|
65
70
|
return f"{color}{text}{reset_code}"
|
|
71
|
+
|
|
72
|
+
|
|
66
73
|
class Animate:
|
|
67
74
|
def clear_screen():
|
|
68
|
-
os.system('cls' if os.name == 'nt' else 'clear')
|
|
75
|
+
os.system('cls' if os.name == 'nt' else 'clear')
|
|
76
|
+
|
|
69
77
|
class ProgressBar:
|
|
70
78
|
def __init__(
|
|
71
79
|
self,
|
|
@@ -94,18 +102,18 @@ class Animate:
|
|
|
94
102
|
self._lock = threading.Lock()
|
|
95
103
|
self._finished = False
|
|
96
104
|
self._cleared = False
|
|
97
|
-
|
|
105
|
+
|
|
98
106
|
def update(self, increment: int = 1) -> None:
|
|
99
107
|
with self._lock:
|
|
100
108
|
if self._finished:
|
|
101
109
|
return
|
|
102
110
|
self.current = min(self.current + increment, self.total)
|
|
103
111
|
self._print_bar()
|
|
104
|
-
|
|
112
|
+
|
|
105
113
|
if self.current >= self.total:
|
|
106
114
|
self._finished = True
|
|
107
115
|
print()
|
|
108
|
-
|
|
116
|
+
|
|
109
117
|
def set(self, value: int) -> None:
|
|
110
118
|
with self._lock:
|
|
111
119
|
if self._finished:
|
|
@@ -115,6 +123,7 @@ class Animate:
|
|
|
115
123
|
if self.current >= self.total:
|
|
116
124
|
self._finished = True
|
|
117
125
|
print()
|
|
126
|
+
|
|
118
127
|
def _print_bar(self) -> None:
|
|
119
128
|
percent = self.current / self.total
|
|
120
129
|
filled_len = int(self.length * percent)
|
|
@@ -129,22 +138,25 @@ class Animate:
|
|
|
129
138
|
line = " ".join(parts)
|
|
130
139
|
sys.stdout.write("\r" + line)
|
|
131
140
|
sys.stdout.flush()
|
|
132
|
-
|
|
141
|
+
|
|
133
142
|
def __enter__(self):
|
|
134
143
|
if self.auto_clear and not self._cleared:
|
|
135
|
-
clear_screen()
|
|
144
|
+
Animate.clear_screen()
|
|
136
145
|
self._cleared = True
|
|
137
146
|
if self.clear_delay > 0:
|
|
138
147
|
time.sleep(self.clear_delay)
|
|
139
148
|
return self
|
|
149
|
+
|
|
140
150
|
def __exit__(self, exc_type, exc_val, exc_tb):
|
|
141
151
|
if not self._finished:
|
|
142
152
|
self._print_bar()
|
|
143
153
|
print()
|
|
154
|
+
|
|
144
155
|
def iterate(self, iterable: Iterator) -> Iterator:
|
|
145
156
|
for i, item in enumerate(iterable):
|
|
146
157
|
yield item
|
|
147
158
|
self.update(1)
|
|
159
|
+
|
|
148
160
|
def animate_print(
|
|
149
161
|
text: str,
|
|
150
162
|
delay: float = 0.05,
|
|
@@ -177,6 +189,7 @@ class Animate:
|
|
|
177
189
|
sys.stdout.write(end)
|
|
178
190
|
if flush:
|
|
179
191
|
sys.stdout.flush()
|
|
192
|
+
|
|
180
193
|
def spinning_cursor(
|
|
181
194
|
message: str = "Loading",
|
|
182
195
|
duration: float = 3.0,
|
|
@@ -185,7 +198,7 @@ class Animate:
|
|
|
185
198
|
clear_before: bool = False,
|
|
186
199
|
) -> None:
|
|
187
200
|
if clear_before:
|
|
188
|
-
clear_screen()
|
|
201
|
+
Animate.clear_screen()
|
|
189
202
|
if frames is None:
|
|
190
203
|
frames = ["|", "/", "-", r"\\"]
|
|
191
204
|
end_time = time.time() + duration
|
|
@@ -198,16 +211,20 @@ class Animate:
|
|
|
198
211
|
idx += 1
|
|
199
212
|
sys.stdout.write("\r" + " " * (len(message) + 3) + "\r")
|
|
200
213
|
sys.stdout.flush()
|
|
214
|
+
|
|
201
215
|
def countdown(seconds: int, message: str = "Countdown", clear_before: bool = False) -> None:
|
|
202
216
|
if clear_before:
|
|
203
|
-
clear_screen()
|
|
217
|
+
Animate.clear_screen()
|
|
204
218
|
for remaining in range(seconds, 0, -1):
|
|
205
219
|
sys.stdout.write(f"\r{message}: {remaining:2d} seconds remaining ")
|
|
206
220
|
sys.stdout.flush()
|
|
207
221
|
time.sleep(1)
|
|
208
222
|
sys.stdout.write(f"\r{message}: 0 seconds remaining! Done!\n")
|
|
209
223
|
sys.stdout.flush()
|
|
224
|
+
|
|
225
|
+
|
|
210
226
|
class Render:
|
|
227
|
+
# ---- CORE ----
|
|
211
228
|
@staticmethod
|
|
212
229
|
def DrawPic(points=None, width=80, height=25, clear_before_draw=False, default_char=' '):
|
|
213
230
|
if clear_before_draw:
|
|
@@ -215,15 +232,42 @@ class Render:
|
|
|
215
232
|
field = [[default_char for _ in range(width)] for _ in range(height)]
|
|
216
233
|
if points:
|
|
217
234
|
for item in points:
|
|
218
|
-
if len(item)
|
|
219
|
-
x, y, char = item
|
|
235
|
+
if len(item) >= 3:
|
|
236
|
+
x, y, char = item[0], item[1], item[2]
|
|
220
237
|
if 0 <= x < width and 0 <= y < height:
|
|
221
|
-
|
|
238
|
+
# Если есть цвет — применяем
|
|
239
|
+
if len(item) == 4:
|
|
240
|
+
color = item[3]
|
|
241
|
+
field[y][x] = f"{color}{char}{Colors.RESET}"
|
|
242
|
+
elif len(item) == 5:
|
|
243
|
+
color, bg = item[3], item[4]
|
|
244
|
+
field[y][x] = f"{color}{bg}{char}{Colors.RESET}"
|
|
245
|
+
else:
|
|
246
|
+
field[y][x] = char
|
|
222
247
|
for row in field:
|
|
223
248
|
print(''.join(row))
|
|
224
249
|
|
|
250
|
+
# ---- POINT GENERATORS WITH COLOR ----
|
|
251
|
+
@staticmethod
|
|
252
|
+
def _apply_color(points, color=None, bg=None):
|
|
253
|
+
if color is None and bg is None:
|
|
254
|
+
return points
|
|
255
|
+
result = []
|
|
256
|
+
for p in points:
|
|
257
|
+
if len(p) == 3:
|
|
258
|
+
x, y, char = p
|
|
259
|
+
if color and bg:
|
|
260
|
+
result.append((x, y, char, color, bg))
|
|
261
|
+
elif color:
|
|
262
|
+
result.append((x, y, char, color))
|
|
263
|
+
else:
|
|
264
|
+
result.append((x, y, char, Colors.BG_BLACK + bg))
|
|
265
|
+
else:
|
|
266
|
+
result.append(p)
|
|
267
|
+
return result
|
|
268
|
+
|
|
225
269
|
@staticmethod
|
|
226
|
-
def get_line_points(x1, y1, x2, y2, char='#'):
|
|
270
|
+
def get_line_points(x1, y1, x2, y2, char='#', color=None, bg=None):
|
|
227
271
|
points = []
|
|
228
272
|
dx = abs(x2 - x1)
|
|
229
273
|
dy = abs(y2 - y1)
|
|
@@ -241,29 +285,29 @@ class Render:
|
|
|
241
285
|
if e2 < dx:
|
|
242
286
|
err += dx
|
|
243
287
|
y1 += sy
|
|
244
|
-
return points
|
|
288
|
+
return Render._apply_color(points, color, bg)
|
|
245
289
|
|
|
246
290
|
@staticmethod
|
|
247
|
-
def get_circle_points(cx, cy, r, char='#'):
|
|
291
|
+
def get_circle_points(cx, cy, r, char='#', color=None, bg=None):
|
|
248
292
|
points = []
|
|
249
293
|
for angle in range(0, 360, 5):
|
|
250
294
|
rad = angle * math.pi / 180
|
|
251
295
|
x = int(cx + r * math.cos(rad))
|
|
252
296
|
y = int(cy + r * math.sin(rad))
|
|
253
297
|
points.append((x, y, char))
|
|
254
|
-
return points
|
|
298
|
+
return Render._apply_color(points, color, bg)
|
|
255
299
|
|
|
256
300
|
@staticmethod
|
|
257
|
-
def get_filled_circle_points(cx, cy, r, char='#'):
|
|
301
|
+
def get_filled_circle_points(cx, cy, r, char='#', color=None, bg=None):
|
|
258
302
|
points = []
|
|
259
303
|
for y in range(cy - r, cy + r + 1):
|
|
260
304
|
for x in range(cx - r, cx + r + 1):
|
|
261
305
|
if (x - cx) ** 2 + (y - cy) ** 2 <= r ** 2:
|
|
262
306
|
points.append((x, y, char))
|
|
263
|
-
return points
|
|
307
|
+
return Render._apply_color(points, color, bg)
|
|
264
308
|
|
|
265
309
|
@staticmethod
|
|
266
|
-
def get_rect_points(x1, y1, x2, y2, char='#'):
|
|
310
|
+
def get_rect_points(x1, y1, x2, y2, char='#', color=None, bg=None):
|
|
267
311
|
points = []
|
|
268
312
|
for x in range(x1, x2 + 1):
|
|
269
313
|
points.append((x, y1, char))
|
|
@@ -271,18 +315,18 @@ class Render:
|
|
|
271
315
|
for y in range(y1, y2 + 1):
|
|
272
316
|
points.append((x1, y, char))
|
|
273
317
|
points.append((x2, y, char))
|
|
274
|
-
return points
|
|
318
|
+
return Render._apply_color(points, color, bg)
|
|
275
319
|
|
|
276
320
|
@staticmethod
|
|
277
|
-
def get_fill_rect_points(x1, y1, x2, y2, char='#'):
|
|
321
|
+
def get_fill_rect_points(x1, y1, x2, y2, char='#', color=None, bg=None):
|
|
278
322
|
points = []
|
|
279
323
|
for y in range(y1, y2 + 1):
|
|
280
324
|
for x in range(x1, x2 + 1):
|
|
281
325
|
points.append((x, y, char))
|
|
282
|
-
return points
|
|
326
|
+
return Render._apply_color(points, color, bg)
|
|
283
327
|
|
|
284
328
|
@staticmethod
|
|
285
|
-
def get_text_points(x, y, text, char=None):
|
|
329
|
+
def get_text_points(x, y, text, char=None, color=None, bg=None):
|
|
286
330
|
points = []
|
|
287
331
|
if char is None:
|
|
288
332
|
for i, ch in enumerate(text):
|
|
@@ -290,18 +334,18 @@ class Render:
|
|
|
290
334
|
else:
|
|
291
335
|
for i in range(len(text)):
|
|
292
336
|
points.append((x + i, y, char))
|
|
293
|
-
return points
|
|
337
|
+
return Render._apply_color(points, color, bg)
|
|
294
338
|
|
|
295
339
|
@staticmethod
|
|
296
|
-
def get_triangle_points(x1, y1, x2, y2, x3, y3, char='#'):
|
|
340
|
+
def get_triangle_points(x1, y1, x2, y2, x3, y3, char='#', color=None, bg=None):
|
|
297
341
|
points = []
|
|
298
342
|
points.extend(Render.get_line_points(x1, y1, x2, y2, char))
|
|
299
343
|
points.extend(Render.get_line_points(x2, y2, x3, y3, char))
|
|
300
344
|
points.extend(Render.get_line_points(x3, y3, x1, y1, char))
|
|
301
|
-
return points
|
|
345
|
+
return Render._apply_color(points, color, bg)
|
|
302
346
|
|
|
303
347
|
@staticmethod
|
|
304
|
-
def get_filled_triangle_points(x1, y1, x2, y2, x3, y3, char='#'):
|
|
348
|
+
def get_filled_triangle_points(x1, y1, x2, y2, x3, y3, char='#', color=None, bg=None):
|
|
305
349
|
points = []
|
|
306
350
|
min_x = min(x1, x2, x3)
|
|
307
351
|
max_x = max(x1, x2, x3)
|
|
@@ -311,19 +355,19 @@ class Render:
|
|
|
311
355
|
for x in range(min_x, max_x + 1):
|
|
312
356
|
if Render._point_in_triangle(x, y, x1, y1, x2, y2, x3, y3):
|
|
313
357
|
points.append((x, y, char))
|
|
314
|
-
return points
|
|
358
|
+
return Render._apply_color(points, color, bg)
|
|
315
359
|
|
|
316
360
|
@staticmethod
|
|
317
|
-
def get_heart_points(cx, cy, size=5, char='#'):
|
|
361
|
+
def get_heart_points(cx, cy, size=5, char='#', color=None, bg=None):
|
|
318
362
|
points = []
|
|
319
363
|
for y in range(-size, size + 1):
|
|
320
364
|
for x in range(-size, size + 1):
|
|
321
365
|
if ((x * x + y * y - size * size) ** 3 <= size * size * x * x * y * y * 0.5):
|
|
322
366
|
points.append((cx + x, cy - y, char))
|
|
323
|
-
return points
|
|
367
|
+
return Render._apply_color(points, color, bg)
|
|
324
368
|
|
|
325
369
|
@staticmethod
|
|
326
|
-
def get_star_points(cx, cy, radius=5, points_count=5, char='*'):
|
|
370
|
+
def get_star_points(cx, cy, radius=5, points_count=5, char='*', color=None, bg=None):
|
|
327
371
|
points = []
|
|
328
372
|
angle = -math.pi / 2
|
|
329
373
|
step = math.pi / points_count
|
|
@@ -343,28 +387,28 @@ class Render:
|
|
|
343
387
|
p3 = outer_points[(i + 1) % points_count]
|
|
344
388
|
points.extend(Render.get_line_points(int(p1[0]), int(p1[1]), int(p2[0]), int(p2[1]), char))
|
|
345
389
|
points.extend(Render.get_line_points(int(p2[0]), int(p2[1]), int(p3[0]), int(p3[1]), char))
|
|
346
|
-
return points
|
|
390
|
+
return Render._apply_color(points, color, bg)
|
|
347
391
|
|
|
348
392
|
@staticmethod
|
|
349
|
-
def get_bezier_points(x1, y1, x2, y2, x3, y3, steps=20, char='#'):
|
|
393
|
+
def get_bezier_points(x1, y1, x2, y2, x3, y3, steps=20, char='#', color=None, bg=None):
|
|
350
394
|
points = []
|
|
351
395
|
for t in range(steps + 1):
|
|
352
396
|
t = t / steps
|
|
353
397
|
x = (1 - t) ** 2 * x1 + 2 * (1 - t) * t * x2 + t ** 2 * x3
|
|
354
398
|
y = (1 - t) ** 2 * y1 + 2 * (1 - t) * t * y2 + t ** 2 * y3
|
|
355
399
|
points.append((int(x), int(y), char))
|
|
356
|
-
return points
|
|
400
|
+
return Render._apply_color(points, color, bg)
|
|
357
401
|
|
|
358
402
|
@staticmethod
|
|
359
|
-
def get_wave_points(cx, cy, amplitude=5, length=20, char='~'):
|
|
403
|
+
def get_wave_points(cx, cy, amplitude=5, length=20, char='~', color=None, bg=None):
|
|
360
404
|
points = []
|
|
361
405
|
for x in range(length):
|
|
362
406
|
y = cy + int(amplitude * math.sin(x * 0.5))
|
|
363
407
|
points.append((cx + x, y, char))
|
|
364
|
-
return points
|
|
408
|
+
return Render._apply_color(points, color, bg)
|
|
365
409
|
|
|
366
410
|
@staticmethod
|
|
367
|
-
def get_spiral_points(cx, cy, turns=3, radius=10, step=0.1, char='*'):
|
|
411
|
+
def get_spiral_points(cx, cy, turns=3, radius=10, step=0.1, char='*', color=None, bg=None):
|
|
368
412
|
points = []
|
|
369
413
|
angle = 0
|
|
370
414
|
r = 0
|
|
@@ -374,18 +418,18 @@ class Render:
|
|
|
374
418
|
points.append((x, y, char))
|
|
375
419
|
angle += step
|
|
376
420
|
r += step * 2
|
|
377
|
-
return points
|
|
421
|
+
return Render._apply_color(points, color, bg)
|
|
378
422
|
|
|
379
423
|
@staticmethod
|
|
380
|
-
def get_grid_points(x1, y1, x2, y2, step=2, char='+'):
|
|
424
|
+
def get_grid_points(x1, y1, x2, y2, step=2, char='+', color=None, bg=None):
|
|
381
425
|
points = []
|
|
382
426
|
for x in range(x1, x2 + 1, step):
|
|
383
427
|
for y in range(y1, y2 + 1, step):
|
|
384
428
|
points.append((x, y, char))
|
|
385
|
-
return points
|
|
429
|
+
return Render._apply_color(points, color, bg)
|
|
386
430
|
|
|
387
431
|
@staticmethod
|
|
388
|
-
def get_noise_points(cx, cy, radius, count=50, char='.'):
|
|
432
|
+
def get_noise_points(cx, cy, radius, count=50, char='.', color=None, bg=None):
|
|
389
433
|
points = []
|
|
390
434
|
for _ in range(count):
|
|
391
435
|
angle = random.uniform(0, 2 * math.pi)
|
|
@@ -393,8 +437,9 @@ class Render:
|
|
|
393
437
|
x = int(cx + r * math.cos(angle))
|
|
394
438
|
y = int(cy + r * math.sin(angle))
|
|
395
439
|
points.append((x, y, char))
|
|
396
|
-
return points
|
|
440
|
+
return Render._apply_color(points, color, bg)
|
|
397
441
|
|
|
442
|
+
# ---- 3D ----
|
|
398
443
|
@staticmethod
|
|
399
444
|
def _point_in_triangle(px, py, x1, y1, x2, y2, x3, y3):
|
|
400
445
|
def sign(a, b, c):
|
|
@@ -444,7 +489,7 @@ class Render:
|
|
|
444
489
|
return x2d, y2d
|
|
445
490
|
|
|
446
491
|
@staticmethod
|
|
447
|
-
def get_cube_3d_points(size=5, rotx=0, roty=0, rotz=0, scale=10, cx=40, cy=12, char='#'):
|
|
492
|
+
def get_cube_3d_points(size=5, rotx=0, roty=0, rotz=0, scale=10, cx=40, cy=12, char='#', color=None, bg=None):
|
|
448
493
|
s = size / 2
|
|
449
494
|
vertices = [
|
|
450
495
|
(-s, -s, -s), (s, -s, -s), (s, s, -s), (-s, s, -s),
|
|
@@ -464,10 +509,10 @@ class Render:
|
|
|
464
509
|
x1, y1 = projected[edge[0]]
|
|
465
510
|
x2, y2 = projected[edge[1]]
|
|
466
511
|
points.extend(Render.get_line_points(x1, y1, x2, y2, char))
|
|
467
|
-
return points
|
|
512
|
+
return Render._apply_color(points, color, bg)
|
|
468
513
|
|
|
469
514
|
@staticmethod
|
|
470
|
-
def get_pyramid_3d_points(size=5, rotx=0, roty=0, rotz=0, scale=10, cx=40, cy=12, char='#'):
|
|
515
|
+
def get_pyramid_3d_points(size=5, rotx=0, roty=0, rotz=0, scale=10, cx=40, cy=12, char='#', color=None, bg=None):
|
|
471
516
|
s = size / 2
|
|
472
517
|
vertices = [
|
|
473
518
|
(-s, -s, -s), (s, -s, -s), (s, -s, s), (-s, -s, s),
|
|
@@ -486,10 +531,10 @@ class Render:
|
|
|
486
531
|
x1, y1 = projected[edge[0]]
|
|
487
532
|
x2, y2 = projected[edge[1]]
|
|
488
533
|
points.extend(Render.get_line_points(x1, y1, x2, y2, char))
|
|
489
|
-
return points
|
|
534
|
+
return Render._apply_color(points, color, bg)
|
|
490
535
|
|
|
491
536
|
@staticmethod
|
|
492
|
-
def get_cylinder_3d_points(radius=5, height=10, segments=12, rotx=0, roty=0, rotz=0, scale=10, cx=40, cy=12, char='#'):
|
|
537
|
+
def get_cylinder_3d_points(radius=5, height=10, segments=12, rotx=0, roty=0, rotz=0, scale=10, cx=40, cy=12, char='#', color=None, bg=None):
|
|
493
538
|
points = []
|
|
494
539
|
top_points = []
|
|
495
540
|
bottom_points = []
|
|
@@ -515,10 +560,10 @@ class Render:
|
|
|
515
560
|
x1, y1 = projected[i]
|
|
516
561
|
x2, y2 = projected[i + segments]
|
|
517
562
|
points.extend(Render.get_line_points(x1, y1, x2, y2, char))
|
|
518
|
-
return points
|
|
563
|
+
return Render._apply_color(points, color, bg)
|
|
519
564
|
|
|
520
565
|
@staticmethod
|
|
521
|
-
def get_sphere_3d_points(radius=5, segments=12, rotx=0, roty=0, rotz=0, scale=10, cx=40, cy=12, char='#'):
|
|
566
|
+
def get_sphere_3d_points(radius=5, segments=12, rotx=0, roty=0, rotz=0, scale=10, cx=40, cy=12, char='#', color=None, bg=None):
|
|
522
567
|
points = []
|
|
523
568
|
for i in range(segments):
|
|
524
569
|
theta = i / segments * math.pi
|
|
@@ -529,10 +574,10 @@ class Render:
|
|
|
529
574
|
z = radius * math.sin(theta) * math.sin(phi)
|
|
530
575
|
x2d, y2d = Render._project_3d(x, y, z, rotx, roty, rotz, scale, cx, cy)
|
|
531
576
|
points.append((x2d, y2d, char))
|
|
532
|
-
return points
|
|
577
|
+
return Render._apply_color(points, color, bg)
|
|
533
578
|
|
|
534
579
|
@staticmethod
|
|
535
|
-
def get_cone_3d_points(radius=5, height=10, segments=12, rotx=0, roty=0, rotz=0, scale=10, cx=40, cy=12, char='#'):
|
|
580
|
+
def get_cone_3d_points(radius=5, height=10, segments=12, rotx=0, roty=0, rotz=0, scale=10, cx=40, cy=12, char='#', color=None, bg=None):
|
|
536
581
|
points = []
|
|
537
582
|
base_points = []
|
|
538
583
|
for i in range(segments):
|
|
@@ -554,10 +599,10 @@ class Render:
|
|
|
554
599
|
x1, y1 = projected[i]
|
|
555
600
|
x2, y2 = projected[-1]
|
|
556
601
|
points.extend(Render.get_line_points(x1, y1, x2, y2, char))
|
|
557
|
-
return points
|
|
602
|
+
return Render._apply_color(points, color, bg)
|
|
558
603
|
|
|
559
604
|
@staticmethod
|
|
560
|
-
def get_torus_3d_points(radius=8, tube=3, segments=16, rotx=0, roty=0, rotz=0, scale=10, cx=40, cy=12, char='#'):
|
|
605
|
+
def get_torus_3d_points(radius=8, tube=3, segments=16, rotx=0, roty=0, rotz=0, scale=10, cx=40, cy=12, char='#', color=None, bg=None):
|
|
561
606
|
points = []
|
|
562
607
|
for i in range(segments):
|
|
563
608
|
theta = i / segments * 2 * math.pi
|
|
@@ -568,10 +613,10 @@ class Render:
|
|
|
568
613
|
z = (radius + tube * math.cos(phi)) * math.sin(theta)
|
|
569
614
|
x2d, y2d = Render._project_3d(x, y, z, rotx, roty, rotz, scale, cx, cy)
|
|
570
615
|
points.append((x2d, y2d, char))
|
|
571
|
-
return points
|
|
616
|
+
return Render._apply_color(points, color, bg)
|
|
572
617
|
|
|
573
618
|
@staticmethod
|
|
574
|
-
def get_ico_sphere_3d_points(radius=5, rotx=0, roty=0, rotz=0, scale=10, cx=40, cy=12, char='#'):
|
|
619
|
+
def get_ico_sphere_3d_points(radius=5, rotx=0, roty=0, rotz=0, scale=10, cx=40, cy=12, char='#', color=None, bg=None):
|
|
575
620
|
points = []
|
|
576
621
|
phi = (1 + math.sqrt(5)) / 2
|
|
577
622
|
vertices = [
|
|
@@ -600,118 +645,120 @@ class Render:
|
|
|
600
645
|
x1, y1 = projected[edge[0]]
|
|
601
646
|
x2, y2 = projected[edge[1]]
|
|
602
647
|
points.extend(Render.get_line_points(x1, y1, x2, y2, char))
|
|
603
|
-
return points
|
|
648
|
+
return Render._apply_color(points, color, bg)
|
|
604
649
|
|
|
650
|
+
# ---- DRAW WRAPPERS ----
|
|
605
651
|
@staticmethod
|
|
606
|
-
def
|
|
607
|
-
points = Render.
|
|
652
|
+
def draw_line(x1, y1, x2, y2, char='#', width=80, height=25, clear_before_draw=False, color=None, bg=None):
|
|
653
|
+
points = Render.get_line_points(x1, y1, x2, y2, char, color, bg)
|
|
608
654
|
Render.DrawPic(points=points, width=width, height=height, clear_before_draw=clear_before_draw)
|
|
609
655
|
|
|
610
656
|
@staticmethod
|
|
611
|
-
def
|
|
612
|
-
points = Render.
|
|
657
|
+
def draw_circle(cx, cy, r, char='#', width=80, height=25, clear_before_draw=False, color=None, bg=None):
|
|
658
|
+
points = Render.get_circle_points(cx, cy, r, char, color, bg)
|
|
613
659
|
Render.DrawPic(points=points, width=width, height=height, clear_before_draw=clear_before_draw)
|
|
614
660
|
|
|
615
661
|
@staticmethod
|
|
616
|
-
def
|
|
617
|
-
points = Render.
|
|
662
|
+
def draw_filled_circle(cx, cy, r, char='#', width=80, height=25, clear_before_draw=False, color=None, bg=None):
|
|
663
|
+
points = Render.get_filled_circle_points(cx, cy, r, char, color, bg)
|
|
618
664
|
Render.DrawPic(points=points, width=width, height=height, clear_before_draw=clear_before_draw)
|
|
619
665
|
|
|
620
666
|
@staticmethod
|
|
621
|
-
def
|
|
622
|
-
points = Render.
|
|
667
|
+
def draw_rect(x1, y1, x2, y2, char='#', width=80, height=25, clear_before_draw=False, color=None, bg=None):
|
|
668
|
+
points = Render.get_rect_points(x1, y1, x2, y2, char, color, bg)
|
|
623
669
|
Render.DrawPic(points=points, width=width, height=height, clear_before_draw=clear_before_draw)
|
|
624
670
|
|
|
625
671
|
@staticmethod
|
|
626
|
-
def
|
|
627
|
-
points = Render.
|
|
672
|
+
def fill_rect(x1, y1, x2, y2, char='#', width=80, height=25, clear_before_draw=False, color=None, bg=None):
|
|
673
|
+
points = Render.get_fill_rect_points(x1, y1, x2, y2, char, color, bg)
|
|
628
674
|
Render.DrawPic(points=points, width=width, height=height, clear_before_draw=clear_before_draw)
|
|
629
675
|
|
|
630
676
|
@staticmethod
|
|
631
|
-
def
|
|
632
|
-
points = Render.
|
|
677
|
+
def draw_text(x, y, text, width=80, height=25, clear_before_draw=False, color=None, bg=None):
|
|
678
|
+
points = Render.get_text_points(x, y, text, color=color, bg=bg)
|
|
633
679
|
Render.DrawPic(points=points, width=width, height=height, clear_before_draw=clear_before_draw)
|
|
634
680
|
|
|
635
681
|
@staticmethod
|
|
636
|
-
def
|
|
637
|
-
points = Render.
|
|
682
|
+
def draw_triangle(x1, y1, x2, y2, x3, y3, char='#', width=80, height=25, clear_before_draw=False, color=None, bg=None):
|
|
683
|
+
points = Render.get_triangle_points(x1, y1, x2, y2, x3, y3, char, color, bg)
|
|
638
684
|
Render.DrawPic(points=points, width=width, height=height, clear_before_draw=clear_before_draw)
|
|
639
685
|
|
|
640
686
|
@staticmethod
|
|
641
|
-
def
|
|
642
|
-
points = Render.
|
|
687
|
+
def fill_triangle(x1, y1, x2, y2, x3, y3, char='#', width=80, height=25, clear_before_draw=False, color=None, bg=None):
|
|
688
|
+
points = Render.get_filled_triangle_points(x1, y1, x2, y2, x3, y3, char, color, bg)
|
|
643
689
|
Render.DrawPic(points=points, width=width, height=height, clear_before_draw=clear_before_draw)
|
|
644
690
|
|
|
645
691
|
@staticmethod
|
|
646
|
-
def
|
|
647
|
-
points = Render.
|
|
692
|
+
def draw_heart(cx, cy, size=5, char='#', width=80, height=25, clear_before_draw=False, color=None, bg=None):
|
|
693
|
+
points = Render.get_heart_points(cx, cy, size, char, color, bg)
|
|
648
694
|
Render.DrawPic(points=points, width=width, height=height, clear_before_draw=clear_before_draw)
|
|
649
695
|
|
|
650
696
|
@staticmethod
|
|
651
|
-
def
|
|
652
|
-
points = Render.
|
|
697
|
+
def draw_star(cx, cy, radius=5, points_count=5, char='#', width=80, height=25, clear_before_draw=False, color=None, bg=None):
|
|
698
|
+
points = Render.get_star_points(cx, cy, radius, points_count, char, color, bg)
|
|
653
699
|
Render.DrawPic(points=points, width=width, height=height, clear_before_draw=clear_before_draw)
|
|
654
700
|
|
|
655
701
|
@staticmethod
|
|
656
|
-
def
|
|
657
|
-
points = Render.
|
|
702
|
+
def draw_bezier(x1, y1, x2, y2, x3, y3, steps=20, char='#', width=80, height=25, clear_before_draw=False, color=None, bg=None):
|
|
703
|
+
points = Render.get_bezier_points(x1, y1, x2, y2, x3, y3, steps, char, color, bg)
|
|
658
704
|
Render.DrawPic(points=points, width=width, height=height, clear_before_draw=clear_before_draw)
|
|
659
705
|
|
|
660
706
|
@staticmethod
|
|
661
|
-
def
|
|
662
|
-
points = Render.
|
|
707
|
+
def draw_wave(cx, cy, amplitude=5, length=20, char='~', width=80, height=25, clear_before_draw=False, color=None, bg=None):
|
|
708
|
+
points = Render.get_wave_points(cx, cy, amplitude, length, char, color, bg)
|
|
663
709
|
Render.DrawPic(points=points, width=width, height=height, clear_before_draw=clear_before_draw)
|
|
664
710
|
|
|
665
711
|
@staticmethod
|
|
666
|
-
def
|
|
667
|
-
points = Render.
|
|
712
|
+
def draw_spiral(cx, cy, turns=3, radius=10, step=0.1, char='*', width=80, height=25, clear_before_draw=False, color=None, bg=None):
|
|
713
|
+
points = Render.get_spiral_points(cx, cy, turns, radius, step, char, color, bg)
|
|
668
714
|
Render.DrawPic(points=points, width=width, height=height, clear_before_draw=clear_before_draw)
|
|
669
715
|
|
|
670
716
|
@staticmethod
|
|
671
|
-
def
|
|
672
|
-
points = Render.
|
|
717
|
+
def draw_grid(x1, y1, x2, y2, step=2, char='+', width=80, height=25, clear_before_draw=False, color=None, bg=None):
|
|
718
|
+
points = Render.get_grid_points(x1, y1, x2, y2, step, char, color, bg)
|
|
673
719
|
Render.DrawPic(points=points, width=width, height=height, clear_before_draw=clear_before_draw)
|
|
674
720
|
|
|
675
721
|
@staticmethod
|
|
676
|
-
def
|
|
677
|
-
points = Render.
|
|
722
|
+
def draw_noise(cx, cy, radius, count=50, char='.', width=80, height=25, clear_before_draw=False, color=None, bg=None):
|
|
723
|
+
points = Render.get_noise_points(cx, cy, radius, count, char, color, bg)
|
|
678
724
|
Render.DrawPic(points=points, width=width, height=height, clear_before_draw=clear_before_draw)
|
|
679
725
|
|
|
680
726
|
@staticmethod
|
|
681
|
-
def
|
|
682
|
-
points = Render.
|
|
727
|
+
def draw_cube_3d(size=5, rotx=0, roty=0, rotz=0, scale=10, cx=40, cy=12, char='#', width=80, height=25, clear_before_draw=False, color=None, bg=None):
|
|
728
|
+
points = Render.get_cube_3d_points(size, rotx, roty, rotz, scale, cx, cy, char, color, bg)
|
|
683
729
|
Render.DrawPic(points=points, width=width, height=height, clear_before_draw=clear_before_draw)
|
|
684
730
|
|
|
685
731
|
@staticmethod
|
|
686
|
-
def
|
|
687
|
-
points = Render.
|
|
732
|
+
def draw_pyramid_3d(size=5, rotx=0, roty=0, rotz=0, scale=10, cx=40, cy=12, char='#', width=80, height=25, clear_before_draw=False, color=None, bg=None):
|
|
733
|
+
points = Render.get_pyramid_3d_points(size, rotx, roty, rotz, scale, cx, cy, char, color, bg)
|
|
688
734
|
Render.DrawPic(points=points, width=width, height=height, clear_before_draw=clear_before_draw)
|
|
689
735
|
|
|
690
736
|
@staticmethod
|
|
691
|
-
def
|
|
692
|
-
points = Render.
|
|
737
|
+
def draw_cylinder_3d(radius=5,segments=12, rotx=0, roty=0, rotz=0, scale=10, cx=40, cy=12, char='#', width=80, height=25, clear_before_draw=False, color=None, bg=None):
|
|
738
|
+
points = Render.get_cylinder_3d_points(radius, height, segments, rotx, roty, rotz, scale, cx, cy, char, color, bg)
|
|
693
739
|
Render.DrawPic(points=points, width=width, height=height, clear_before_draw=clear_before_draw)
|
|
694
740
|
|
|
695
741
|
@staticmethod
|
|
696
|
-
def
|
|
697
|
-
points = Render.
|
|
742
|
+
def draw_sphere_3d(radius=5, segments=12, rotx=0, roty=0, rotz=0, scale=10, cx=40, cy=12, char='#', width=80, height=25, clear_before_draw=False, color=None, bg=None):
|
|
743
|
+
points = Render.get_sphere_3d_points(radius, segments, rotx, roty, rotz, scale, cx, cy, char, color, bg)
|
|
698
744
|
Render.DrawPic(points=points, width=width, height=height, clear_before_draw=clear_before_draw)
|
|
699
745
|
|
|
700
746
|
@staticmethod
|
|
701
|
-
def
|
|
702
|
-
points = Render.
|
|
747
|
+
def draw_cone_3d(radius=5, segments=12, rotx=0, roty=0, rotz=0, scale=10, cx=40, cy=12, char='#', width=80, height=25, clear_before_draw=False, color=None, bg=None):
|
|
748
|
+
points = Render.get_cone_3d_points(radius, height, segments, rotx, roty, rotz, scale, cx, cy, char, color, bg)
|
|
703
749
|
Render.DrawPic(points=points, width=width, height=height, clear_before_draw=clear_before_draw)
|
|
704
750
|
|
|
705
751
|
@staticmethod
|
|
706
|
-
def
|
|
707
|
-
points = Render.
|
|
752
|
+
def draw_torus_3d(radius=8, tube=3, segments=16, rotx=0, roty=0, rotz=0, scale=10, cx=40, cy=12, char='#', width=80, height=25, clear_before_draw=False, color=None, bg=None):
|
|
753
|
+
points = Render.get_torus_3d_points(radius, tube, segments, rotx, roty, rotz, scale, cx, cy, char, color, bg)
|
|
708
754
|
Render.DrawPic(points=points, width=width, height=height, clear_before_draw=clear_before_draw)
|
|
709
755
|
|
|
710
756
|
@staticmethod
|
|
711
|
-
def
|
|
712
|
-
points = Render.
|
|
757
|
+
def draw_ico_sphere_3d(radius=5, rotx=0, roty=0, rotz=0, scale=10, cx=40, cy=12, char='#', width=80, height=25, clear_before_draw=False, color=None, bg=None):
|
|
758
|
+
points = Render.get_ico_sphere_3d_points(radius, rotx, roty, rotz, scale, cx, cy, char, color, bg)
|
|
713
759
|
Render.DrawPic(points=points, width=width, height=height, clear_before_draw=clear_before_draw)
|
|
714
760
|
|
|
761
|
+
|
|
715
762
|
class ConsoleInfo:
|
|
716
763
|
@staticmethod
|
|
717
764
|
def GetConsole():
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "ConsoleLib"
|
|
7
|
-
version = "1.3.
|
|
7
|
+
version = "1.3.4"
|
|
8
8
|
description = "The library for easy and best control on the Console."
|
|
9
9
|
authors = [{name = "Suleiman", email = "steal.apet@mail.ru"}]
|
|
10
10
|
readme = "README.md"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|