ConsoleLib 1.2.1__tar.gz → 1.3.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,226 @@
1
+ """
2
+ ConsoleLib - The best Console Renderer of the Python.
3
+ By: Suleiman
4
+ Copyright © Suleiman 2026
5
+ All rights are reserved.
6
+ """
7
+ import os
8
+ import sys
9
+ import time
10
+ import subprocess as CMD
11
+ import math
12
+ class Render:
13
+ @staticmethod
14
+ def DrawPic(points=None, width=80, height=25, clear_before_draw=False, default_char=' '):
15
+ if clear_before_draw:
16
+ os.system("cls" if os.name == "nt" else "clear")
17
+ field = [[default_char for _ in range(width)] for _ in range(height)]
18
+ if points:
19
+ for item in points:
20
+ if len(item) == 3:
21
+ x, y, char = item
22
+ if 0 <= x < width and 0 <= y < height:
23
+ field[y][x] = char
24
+ for row in field:
25
+ print(''.join(row))
26
+ @staticmethod
27
+ def get_line_points(x1, y1, x2, y2, char='#'):
28
+ points = []
29
+ dx = abs(x2 - x1)
30
+ dy = abs(y2 - y1)
31
+ sx = 1 if x1 < x2 else -1
32
+ sy = 1 if y1 < y2 else -1
33
+ err = dx - dy
34
+ while True:
35
+ points.append((x1, y1, char))
36
+ if x1 == x2 and y1 == y2:
37
+ break
38
+ e2 = err * 2
39
+ if e2 > -dy:
40
+ err -= dy
41
+ x1 += sx
42
+ if e2 < dx:
43
+ err += dx
44
+ y1 += sy
45
+ return points
46
+ @staticmethod
47
+ def get_circle_points(cx, cy, r, char='#'):
48
+ points = []
49
+ for angle in range(0, 360, 5):
50
+ rad = angle * math.pi / 180
51
+ x = int(cx + r * math.cos(rad))
52
+ y = int(cy + r * math.sin(rad))
53
+ points.append((x, y, char))
54
+ return points
55
+ @staticmethod
56
+ def get_filled_circle_points(cx, cy, r, char='#'):
57
+ points = []
58
+ for y in range(cy - r, cy + r + 1):
59
+ for x in range(cx - r, cx + r + 1):
60
+ if (x - cx) ** 2 + (y - cy) ** 2 <= r ** 2:
61
+ points.append((x, y, char))
62
+ return points
63
+ @staticmethod
64
+ def get_rect_points(x1, y1, x2, y2, char='#'):
65
+ points = []
66
+ for x in range(x1, x2 + 1):
67
+ points.append((x, y1, char))
68
+ points.append((x, y2, char))
69
+ for y in range(y1, y2 + 1):
70
+ points.append((x1, y, char))
71
+ points.append((x2, y, char))
72
+ return points
73
+ @staticmethod
74
+ def get_fill_rect_points(x1, y1, x2, y2, char='#'):
75
+ points = []
76
+ for y in range(y1, y2 + 1):
77
+ for x in range(x1, x2 + 1):
78
+ points.append((x, y, char))
79
+ return points
80
+ @staticmethod
81
+ def get_text_points(x, y, text, char=None):
82
+ points = []
83
+ if char is None:
84
+ for i, ch in enumerate(text):
85
+ points.append((x + i, y, ch))
86
+ else:
87
+ for i in range(len(text)):
88
+ points.append((x + i, y, char))
89
+ return points
90
+ @staticmethod
91
+ def get_triangle_points(x1, y1, x2, y2, x3, y3, char='#'):
92
+ points = []
93
+ points.extend(Render.get_line_points(x1, y1, x2, y2, char))
94
+ points.extend(Render.get_line_points(x2, y2, x3, y3, char))
95
+ points.extend(Render.get_line_points(x3, y3, x1, y1, char))
96
+ return points
97
+ @staticmethod
98
+ def get_filled_triangle_points(x1, y1, x2, y2, x3, y3, char='#'):
99
+ points = []
100
+ min_x = min(x1, x2, x3)
101
+ max_x = max(x1, x2, x3)
102
+ min_y = min(y1, y2, y3)
103
+ max_y = max(y1, y2, y3)
104
+ for y in range(min_y, max_y + 1):
105
+ for x in range(min_x, max_x + 1):
106
+ if Render._point_in_triangle(x, y, x1, y1, x2, y2, x3, y3):
107
+ points.append((x, y, char))
108
+ return points
109
+ @staticmethod
110
+ def get_heart_points(cx, cy, size=5, char='#'):
111
+ points = []
112
+ for y in range(-size, size + 1):
113
+ for x in range(-size, size + 1):
114
+ if ((x * x + y * y - size * size) ** 3 <= size * size * x * x * y * y * 0.5):
115
+ points.append((cx + x, cy - y, char))
116
+ return points
117
+ @staticmethod
118
+ def get_star_points(cx, cy, radius=5, points_count=5, char='*'):
119
+ points = []
120
+ angle = -math.pi / 2
121
+ step = math.pi / points_count
122
+ outer_points = []
123
+ inner_points = []
124
+ for i in range(points_count * 2):
125
+ r = radius if i % 2 == 0 else radius * 0.4
126
+ x = cx + r * math.cos(angle + i * step)
127
+ y = cy + r * math.sin(angle + i * step)
128
+ if i % 2 == 0:
129
+ outer_points.append((x, y))
130
+ else:
131
+ inner_points.append((x, y))
132
+ for i in range(points_count):
133
+ p1 = outer_points[i]
134
+ p2 = inner_points[i]
135
+ p3 = outer_points[(i + 1) % points_count]
136
+ points.extend(Render.get_line_points(int(p1[0]), int(p1[1]), int(p2[0]), int(p2[1]), char))
137
+ points.extend(Render.get_line_points(int(p2[0]), int(p2[1]), int(p3[0]), int(p3[1]), char))
138
+ return points
139
+ @staticmethod
140
+ def get_bezier_points(x1, y1, x2, y2, x3, y3, steps=20, char='#'):
141
+ points = []
142
+ for t in range(steps + 1):
143
+ t = t / steps
144
+ x = (1 - t) ** 2 * x1 + 2 * (1 - t) * t * x2 + t ** 2 * x3
145
+ y = (1 - t) ** 2 * y1 + 2 * (1 - t) * t * y2 + t ** 2 * y3
146
+ points.append((int(x), int(y), char))
147
+ return points
148
+ @staticmethod
149
+ def get_wave_points(cx, cy, amplitude=5, length=20, char='~'):
150
+ points = []
151
+ for x in range(length):
152
+ y = cy + int(amplitude * math.sin(x * 0.5))
153
+ points.append((cx + x, y, char))
154
+ return points
155
+ @staticmethod
156
+ def _point_in_triangle(px, py, x1, y1, x2, y2, x3, y3):
157
+ def sign(a, b, c):
158
+ return (a[0] - c[0]) * (b[1] - c[1]) - (b[0] - c[0]) * (a[1] - c[1])
159
+ p = (px, py)
160
+ d1 = sign(p, (x2, y2), (x1, y1))
161
+ d2 = sign(p, (x3, y3), (x2, y2))
162
+ d3 = sign(p, (x1, y1), (x3, y3))
163
+ has_neg = (d1 < 0) or (d2 < 0) or (d3 < 0)
164
+ has_pos = (d1 > 0) or (d2 > 0) or (d3 > 0)
165
+ return not (has_neg and has_pos)
166
+ @staticmethod
167
+ def draw_line(x1, y1, x2, y2, char='#', width=80, height=25, clear_before_draw=False):
168
+ points = Render.get_line_points(x1, y1, x2, y2, char)
169
+ Render.DrawPic(points=points, width=width, height=height, clear_before_draw=clear_before_draw)
170
+ @staticmethod
171
+ def draw_circle(cx, cy, r, char='#', width=80, height=25, clear_before_draw=False):
172
+ points = Render.get_circle_points(cx, cy, r, char)
173
+ Render.DrawPic(points=points, width=width, height=height, clear_before_draw=clear_before_draw)
174
+ @staticmethod
175
+ def draw_filled_circle(cx, cy, r, char='#', width=80, height=25, clear_before_draw=False):
176
+ points = Render.get_filled_circle_points(cx, cy, r, char)
177
+ Render.DrawPic(points=points, width=width, height=height, clear_before_draw=clear_before_draw)
178
+ @staticmethod
179
+ def draw_rect(x1, y1, x2, y2, char='#', width=80, height=25, clear_before_draw=False):
180
+ points = Render.get_rect_points(x1, y1, x2, y2, char)
181
+ Render.DrawPic(points=points, width=width, height=height, clear_before_draw=clear_before_draw)
182
+ @staticmethod
183
+ def fill_rect(x1, y1, x2, y2, char='#', width=80, height=25, clear_before_draw=False):
184
+ points = Render.get_fill_rect_points(x1, y1, x2, y2, char)
185
+ Render.DrawPic(points=points, width=width, height=height, clear_before_draw=clear_before_draw)
186
+ @staticmethod
187
+ def draw_text(x, y, text, width=80, height=25, clear_before_draw=False):
188
+ points = Render.get_text_points(x, y, text)
189
+ Render.DrawPic(points=points, width=width, height=height, clear_before_draw=clear_before_draw)
190
+ @staticmethod
191
+ def draw_triangle(x1, y1, x2, y2, x3, y3, char='#', width=80, height=25, clear_before_draw=False):
192
+ points = Render.get_triangle_points(x1, y1, x2, y2, x3, y3, char)
193
+ Render.DrawPic(points=points, width=width, height=height, clear_before_draw=clear_before_draw)
194
+ @staticmethod
195
+ def fill_triangle(x1, y1, x2, y2, x3, y3, char='#', width=80, height=25, clear_before_draw=False):
196
+ points = Render.get_filled_triangle_points(x1, y1, x2, y2, x3, y3, char)
197
+ Render.DrawPic(points=points, width=width, height=height, clear_before_draw=clear_before_draw)
198
+ @staticmethod
199
+ def draw_heart(cx, cy, size=5, char='#', width=80, height=25, clear_before_draw=False):
200
+ points = Render.get_heart_points(cx, cy, size, char)
201
+ Render.DrawPic(points=points, width=width, height=height, clear_before_draw=clear_before_draw)
202
+ @staticmethod
203
+ def draw_star(cx, cy, radius=5, points_count=5, char='#', width=80, height=25, clear_before_draw=False):
204
+ points = Render.get_star_points(cx, cy, radius, points_count, char)
205
+ Render.DrawPic(points=points, width=width, height=height, clear_before_draw=clear_before_draw)
206
+ @staticmethod
207
+ def draw_bezier(x1, y1, x2, y2, x3, y3, steps=20, char='#', width=80, height=25, clear_before_draw=False):
208
+ points = Render.get_bezier_points(x1, y1, x2, y2, x3, y3, steps, char)
209
+ Render.DrawPic(points=points, width=width, height=height, clear_before_draw=clear_before_draw)
210
+ @staticmethod
211
+ def draw_wave(cx, cy, amplitude=5, length=20, char='~', width=80, height=25, clear_before_draw=False):
212
+ points = Render.get_wave_points(cx, cy, amplitude, length, char)
213
+ Render.DrawPic(points=points, width=width, height=height, clear_before_draw=clear_before_draw)
214
+ class ConsoleInfo:
215
+ @staticmethod
216
+ def GetConsole():
217
+ return sys.stdout
218
+ @staticmethod
219
+ def GetPipVer():
220
+ try:
221
+ result = CMD.run(['python', '-m', 'pip', '--version'], capture_output=True, text=True, check=True)
222
+ return result.stdout.strip()
223
+ except CMD.CalledProcessError as e:
224
+ return f"Error: pip not found (code {e.returncode})"
225
+ except FileNotFoundError:
226
+ return "Error: Python not installed or not in PATH"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ConsoleLib
3
- Version: 1.2.1
3
+ Version: 1.3.0
4
4
  Summary: The library for easy and best control on the Console.
5
5
  Author-email: Suleiman <steal.apet@mail.ru>
6
6
  License: MIT
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ConsoleLib
3
- Version: 1.2.1
3
+ Version: 1.3.0
4
4
  Summary: The library for easy and best control on the Console.
5
5
  Author-email: Suleiman <steal.apet@mail.ru>
6
6
  License: MIT
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "ConsoleLib"
7
- version = "1.2.1"
7
+ version = "1.3.0"
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"
@@ -1,88 +0,0 @@
1
- import os, sys, time
2
- import subprocess as CMD
3
- class Render:
4
- @staticmethod
5
- def DrawPic(points=None, width=80, height=25, clear_before_draw=False, default_char=' '):
6
- if clear_before_draw:
7
- os.system("cls" if os.name == "nt" else "clear")
8
- field = [[default_char for _ in range(width)] for _ in range(height)]
9
- if points:
10
- for item in points:
11
- if len(item) == 3:
12
- x, y, char = item
13
- if 0 <= x < width and 0 <= y < height:
14
- field[y][x] = char
15
- for row in field:
16
- print(''.join(row))
17
-
18
- @staticmethod
19
- def draw_line(x1, y1, x2, y2, char='#', width=80, height=25, clear_before_draw=False):
20
- points = []
21
- dx = abs(x2 - x1)
22
- dy = abs(y2 - y1)
23
- sx = 1 if x1 < x2 else -1
24
- sy = 1 if y1 < y2 else -1
25
- err = dx - dy
26
- while True:
27
- points.append((x1, y1, char))
28
- if x1 == x2 and y1 == y2:
29
- break
30
- e2 = err * 2
31
- if e2 > -dy:
32
- err -= dy
33
- x1 += sx
34
- if e2 < dx:
35
- err += dx
36
- y1 += sy
37
- Render.DrawPic(points=points, width=width, height=height, clear_before_draw=clear_before_draw)
38
-
39
- @staticmethod
40
- def draw_circle(cx, cy, r, char='#', width=80, height=25, clear_before_draw=False):
41
- import math
42
- points = []
43
- for angle in range(0, 360, 5):
44
- rad = angle * 3.14159 / 180
45
- x = int(cx + r * math.cos(rad))
46
- y = int(cy + r * math.sin(rad))
47
- points.append((x, y, char))
48
- Render.DrawPic(points=points, width=width, height=height, clear_before_draw=clear_before_draw)
49
-
50
- @staticmethod
51
- def draw_rect(x1, y1, x2, y2, char='#', width=80, height=25, clear_before_draw=False):
52
- points = []
53
- for x in range(x1, x2 + 1):
54
- points.append((x, y1, char))
55
- points.append((x, y2, char))
56
- for y in range(y1, y2 + 1):
57
- points.append((x1, y, char))
58
- points.append((x2, y, char))
59
- Render.DrawPic(points=points, width=width, height=height, clear_before_draw=clear_before_draw)
60
-
61
- @staticmethod
62
- def fill_rect(x1, y1, x2, y2, char='#', width=80, height=25, clear_before_draw=False):
63
- points = []
64
- for y in range(y1, y2 + 1):
65
- for x in range(x1, x2 + 1):
66
- points.append((x, y, char))
67
- Render.DrawPic(points=points, width=width, height=height, clear_before_draw=clear_before_draw)
68
-
69
- @staticmethod
70
- def draw_text(x, y, text, width=80, height=25, clear_before_draw=False):
71
- points = []
72
- for i, char in enumerate(text):
73
- points.append((x + i, y, char))
74
- Render.DrawPic(points=points, width=width, height=height, clear_before_draw=clear_before_draw)
75
- class ConsoleInfo:
76
- @staticmethod
77
- def GetConsole():
78
- return sys.stdout
79
-
80
- @staticmethod
81
- def GetPipVer():
82
- try:
83
- result = CMD.run(['python', '-m', 'pip', '--version'], capture_output=True, text=True, check=True)
84
- return result.stdout.strip()
85
- except CMD.CalledProcessError as e:
86
- return f"Error: pip not found (code {e.returncode})"
87
- except FileNotFoundError:
88
- return "Error: Python not installed or not in PATH"
File without changes
File without changes