ConsoleFramework 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.
@@ -1,7 +1,7 @@
1
1
  /*
2
- ConsoleTools - The best Console Library of the Python.
2
+ ConsoleFramework - The best Console Library of the Python.
3
3
  By: Suleiman
4
- Copyright В© Suleiman 2026
4
+ Copyright © Suleiman 2026
5
5
  All rights are reserved.
6
6
  */
7
7
  #include <Python.h>
@@ -13,6 +13,8 @@ All rights are reserved.
13
13
  #include <thread>
14
14
  #include <chrono>
15
15
  #include <sstream>
16
+ #include <cstring>
17
+ #include <ctime>
16
18
 
17
19
  #ifdef _WIN32
18
20
  #include <windows.h>
@@ -33,6 +35,52 @@ All rights are reserved.
33
35
 
34
36
  using namespace std;
35
37
 
38
+ struct Point {
39
+ int x, y;
40
+ char ch;
41
+ string color;
42
+ string bg;
43
+ };
44
+
45
+ struct Vec3 {
46
+ double x, y, z;
47
+ };
48
+
49
+ static bool point_in_triangle(int px, int py, int x1, int y1, int x2, int y2, int x3, int y3) {
50
+ int d1 = (x2 - x1) * (py - y1) - (y2 - y1) * (px - x1);
51
+ int d2 = (x3 - x2) * (py - y2) - (y3 - y2) * (px - x2);
52
+ int d3 = (x1 - x3) * (py - y3) - (y1 - y3) * (px - x3);
53
+ bool has_neg = (d1 < 0) || (d2 < 0) || (d3 < 0);
54
+ bool has_pos = (d1 > 0) || (d2 > 0) || (d3 > 0);
55
+ return !(has_neg && has_pos);
56
+ }
57
+
58
+ static Vec3 rotx(Vec3 v, double angle) {
59
+ double rad = angle * M_PI / 180.0;
60
+ double ca = cos(rad), sa = sin(rad);
61
+ return {v.x, v.y * ca - v.z * sa, v.y * sa + v.z * ca};
62
+ }
63
+
64
+ static Vec3 roty(Vec3 v, double angle) {
65
+ double rad = angle * M_PI / 180.0;
66
+ double ca = cos(rad), sa = sin(rad);
67
+ return {v.x * ca + v.z * sa, v.y, -v.x * sa + v.z * ca};
68
+ }
69
+
70
+ static Vec3 rotz(Vec3 v, double angle) {
71
+ double rad = angle * M_PI / 180.0;
72
+ double ca = cos(rad), sa = sin(rad);
73
+ return {v.x * ca - v.y * sa, v.x * sa + v.y * ca, v.z};
74
+ }
75
+
76
+ static void project_3d(Vec3 v, double rx, double ry, double rz, double scale, int cx, int cy, int* ox, int* oy) {
77
+ v = rotx(v, rx);
78
+ v = roty(v, ry);
79
+ v = rotz(v, rz);
80
+ *ox = (int)(v.x * scale + cx);
81
+ *oy = (int)(-v.y * scale + cy);
82
+ }
83
+
36
84
  static PyObject* rgb(PyObject* self, PyObject* args) {
37
85
  int r, g, b;
38
86
  if (!PyArg_ParseTuple(args, "iii", &r, &g, &b)) return NULL;
@@ -60,17 +108,13 @@ static PyObject* colorize(PyObject* self, PyObject* args) {
60
108
  static PyObject* get_line_points(PyObject* self, PyObject* args) {
61
109
  int x1, y1, x2, y2;
62
110
  const char* ch = "#";
63
- const char* color = "";
64
- const char* bg = "";
65
- if (!PyArg_ParseTuple(args, "iiii|sss", &x1, &y1, &x2, &y2, &ch, &color, &bg)) return NULL;
66
-
111
+ if (!PyArg_ParseTuple(args, "iiii|s", &x1, &y1, &x2, &y2, &ch)) return NULL;
67
112
  PyObject* list = PyList_New(0);
68
113
  int dx = abs(x2 - x1);
69
114
  int dy = abs(y2 - y1);
70
115
  int sx = (x1 < x2) ? 1 : -1;
71
116
  int sy = (y1 < y2) ? 1 : -1;
72
117
  int err = dx - dy;
73
-
74
118
  while (true) {
75
119
  PyObject* tuple = PyTuple_New(3);
76
120
  PyTuple_SetItem(tuple, 0, PyLong_FromLong(x1));
@@ -90,7 +134,6 @@ static PyObject* get_circle_points(PyObject* self, PyObject* args) {
90
134
  int cx, cy, r;
91
135
  const char* ch = "#";
92
136
  if (!PyArg_ParseTuple(args, "iii|s", &cx, &cy, &r, &ch)) return NULL;
93
-
94
137
  PyObject* list = PyList_New(0);
95
138
  for (int angle = 0; angle < 360; angle += 5) {
96
139
  double rad = angle * M_PI / 180.0;
@@ -110,7 +153,6 @@ static PyObject* get_filled_circle_points(PyObject* self, PyObject* args) {
110
153
  int cx, cy, r;
111
154
  const char* ch = "#";
112
155
  if (!PyArg_ParseTuple(args, "iii|s", &cx, &cy, &r, &ch)) return NULL;
113
-
114
156
  PyObject* list = PyList_New(0);
115
157
  for (int y = cy - r; y <= cy + r; y++) {
116
158
  for (int x = cx - r; x <= cx + r; x++) {
@@ -131,7 +173,6 @@ static PyObject* get_rect_points(PyObject* self, PyObject* args) {
131
173
  int x1, y1, x2, y2;
132
174
  const char* ch = "#";
133
175
  if (!PyArg_ParseTuple(args, "iiii|s", &x1, &y1, &x2, &y2, &ch)) return NULL;
134
-
135
176
  PyObject* list = PyList_New(0);
136
177
  for (int x = x1; x <= x2; x++) {
137
178
  PyObject* t1 = PyTuple_New(3);
@@ -168,7 +209,6 @@ static PyObject* get_fill_rect_points(PyObject* self, PyObject* args) {
168
209
  int x1, y1, x2, y2;
169
210
  const char* ch = "#";
170
211
  if (!PyArg_ParseTuple(args, "iiii|s", &x1, &y1, &x2, &y2, &ch)) return NULL;
171
-
172
212
  PyObject* list = PyList_New(0);
173
213
  for (int y = y1; y <= y2; y++) {
174
214
  for (int x = x1; x <= x2; x++) {
@@ -187,14 +227,13 @@ static PyObject* get_triangle_points(PyObject* self, PyObject* args) {
187
227
  int x1, y1, x2, y2, x3, y3;
188
228
  const char* ch = "#";
189
229
  if (!PyArg_ParseTuple(args, "iiiiii|s", &x1, &y1, &x2, &y2, &x3, &y3, &ch)) return NULL;
190
-
191
230
  PyObject* list = PyList_New(0);
192
- vector<pair<int,int>> points;
231
+ vector<pair<int,int>> pts;
193
232
  int dx = abs(x2 - x1), dy = abs(y2 - y1);
194
233
  int sx = (x1 < x2) ? 1 : -1, sy = (y1 < y2) ? 1 : -1;
195
234
  int err = dx - dy;
196
235
  while (true) {
197
- points.push_back({x1, y1});
236
+ pts.push_back({x1, y1});
198
237
  if (x1 == x2 && y1 == y2) break;
199
238
  int e2 = err * 2;
200
239
  if (e2 > -dy) { err -= dy; x1 += sx; }
@@ -204,7 +243,7 @@ static PyObject* get_triangle_points(PyObject* self, PyObject* args) {
204
243
  sx = (x2 < x3) ? 1 : -1; sy = (y2 < y3) ? 1 : -1;
205
244
  err = dx - dy;
206
245
  while (true) {
207
- points.push_back({x2, y2});
246
+ pts.push_back({x2, y2});
208
247
  if (x2 == x3 && y2 == y3) break;
209
248
  int e2 = err * 2;
210
249
  if (e2 > -dy) { err -= dy; x2 += sx; }
@@ -214,13 +253,13 @@ static PyObject* get_triangle_points(PyObject* self, PyObject* args) {
214
253
  sx = (x3 < x1) ? 1 : -1; sy = (y3 < y1) ? 1 : -1;
215
254
  err = dx - dy;
216
255
  while (true) {
217
- points.push_back({x3, y3});
256
+ pts.push_back({x3, y3});
218
257
  if (x3 == x1 && y3 == y1) break;
219
258
  int e2 = err * 2;
220
259
  if (e2 > -dy) { err -= dy; x3 += sx; }
221
260
  if (e2 < dx) { err += dx; y3 += sy; }
222
261
  }
223
- for (auto p : points) {
262
+ for (auto p : pts) {
224
263
  PyObject* tuple = PyTuple_New(3);
225
264
  PyTuple_SetItem(tuple, 0, PyLong_FromLong(p.first));
226
265
  PyTuple_SetItem(tuple, 1, PyLong_FromLong(p.second));
@@ -230,29 +269,19 @@ static PyObject* get_triangle_points(PyObject* self, PyObject* args) {
230
269
  }
231
270
  return list;
232
271
  }
272
+
233
273
  static PyObject* get_filled_triangle_points(PyObject* self, PyObject* args) {
234
274
  int x1, y1, x2, y2, x3, y3;
235
275
  const char* ch = "#";
236
276
  if (!PyArg_ParseTuple(args, "iiiiii|s", &x1, &y1, &x2, &y2, &x3, &y3, &ch)) return NULL;
237
-
238
277
  PyObject* list = PyList_New(0);
239
278
  int min_x = min(x1, min(x2, x3));
240
279
  int max_x = max(x1, max(x2, x3));
241
280
  int min_y = min(y1, min(y2, y3));
242
281
  int max_y = max(y1, max(y2, y3));
243
-
244
- auto sign = [](int px, int py, int ax, int ay, int bx, int by) {
245
- return (px - bx) * (ay - by) - (ax - bx) * (py - by);
246
- };
247
-
248
282
  for (int y = min_y; y <= max_y; y++) {
249
283
  for (int x = min_x; x <= max_x; x++) {
250
- int d1 = sign(x, y, x1, y1, x2, y2);
251
- int d2 = sign(x, y, x2, y2, x3, y3);
252
- int d3 = sign(x, y, x3, y3, x1, y1);
253
- bool has_neg = (d1 < 0) || (d2 < 0) || (d3 < 0);
254
- bool has_pos = (d1 > 0) || (d2 > 0) || (d3 > 0);
255
- if (!(has_neg && has_pos)) {
284
+ if (point_in_triangle(x, y, x1, y1, x2, y2, x3, y3)) {
256
285
  PyObject* tuple = PyTuple_New(3);
257
286
  PyTuple_SetItem(tuple, 0, PyLong_FromLong(x));
258
287
  PyTuple_SetItem(tuple, 1, PyLong_FromLong(y));
@@ -269,7 +298,6 @@ static PyObject* get_heart_points(PyObject* self, PyObject* args) {
269
298
  int cx, cy, size = 5;
270
299
  const char* ch = "#";
271
300
  if (!PyArg_ParseTuple(args, "ii|is", &cx, &cy, &size, &ch)) return NULL;
272
-
273
301
  PyObject* list = PyList_New(0);
274
302
  for (int y = -size; y <= size; y++) {
275
303
  for (int x = -size; x <= size; x++) {
@@ -287,16 +315,15 @@ static PyObject* get_heart_points(PyObject* self, PyObject* args) {
287
315
  return list;
288
316
  }
289
317
 
318
+
290
319
  static PyObject* get_star_points(PyObject* self, PyObject* args) {
291
320
  int cx, cy, radius = 5, points_count = 5;
292
321
  const char* ch = "*";
293
322
  if (!PyArg_ParseTuple(args, "ii|iis", &cx, &cy, &radius, &points_count, &ch)) return NULL;
294
-
295
323
  PyObject* list = PyList_New(0);
296
324
  double angle = -M_PI / 2.0;
297
325
  double step = M_PI / points_count;
298
326
  vector<pair<double,double>> outer, inner;
299
-
300
327
  for (int i = 0; i < points_count * 2; i++) {
301
328
  double r = (i % 2 == 0) ? radius : radius * 0.4;
302
329
  double x = cx + r * cos(angle + i * step);
@@ -304,7 +331,6 @@ static PyObject* get_star_points(PyObject* self, PyObject* args) {
304
331
  if (i % 2 == 0) outer.push_back({x, y});
305
332
  else inner.push_back({x, y});
306
333
  }
307
-
308
334
  for (int i = 0; i < points_count; i++) {
309
335
  int j = (i + 1) % points_count;
310
336
  int x1 = (int)outer[i].first, y1 = (int)outer[i].second;
@@ -344,11 +370,11 @@ static PyObject* get_star_points(PyObject* self, PyObject* args) {
344
370
  }
345
371
  return list;
346
372
  }
373
+
347
374
  static PyObject* get_wave_points(PyObject* self, PyObject* args) {
348
375
  int cx, cy, amplitude = 5, length = 20;
349
376
  const char* ch = "~";
350
377
  if (!PyArg_ParseTuple(args, "ii|iis", &cx, &cy, &amplitude, &length, &ch)) return NULL;
351
-
352
378
  PyObject* list = PyList_New(0);
353
379
  for (int x = 0; x < length; x++) {
354
380
  int y = cy + (int)(amplitude * sin(x * 0.5));
@@ -367,7 +393,6 @@ static PyObject* get_spiral_points(PyObject* self, PyObject* args) {
367
393
  double step = 0.1;
368
394
  const char* ch = "*";
369
395
  if (!PyArg_ParseTuple(args, "ii|iids", &cx, &cy, &turns, &radius, &step, &ch)) return NULL;
370
-
371
396
  PyObject* list = PyList_New(0);
372
397
  double angle = 0, r = 0;
373
398
  while (r < radius) {
@@ -389,7 +414,6 @@ static PyObject* get_bezier_points(PyObject* self, PyObject* args) {
389
414
  int x1, y1, x2, y2, x3, y3, steps = 20;
390
415
  const char* ch = "#";
391
416
  if (!PyArg_ParseTuple(args, "iiiiii|is", &x1, &y1, &x2, &y2, &x3, &y3, &steps, &ch)) return NULL;
392
-
393
417
  PyObject* list = PyList_New(0);
394
418
  for (int t = 0; t <= steps; t++) {
395
419
  double tt = (double)t / steps;
@@ -409,7 +433,6 @@ static PyObject* get_grid_points(PyObject* self, PyObject* args) {
409
433
  int x1, y1, x2, y2, step = 2;
410
434
  const char* ch = "+";
411
435
  if (!PyArg_ParseTuple(args, "iiii|is", &x1, &y1, &x2, &y2, &step, &ch)) return NULL;
412
-
413
436
  PyObject* list = PyList_New(0);
414
437
  for (int x = x1; x <= x2; x += step) {
415
438
  for (int y = y1; y <= y2; y += step) {
@@ -428,7 +451,6 @@ static PyObject* get_noise_points(PyObject* self, PyObject* args) {
428
451
  int cx, cy, radius, count = 50;
429
452
  const char* ch = ".";
430
453
  if (!PyArg_ParseTuple(args, "iii|is", &cx, &cy, &radius, &count, &ch)) return NULL;
431
-
432
454
  PyObject* list = PyList_New(0);
433
455
  srand(time(NULL));
434
456
  for (int i = 0; i < count; i++) {
@@ -452,45 +474,24 @@ static PyObject* get_cube_3d_points(PyObject* self, PyObject* args) {
452
474
  int cx = 40, cy = 12;
453
475
  const char* ch = "#";
454
476
  if (!PyArg_ParseTuple(args, "|iddddis", &size, &rotx, &roty, &rotz, &scale, &cx, &cy, &ch)) return NULL;
455
-
456
477
  PyObject* list = PyList_New(0);
457
478
  double s = size / 2.0;
458
- vector<tuple<double,double,double>> vertices = {
479
+ Vec3 vertices[8] = {
459
480
  {-s, -s, -s}, {s, -s, -s}, {s, s, -s}, {-s, s, -s},
460
481
  {-s, -s, s}, {s, -s, s}, {s, s, s}, {-s, s, s}
461
482
  };
462
- vector<pair<int,int>> edges = {
483
+ int edges[12][2] = {
463
484
  {0,1}, {1,2}, {2,3}, {3,0},
464
485
  {4,5}, {5,6}, {6,7}, {7,4},
465
486
  {0,4}, {1,5}, {2,6}, {3,7}
466
487
  };
467
-
468
- auto rotate = [&](double x, double y, double z) {
469
- double rad = rotx * M_PI / 180.0;
470
- double ca = cos(rad), sa = sin(rad);
471
- double ny = y * ca - z * sa, nz = y * sa + z * ca;
472
- y = ny; z = nz;
473
- rad = roty * M_PI / 180.0;
474
- ca = cos(rad); sa = sin(rad);
475
- double nx = x * ca + z * sa;
476
- nz = -x * sa + z * ca;
477
- x = nx; z = nz;
478
- rad = rotz * M_PI / 180.0;
479
- ca = cos(rad); sa = sin(rad);
480
- nx = x * ca - y * sa;
481
- ny = x * sa + y * ca;
482
- x = nx; y = ny;
483
- return tuple<int,int>({(int)(x * scale + cx), (int)(-y * scale + cy)});
484
- };
485
-
486
- vector<pair<int,int>> projected;
487
- for (auto v : vertices) {
488
- projected.push_back(rotate(get<0>(v), get<1>(v), get<2>(v)));
488
+ int proj[8][2];
489
+ for (int i = 0; i < 8; i++) {
490
+ project_3d(vertices[i], rotx, roty, rotz, scale, cx, cy, &proj[i][0], &proj[i][1]);
489
491
  }
490
-
491
- for (auto e : edges) {
492
- int x1 = projected[e.first].first, y1 = projected[e.first].second;
493
- int x2 = projected[e.second].first, y2 = projected[e.second].second;
492
+ for (int i = 0; i < 12; i++) {
493
+ int x1 = proj[edges[i][0]][0], y1 = proj[edges[i][0]][1];
494
+ int x2 = proj[edges[i][1]][0], y2 = proj[edges[i][1]][1];
494
495
  int dx = abs(x2 - x1), dy = abs(y2 - y1);
495
496
  int sx = (x1 < x2) ? 1 : -1, sy = (y1 < y2) ? 1 : -1;
496
497
  int err = dx - dy;
@@ -516,31 +517,14 @@ static PyObject* get_sphere_3d_points(PyObject* self, PyObject* args) {
516
517
  int cx = 40, cy = 12;
517
518
  const char* ch = "#";
518
519
  if (!PyArg_ParseTuple(args, "|iidddis", &radius, &segments, &rotx, &roty, &rotz, &scale, &cx, &cy, &ch)) return NULL;
519
-
520
520
  PyObject* list = PyList_New(0);
521
521
  for (int i = 0; i < segments; i++) {
522
522
  double theta = (double)i / segments * M_PI;
523
523
  for (int j = 0; j < segments; j++) {
524
524
  double phi = (double)j / segments * 2 * M_PI;
525
- double x = radius * sin(theta) * cos(phi);
526
- double y = radius * cos(theta);
527
- double z = radius * sin(theta) * sin(phi);
528
- double rad = rotx * M_PI / 180.0;
529
- double ca = cos(rad), sa = sin(rad);
530
- double ny = y * ca - z * sa, nz = y * sa + z * ca;
531
- y = ny; z = nz;
532
- rad = roty * M_PI / 180.0;
533
- ca = cos(rad); sa = sin(rad);
534
- double nx = x * ca + z * sa;
535
- nz = -x * sa + z * ca;
536
- x = nx; z = nz;
537
- rad = rotz * M_PI / 180.0;
538
- ca = cos(rad); sa = sin(rad);
539
- nx = x * ca - y * sa;
540
- ny = x * sa + y * ca;
541
- x = nx; y = ny;
542
- int px = (int)(x * scale + cx);
543
- int py = (int)(-y * scale + cy);
525
+ Vec3 v = {radius * sin(theta) * cos(phi), radius * cos(theta), radius * sin(theta) * sin(phi)};
526
+ int px, py;
527
+ project_3d(v, rotx, roty, rotz, scale, cx, cy, &px, &py);
544
528
  PyObject* tuple = PyTuple_New(3);
545
529
  PyTuple_SetItem(tuple, 0, PyLong_FromLong(px));
546
530
  PyTuple_SetItem(tuple, 1, PyLong_FromLong(py));
@@ -558,42 +542,24 @@ static PyObject* get_cylinder_3d_points(PyObject* self, PyObject* args) {
558
542
  int cx = 40, cy = 12;
559
543
  const char* ch = "#";
560
544
  if (!PyArg_ParseTuple(args, "|iiidddis", &radius, &height, &segments, &rotx, &roty, &rotz, &scale, &cx, &cy, &ch)) return NULL;
561
-
562
545
  PyObject* list = PyList_New(0);
563
- vector<tuple<double,double,double>> top, bottom;
546
+ Vec3 top[100], bottom[100];
564
547
  for (int i = 0; i < segments; i++) {
565
548
  double rad = (double)i / segments * 2 * M_PI;
566
- double x = radius * cos(rad), z = radius * sin(rad);
567
- top.push_back({x, (double)height/2, z});
568
- bottom.push_back({x, -(double)height/2, z});
549
+ double x = radius * cos(rad);
550
+ double z = radius * sin(rad);
551
+ top[i] = {x, (double)height / 2, z};
552
+ bottom[i] = {x, -(double)height / 2, z};
553
+ }
554
+ int proj_top[100][2], proj_bottom[100][2];
555
+ for (int i = 0; i < segments; i++) {
556
+ project_3d(top[i], rotx, roty, rotz, scale, cx, cy, &proj_top[i][0], &proj_top[i][1]);
557
+ project_3d(bottom[i], rotx, roty, rotz, scale, cx, cy, &proj_bottom[i][0], &proj_bottom[i][1]);
569
558
  }
570
-
571
- auto rotate = [&](double x, double y, double z) {
572
- double rad = rotx * M_PI / 180.0;
573
- double ca = cos(rad), sa = sin(rad);
574
- double ny = y * ca - z * sa, nz = y * sa + z * ca;
575
- y = ny; z = nz;
576
- rad = roty * M_PI / 180.0;
577
- ca = cos(rad); sa = sin(rad);
578
- double nx = x * ca + z * sa;
579
- nz = -x * sa + z * ca;
580
- x = nx; z = nz;
581
- rad = rotz * M_PI / 180.0;
582
- ca = cos(rad); sa = sin(rad);
583
- nx = x * ca - y * sa;
584
- ny = x * sa + y * ca;
585
- x = nx; y = ny;
586
- return tuple<int,int>({(int)(x * scale + cx), (int)(-y * scale + cy)});
587
- };
588
-
589
- vector<pair<int,int>> proj_top, proj_bottom;
590
- for (auto v : top) proj_top.push_back(rotate(get<0>(v), get<1>(v), get<2>(v)));
591
- for (auto v : bottom) proj_bottom.push_back(rotate(get<0>(v), get<1>(v), get<2>(v)));
592
-
593
559
  for (int i = 0; i < segments; i++) {
594
560
  int j = (i + 1) % segments;
595
- int x1 = proj_top[i].first, y1 = proj_top[i].second;
596
- int x2 = proj_top[j].first, y2 = proj_top[j].second;
561
+ int x1 = proj_top[i][0], y1 = proj_top[i][1];
562
+ int x2 = proj_top[j][0], y2 = proj_top[j][1];
597
563
  int dx = abs(x2 - x1), dy = abs(y2 - y1);
598
564
  int sx = (x1 < x2) ? 1 : -1, sy = (y1 < y2) ? 1 : -1;
599
565
  int err = dx - dy;
@@ -609,8 +575,8 @@ static PyObject* get_cylinder_3d_points(PyObject* self, PyObject* args) {
609
575
  if (e2 > -dy) { err -= dy; x1 += sx; }
610
576
  if (e2 < dx) { err += dx; y1 += sy; }
611
577
  }
612
- x1 = proj_bottom[i].first; y1 = proj_bottom[i].second;
613
- x2 = proj_bottom[j].first; y2 = proj_bottom[j].second;
578
+ x1 = proj_bottom[i][0]; y1 = proj_bottom[i][1];
579
+ x2 = proj_bottom[j][0]; y2 = proj_bottom[j][1];
614
580
  dx = abs(x2 - x1); dy = abs(y2 - y1);
615
581
  sx = (x1 < x2) ? 1 : -1; sy = (y1 < y2) ? 1 : -1;
616
582
  err = dx - dy;
@@ -626,8 +592,8 @@ static PyObject* get_cylinder_3d_points(PyObject* self, PyObject* args) {
626
592
  if (e2 > -dy) { err -= dy; x1 += sx; }
627
593
  if (e2 < dx) { err += dx; y1 += sy; }
628
594
  }
629
- x1 = proj_top[i].first; y1 = proj_top[i].second;
630
- x2 = proj_bottom[i].first; y2 = proj_bottom[i].second;
595
+ x1 = proj_top[i][0]; y1 = proj_top[i][1];
596
+ x2 = proj_bottom[i][0]; y2 = proj_bottom[i][1];
631
597
  dx = abs(x2 - x1); dy = abs(y2 - y1);
632
598
  sx = (x1 < x2) ? 1 : -1; sy = (y1 < y2) ? 1 : -1;
633
599
  err = dx - dy;
@@ -646,47 +612,29 @@ static PyObject* get_cylinder_3d_points(PyObject* self, PyObject* args) {
646
612
  }
647
613
  return list;
648
614
  }
615
+
649
616
  static PyObject* get_cone_3d_points(PyObject* self, PyObject* args) {
650
617
  int radius = 5, height = 10, segments = 12;
651
618
  double rotx = 0, roty = 0, rotz = 0, scale = 10.0;
652
619
  int cx = 40, cy = 12;
653
620
  const char* ch = "#";
654
621
  if (!PyArg_ParseTuple(args, "|iiidddis", &radius, &height, &segments, &rotx, &roty, &rotz, &scale, &cx, &cy, &ch)) return NULL;
655
-
656
622
  PyObject* list = PyList_New(0);
657
- vector<tuple<double,double,double>> base;
623
+ Vec3 base[100];
658
624
  for (int i = 0; i < segments; i++) {
659
625
  double rad = (double)i / segments * 2 * M_PI;
660
- base.push_back({radius * cos(rad), -(double)height/2, radius * sin(rad)});
626
+ base[i] = {radius * cos(rad), -(double)height / 2, radius * sin(rad)};
661
627
  }
662
- tuple<double,double,double> apex = {0, (double)height/2, 0};
663
-
664
- auto rotate = [&](double x, double y, double z) {
665
- double rad = rotx * M_PI / 180.0;
666
- double ca = cos(rad), sa = sin(rad);
667
- double ny = y * ca - z * sa, nz = y * sa + z * ca;
668
- y = ny; z = nz;
669
- rad = roty * M_PI / 180.0;
670
- ca = cos(rad); sa = sin(rad);
671
- double nx = x * ca + z * sa;
672
- nz = -x * sa + z * ca;
673
- x = nx; z = nz;
674
- rad = rotz * M_PI / 180.0;
675
- ca = cos(rad); sa = sin(rad);
676
- nx = x * ca - y * sa;
677
- ny = x * sa + y * ca;
678
- x = nx; y = ny;
679
- return tuple<int,int>({(int)(x * scale + cx), (int)(-y * scale + cy)});
680
- };
681
-
682
- vector<pair<int,int>> proj_base;
683
- for (auto v : base) proj_base.push_back(rotate(get<0>(v), get<1>(v), get<2>(v)));
684
- pair<int,int> proj_apex = rotate(get<0>(apex), get<1>(apex), get<2>(apex));
685
-
628
+ Vec3 apex = {0, (double)height / 2, 0};
629
+ int proj_base[100][2], proj_apex[2];
630
+ for (int i = 0; i < segments; i++) {
631
+ project_3d(base[i], rotx, roty, rotz, scale, cx, cy, &proj_base[i][0], &proj_base[i][1]);
632
+ }
633
+ project_3d(apex, rotx, roty, rotz, scale, cx, cy, &proj_apex[0], &proj_apex[1]);
686
634
  for (int i = 0; i < segments; i++) {
687
635
  int j = (i + 1) % segments;
688
- int x1 = proj_base[i].first, y1 = proj_base[i].second;
689
- int x2 = proj_base[j].first, y2 = proj_base[j].second;
636
+ int x1 = proj_base[i][0], y1 = proj_base[i][1];
637
+ int x2 = proj_base[j][0], y2 = proj_base[j][1];
690
638
  int dx = abs(x2 - x1), dy = abs(y2 - y1);
691
639
  int sx = (x1 < x2) ? 1 : -1, sy = (y1 < y2) ? 1 : -1;
692
640
  int err = dx - dy;
@@ -702,8 +650,8 @@ static PyObject* get_cone_3d_points(PyObject* self, PyObject* args) {
702
650
  if (e2 > -dy) { err -= dy; x1 += sx; }
703
651
  if (e2 < dx) { err += dx; y1 += sy; }
704
652
  }
705
- x1 = proj_base[i].first; y1 = proj_base[i].second;
706
- x2 = proj_apex.first; y2 = proj_apex.second;
653
+ x1 = proj_base[i][0]; y1 = proj_base[i][1];
654
+ x2 = proj_apex[0]; y2 = proj_apex[1];
707
655
  dx = abs(x2 - x1); dy = abs(y2 - y1);
708
656
  sx = (x1 < x2) ? 1 : -1; sy = (y1 < y2) ? 1 : -1;
709
657
  err = dx - dy;
@@ -729,31 +677,14 @@ static PyObject* get_torus_3d_points(PyObject* self, PyObject* args) {
729
677
  int cx = 40, cy = 12;
730
678
  const char* ch = "#";
731
679
  if (!PyArg_ParseTuple(args, "|iiidddis", &radius, &tube, &segments, &rotx, &roty, &rotz, &scale, &cx, &cy, &ch)) return NULL;
732
-
733
680
  PyObject* list = PyList_New(0);
734
681
  for (int i = 0; i < segments; i++) {
735
682
  double theta = (double)i / segments * 2 * M_PI;
736
683
  for (int j = 0; j < segments; j++) {
737
684
  double phi = (double)j / segments * 2 * M_PI;
738
- double x = (radius + tube * cos(phi)) * cos(theta);
739
- double y = tube * sin(phi);
740
- double z = (radius + tube * cos(phi)) * sin(theta);
741
- double rad = rotx * M_PI / 180.0;
742
- double ca = cos(rad), sa = sin(rad);
743
- double ny = y * ca - z * sa, nz = y * sa + z * ca;
744
- y = ny; z = nz;
745
- rad = roty * M_PI / 180.0;
746
- ca = cos(rad); sa = sin(rad);
747
- double nx = x * ca + z * sa;
748
- nz = -x * sa + z * ca;
749
- x = nx; z = nz;
750
- rad = rotz * M_PI / 180.0;
751
- ca = cos(rad); sa = sin(rad);
752
- nx = x * ca - y * sa;
753
- ny = x * sa + y * ca;
754
- x = nx; y = ny;
755
- int px = (int)(x * scale + cx);
756
- int py = (int)(-y * scale + cy);
685
+ Vec3 v = {(radius + tube * cos(phi)) * cos(theta), tube * sin(phi), (radius + tube * cos(phi)) * sin(theta)};
686
+ int px, py;
687
+ project_3d(v, rotx, roty, rotz, scale, cx, cy, &px, &py);
757
688
  PyObject* tuple = PyTuple_New(3);
758
689
  PyTuple_SetItem(tuple, 0, PyLong_FromLong(px));
759
690
  PyTuple_SetItem(tuple, 1, PyLong_FromLong(py));
@@ -764,58 +695,43 @@ static PyObject* get_torus_3d_points(PyObject* self, PyObject* args) {
764
695
  }
765
696
  return list;
766
697
  }
698
+
767
699
  static PyObject* get_ico_sphere_3d_points(PyObject* self, PyObject* args) {
768
700
  int radius = 5;
769
701
  double rotx = 0, roty = 0, rotz = 0, scale = 10.0;
770
702
  int cx = 40, cy = 12;
771
703
  const char* ch = "#";
772
704
  if (!PyArg_ParseTuple(args, "|idddis", &radius, &rotx, &roty, &rotz, &scale, &cx, &cy, &ch)) return NULL;
773
-
774
705
  PyObject* list = PyList_New(0);
775
706
  double phi = (1 + sqrt(5)) / 2.0;
776
- vector<tuple<double,double,double>> vertices = {
707
+ Vec3 verts[12] = {
777
708
  {-1, phi, 0}, {1, phi, 0}, {-1, -phi, 0}, {1, -phi, 0},
778
709
  {0, -1, phi}, {0, 1, phi}, {0, -1, -phi}, {0, 1, -phi},
779
710
  {phi, 0, -1}, {phi, 0, 1}, {-phi, 0, -1}, {-phi, 0, 1}
780
711
  };
781
- for (auto& v : vertices) {
782
- get<0>(v) *= radius / 1.618;
783
- get<1>(v) *= radius / 1.618;
784
- get<2>(v) *= radius / 1.618;
712
+ for (int i = 0; i < 12; i++) {
713
+ verts[i].x *= radius / 1.618;
714
+ verts[i].y *= radius / 1.618;
715
+ verts[i].z *= radius / 1.618;
785
716
  }
786
- vector<pair<int,int>> edges = {
717
+ int edges[30][2] = {
787
718
  {0,1}, {0,4}, {0,5}, {0,10}, {0,11},
788
719
  {1,2}, {1,5}, {1,7}, {1,8}, {1,9},
789
720
  {2,3}, {2,6}, {2,7}, {2,10}, {2,11},
790
721
  {3,4}, {3,6}, {3,8}, {3,9}, {3,11},
791
- {4,5}, {4,9}, {4,11}, {5,7}, {5,9},
792
- {6,7}, {6,10}, {7,8}, {8,9}, {8,10}, {10,11}
793
- };
794
-
795
- auto rotate = [&](double x, double y, double z) {
796
- double rad = rotx * M_PI / 180.0;
797
- double ca = cos(rad), sa = sin(rad);
798
- double ny = y * ca - z * sa, nz = y * sa + z * ca;
799
- y = ny; z = nz;
800
- rad = roty * M_PI / 180.0;
801
- ca = cos(rad); sa = sin(rad);
802
- double nx = x * ca + z * sa;
803
- nz = -x * sa + z * ca;
804
- x = nx; z = nz;
805
- rad = rotz * M_PI / 180.0;
806
- ca = cos(rad); sa = sin(rad);
807
- nx = x * ca - y * sa;
808
- ny = x * sa + y * ca;
809
- x = nx; y = ny;
810
- return tuple<int,int>({(int)(x * scale + cx), (int)(-y * scale + cy)});
722
+ {4,5}, {4,9}, {4,11},
723
+ {5,7}, {5,9},
724
+ {6,7}, {6,10},
725
+ {7,8},
726
+ {8,9}, {8,10}
811
727
  };
812
-
813
- vector<pair<int,int>> projected;
814
- for (auto v : vertices) projected.push_back(rotate(get<0>(v), get<1>(v), get<2>(v)));
815
-
816
- for (auto e : edges) {
817
- int x1 = projected[e.first].first, y1 = projected[e.first].second;
818
- int x2 = projected[e.second].first, y2 = projected[e.second].second;
728
+ int proj[12][2];
729
+ for (int i = 0; i < 12; i++) {
730
+ project_3d(verts[i], rotx, roty, rotz, scale, cx, cy, &proj[i][0], &proj[i][1]);
731
+ }
732
+ for (int i = 0; i < 30; i++) {
733
+ int x1 = proj[edges[i][0]][0], y1 = proj[edges[i][0]][1];
734
+ int x2 = proj[edges[i][1]][0], y2 = proj[edges[i][1]][1];
819
735
  int dx = abs(x2 - x1), dy = abs(y2 - y1);
820
736
  int sx = (x1 < x2) ? 1 : -1, sy = (y1 < y2) ? 1 : -1;
821
737
  int err = dx - dy;
@@ -840,7 +756,6 @@ static PyObject* DrawPic(PyObject* self, PyObject* args) {
840
756
  int width = 80, height = 25, clear_before = 0;
841
757
  const char* default_char = " ";
842
758
  if (!PyArg_ParseTuple(args, "|Oiiis", &points, &width, &height, &clear_before, &default_char)) return NULL;
843
-
844
759
  if (clear_before) {
845
760
  #ifdef _WIN32
846
761
  system("cls");
@@ -848,9 +763,7 @@ static PyObject* DrawPic(PyObject* self, PyObject* args) {
848
763
  system("clear");
849
764
  #endif
850
765
  }
851
-
852
766
  vector<vector<string>> field(height, vector<string>(width, default_char));
853
-
854
767
  if (points && PyList_Check(points)) {
855
768
  Py_ssize_t n = PyList_Size(points);
856
769
  for (Py_ssize_t i = 0; i < n; i++) {
@@ -866,14 +779,12 @@ static PyObject* DrawPic(PyObject* self, PyObject* args) {
866
779
  }
867
780
  }
868
781
  }
869
-
870
782
  for (int y = 0; y < height; y++) {
871
783
  for (int x = 0; x < width; x++) {
872
784
  cout << field[y][x];
873
785
  }
874
786
  cout << endl;
875
787
  }
876
-
877
788
  Py_RETURN_NONE;
878
789
  }
879
790
 
@@ -891,11 +802,11 @@ static PyObject* GetKey(PyObject* self, PyObject* args) {
891
802
  #endif
892
803
  return PyUnicode_FromStringAndSize(&ch, 1);
893
804
  }
805
+
894
806
  static PyObject* StartPyCode(PyObject* self, PyObject* args) {
895
807
  const char* code;
896
808
  int wait = 0;
897
809
  if (!PyArg_ParseTuple(args, "s|i", &code, &wait)) return NULL;
898
-
899
810
  string cmd = "python -c \"" + string(code) + "\"";
900
811
  if (!wait) cmd += " &";
901
812
  int result = system(cmd.c_str());
@@ -905,7 +816,6 @@ static PyObject* StartPyCode(PyObject* self, PyObject* args) {
905
816
  static PyObject* KillPyScript(PyObject* self, PyObject* args) {
906
817
  int pid;
907
818
  if (!PyArg_ParseTuple(args, "i", &pid)) return NULL;
908
-
909
819
  #ifdef _WIN32
910
820
  string cmd = "taskkill /PID " + to_string(pid);
911
821
  #else
@@ -918,7 +828,6 @@ static PyObject* KillPyScript(PyObject* self, PyObject* args) {
918
828
  static PyObject* IsRunning(PyObject* self, PyObject* args) {
919
829
  int pid;
920
830
  if (!PyArg_ParseTuple(args, "i", &pid)) return NULL;
921
-
922
831
  #ifdef _WIN32
923
832
  HANDLE process = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, pid);
924
833
  if (process) {
@@ -946,7 +855,6 @@ static PyObject* WaitForProcess(PyObject* self, PyObject* args) {
946
855
  int pid;
947
856
  int timeout = -1;
948
857
  if (!PyArg_ParseTuple(args, "i|i", &pid, &timeout)) return NULL;
949
-
950
858
  int elapsed = 0;
951
859
  while (true) {
952
860
  #ifdef _WIN32
@@ -969,7 +877,6 @@ static PyObject* WaitForProcess(PyObject* self, PyObject* args) {
969
877
  static PyObject* GetProcessList(PyObject* self, PyObject* args) {
970
878
  PyObject* list = PyList_New(0);
971
879
  #ifdef _WIN32
972
- // Windows implementation would require PSAPI or Toolhelp
973
880
  PyObject* tuple = PyTuple_New(2);
974
881
  PyTuple_SetItem(tuple, 0, PyLong_FromLong(0));
975
882
  PyTuple_SetItem(tuple, 1, PyUnicode_FromString("Not implemented on Windows"));
@@ -997,10 +904,10 @@ static PyObject* GetProcessList(PyObject* self, PyObject* args) {
997
904
  #endif
998
905
  return list;
999
906
  }
907
+
1000
908
  static PyObject* GetProcessInfo(PyObject* self, PyObject* args) {
1001
909
  int pid;
1002
910
  if (!PyArg_ParseTuple(args, "i", &pid)) return NULL;
1003
-
1004
911
  #ifdef _WIN32
1005
912
  return PyUnicode_FromString("Not implemented on Windows");
1006
913
  #else
@@ -1042,7 +949,6 @@ static PyObject* animate_print(PyObject* self, PyObject* args) {
1042
949
  double delay = 0.05;
1043
950
  int backspace = 0;
1044
951
  if (!PyArg_ParseTuple(args, "s|di", &text, &delay, &backspace)) return NULL;
1045
-
1046
952
  if (backspace) {
1047
953
  for (int i = 0; text[i]; i++) {
1048
954
  cout << text[i] << flush;
@@ -1072,7 +978,6 @@ static PyObject* spinning_cursor(PyObject* self, PyObject* args) {
1072
978
  double duration = 3.0, delay = 0.1;
1073
979
  int clear_before = 0;
1074
980
  if (!PyArg_ParseTuple(args, "|sddi", &message, &duration, &delay, &clear_before)) return NULL;
1075
-
1076
981
  if (clear_before) clear_screen(NULL, NULL);
1077
982
  vector<string> frames = {"|", "/", "-", "\\"};
1078
983
  double end_time = time(NULL) + duration;
@@ -1091,7 +996,6 @@ static PyObject* countdown(PyObject* self, PyObject* args) {
1091
996
  const char* message = "Countdown";
1092
997
  int clear_before = 0;
1093
998
  if (!PyArg_ParseTuple(args, "i|si", &seconds, &message, &clear_before)) return NULL;
1094
-
1095
999
  if (clear_before) clear_screen(NULL, NULL);
1096
1000
  for (int i = seconds; i > 0; i--) {
1097
1001
  cout << "\r" << message << ": " << i << " seconds remaining " << flush;
@@ -1124,32 +1028,28 @@ static PyObject* GetPipVer(PyObject* self, PyObject* args) {
1124
1028
  #endif
1125
1029
  return PyUnicode_FromString("Error: Python not installed");
1126
1030
  }
1031
+
1127
1032
  #ifdef _WIN32
1128
1033
  static PyObject* Connect(PyObject* self, PyObject* args) {
1129
1034
  const char* host = "127.0.0.1";
1130
1035
  int port = 54321;
1131
1036
  if (!PyArg_ParseTuple(args, "|si", &host, &port)) return NULL;
1132
-
1133
1037
  WSADATA wsaData;
1134
1038
  WSAStartup(MAKEWORD(2,2), &wsaData);
1135
-
1136
1039
  int sock = socket(AF_INET, SOCK_STREAM, 0);
1137
1040
  if (sock == INVALID_SOCKET) {
1138
1041
  WSACleanup();
1139
1042
  return PyLong_FromLong(-1);
1140
1043
  }
1141
-
1142
1044
  struct sockaddr_in server;
1143
1045
  server.sin_family = AF_INET;
1144
1046
  server.sin_port = htons(port);
1145
1047
  server.sin_addr.s_addr = inet_addr(host);
1146
-
1147
1048
  if (connect(sock, (struct sockaddr*)&server, sizeof(server)) == SOCKET_ERROR) {
1148
1049
  closesocket(sock);
1149
1050
  WSACleanup();
1150
1051
  return PyLong_FromLong(-1);
1151
1052
  }
1152
-
1153
1053
  return PyLong_FromLong(sock);
1154
1054
  }
1155
1055
  #else
@@ -1157,20 +1057,16 @@ static PyObject* Connect(PyObject* self, PyObject* args) {
1157
1057
  const char* host = "127.0.0.1";
1158
1058
  int port = 54321;
1159
1059
  if (!PyArg_ParseTuple(args, "|si", &host, &port)) return NULL;
1160
-
1161
1060
  int sock = socket(AF_INET, SOCK_STREAM, 0);
1162
1061
  if (sock < 0) return PyLong_FromLong(-1);
1163
-
1164
1062
  struct sockaddr_in server;
1165
1063
  server.sin_family = AF_INET;
1166
1064
  server.sin_port = htons(port);
1167
1065
  server.sin_addr.s_addr = inet_addr(host);
1168
-
1169
1066
  if (connect(sock, (struct sockaddr*)&server, sizeof(server)) < 0) {
1170
1067
  close(sock);
1171
1068
  return PyLong_FromLong(-1);
1172
1069
  }
1173
-
1174
1070
  return PyLong_FromLong(sock);
1175
1071
  }
1176
1072
  #endif
@@ -1178,7 +1074,6 @@ static PyObject* Connect(PyObject* self, PyObject* args) {
1178
1074
  static PyObject* ConnectPublic(PyObject* self, PyObject* args) {
1179
1075
  int port = 54321;
1180
1076
  if (!PyArg_ParseTuple(args, "|i", &port)) return NULL;
1181
-
1182
1077
  #ifdef _WIN32
1183
1078
  WSADATA wsaData;
1184
1079
  WSAStartup(MAKEWORD(2,2), &wsaData);
@@ -1188,7 +1083,6 @@ static PyObject* ConnectPublic(PyObject* self, PyObject* args) {
1188
1083
  int sock = socket(AF_INET, SOCK_STREAM, 0);
1189
1084
  if (sock < 0) return PyLong_FromLong(-1);
1190
1085
  #endif
1191
-
1192
1086
  struct sockaddr_in server;
1193
1087
  server.sin_family = AF_INET;
1194
1088
  server.sin_port = htons(80);
@@ -1197,7 +1091,6 @@ static PyObject* ConnectPublic(PyObject* self, PyObject* args) {
1197
1091
  #else
1198
1092
  inet_aton("216.58.200.78", &server.sin_addr);
1199
1093
  #endif
1200
-
1201
1094
  if (connect(sock, (struct sockaddr*)&server, sizeof(server)) < 0) {
1202
1095
  #ifdef _WIN32
1203
1096
  closesocket(sock); WSACleanup();
@@ -1206,7 +1099,6 @@ static PyObject* ConnectPublic(PyObject* self, PyObject* args) {
1206
1099
  #endif
1207
1100
  return PyLong_FromLong(-1);
1208
1101
  }
1209
-
1210
1102
  string request = "GET /ip HTTP/1.1\r\nHost: api.ipify.org\r\nConnection: close\r\n\r\n";
1211
1103
  send(sock, request.c_str(), request.length(), 0);
1212
1104
  char buffer[4096];
@@ -1222,7 +1114,6 @@ static PyObject* ConnectPublic(PyObject* self, PyObject* args) {
1222
1114
  #else
1223
1115
  close(sock);
1224
1116
  #endif
1225
-
1226
1117
  size_t pos = response.find("\r\n\r\n");
1227
1118
  if (pos != string::npos) {
1228
1119
  string body = response.substr(pos + 4);
@@ -1236,7 +1127,6 @@ static PyObject* Send(PyObject* self, PyObject* args) {
1236
1127
  int sock;
1237
1128
  const char* message;
1238
1129
  if (!PyArg_ParseTuple(args, "is", &sock, &message)) return NULL;
1239
-
1240
1130
  int result = send(sock, message, strlen(message), 0);
1241
1131
  return PyLong_FromLong(result);
1242
1132
  }
@@ -1245,7 +1135,6 @@ static PyObject* Receive(PyObject* self, PyObject* args) {
1245
1135
  int sock;
1246
1136
  int size = 1024;
1247
1137
  if (!PyArg_ParseTuple(args, "i|i", &sock, &size)) return NULL;
1248
-
1249
1138
  char* buffer = (char*)malloc(size + 1);
1250
1139
  int result = recv(sock, buffer, size, 0);
1251
1140
  if (result > 0) {
@@ -1257,10 +1146,10 @@ static PyObject* Receive(PyObject* self, PyObject* args) {
1257
1146
  free(buffer);
1258
1147
  return PyUnicode_FromString("");
1259
1148
  }
1149
+
1260
1150
  static PyObject* Disconnect(PyObject* self, PyObject* args) {
1261
1151
  int sock;
1262
1152
  if (!PyArg_ParseTuple(args, "i", &sock)) return NULL;
1263
-
1264
1153
  #ifdef _WIN32
1265
1154
  closesocket(sock);
1266
1155
  WSACleanup();
@@ -1278,60 +1167,44 @@ static PyObject* GetPublicIP(PyObject* self, PyObject* args) {
1278
1167
  static PyObject* CreateServer(PyObject* self, PyObject* args) {
1279
1168
  int port = 54321;
1280
1169
  if (!PyArg_ParseTuple(args, "|i", &port)) return NULL;
1281
-
1282
1170
  #ifdef _WIN32
1283
1171
  WSADATA wsaData;
1284
1172
  WSAStartup(MAKEWORD(2,2), &wsaData);
1285
1173
  int server_sock = socket(AF_INET, SOCK_STREAM, 0);
1286
- if (server_sock == INVALID_SOCKET) {
1287
- WSACleanup();
1288
- return PyLong_FromLong(-1);
1289
- }
1174
+ if (server_sock == INVALID_SOCKET) { WSACleanup(); return PyLong_FromLong(-1); }
1290
1175
  #else
1291
1176
  int server_sock = socket(AF_INET, SOCK_STREAM, 0);
1292
- if (server_sock < 0) {
1293
- return PyLong_FromLong(-1);
1294
- }
1177
+ if (server_sock < 0) return PyLong_FromLong(-1);
1295
1178
  #endif
1296
-
1297
1179
  int opt = 1;
1298
1180
  #ifdef _WIN32
1299
1181
  setsockopt(server_sock, SOL_SOCKET, SO_REUSEADDR, (char*)&opt, sizeof(opt));
1300
1182
  #else
1301
1183
  setsockopt(server_sock, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt));
1302
1184
  #endif
1303
-
1304
1185
  struct sockaddr_in server;
1305
1186
  server.sin_family = AF_INET;
1306
1187
  server.sin_addr.s_addr = INADDR_ANY;
1307
1188
  server.sin_port = htons(port);
1308
-
1309
1189
  #ifdef _WIN32
1310
1190
  if (::bind(server_sock, (struct sockaddr*)&server, sizeof(server)) == SOCKET_ERROR) {
1311
- closesocket(server_sock);
1312
- WSACleanup();
1313
- return PyLong_FromLong(-1);
1191
+ closesocket(server_sock); WSACleanup(); return PyLong_FromLong(-1);
1314
1192
  }
1315
1193
  if (listen(server_sock, 1) == SOCKET_ERROR) {
1316
- closesocket(server_sock);
1317
- WSACleanup();
1318
- return PyLong_FromLong(-1);
1194
+ closesocket(server_sock); WSACleanup(); return PyLong_FromLong(-1);
1319
1195
  }
1320
1196
  #else
1321
1197
  if (::bind(server_sock, (struct sockaddr*)&server, sizeof(server)) < 0) {
1322
- close(server_sock);
1323
- return PyLong_FromLong(-1);
1198
+ close(server_sock); return PyLong_FromLong(-1);
1324
1199
  }
1325
1200
  if (listen(server_sock, 1) < 0) {
1326
- close(server_sock);
1327
- return PyLong_FromLong(-1);
1201
+ close(server_sock); return PyLong_FromLong(-1);
1328
1202
  }
1329
1203
  #endif
1330
-
1331
1204
  return PyLong_FromLong(server_sock);
1332
1205
  }
1333
1206
 
1334
- static PyMethodDef ConsoleToolsMethods[] = {
1207
+ static PyMethodDef CoreMethods[] = {
1335
1208
  {"rgb", rgb, METH_VARARGS, "RGB color"},
1336
1209
  {"bg_rgb", bg_rgb, METH_VARARGS, "RGB background"},
1337
1210
  {"colorize", colorize, METH_VARARGS, "Colorize text"},
@@ -1361,16 +1234,15 @@ static PyMethodDef ConsoleToolsMethods[] = {
1361
1234
  {"KillPyScript", KillPyScript, METH_VARARGS, "Kill Python script"},
1362
1235
  {"IsRunning", IsRunning, METH_VARARGS, "Check if process is running"},
1363
1236
  {"GetCurrentPID", GetCurrentPID, METH_VARARGS, "Get current PID"},
1364
- {"WaitForProcess", WaitForProcess, METH_VARARGS, "Wait for process to finish"},
1365
- {"GetProcessList", GetProcessList, METH_VARARGS, "Get list of processes"},
1237
+ {"WaitForProcess", WaitForProcess, METH_VARARGS, "Wait for process"},
1238
+ {"GetProcessList", GetProcessList, METH_VARARGS, "Get process list"},
1366
1239
  {"GetProcessInfo", GetProcessInfo, METH_VARARGS, "Get process info"},
1367
1240
  {"clear_screen", clear_screen, METH_VARARGS, "Clear screen"},
1368
1241
  {"animate_print", animate_print, METH_VARARGS, "Animate print"},
1369
- {"spinning_cursor", spinning_cursor, METH_VARARGS, "Spinning cursor animation"},
1370
- {"countdown", countdown, METH_VARARGS, "Countdown animation"},
1242
+ {"spinning_cursor", spinning_cursor, METH_VARARGS, "Spinning cursor"},
1243
+ {"countdown", countdown, METH_VARARGS, "Countdown"},
1371
1244
  {"GetPipVer", GetPipVer, METH_VARARGS, "Get pip version"},
1372
1245
  {"Connect", Connect, METH_VARARGS, "Connect to server"},
1373
- {"ConnectPublic", ConnectPublic, METH_VARARGS, "Connect to public IP"},
1374
1246
  {"Send", Send, METH_VARARGS, "Send message"},
1375
1247
  {"Receive", Receive, METH_VARARGS, "Receive message"},
1376
1248
  {"Disconnect", Disconnect, METH_VARARGS, "Disconnect"},
@@ -1379,17 +1251,16 @@ static PyMethodDef ConsoleToolsMethods[] = {
1379
1251
  {NULL, NULL, 0, NULL}
1380
1252
  };
1381
1253
 
1382
- static struct PyModuleDef consoleutilsmodule = {
1254
+ static struct PyModuleDef coremodule = {
1383
1255
  PyModuleDef_HEAD_INIT,
1384
- "ConsoleUtils",
1256
+ "core",
1385
1257
  "The best Console Library of the Python.",
1386
1258
  -1,
1387
- ConsoleToolsMethods
1259
+ CoreMethods
1388
1260
  };
1389
1261
 
1390
- PyMODINIT_FUNC PyInit_ConsoleUtils(void) {
1391
- PyObject* module = PyModule_Create(&consoleutilsmodule);
1392
-
1262
+ PyMODINIT_FUNC PyInit_core(void) {
1263
+ PyObject* module = PyModule_Create(&coremodule);
1393
1264
  PyModule_AddStringConstant(module, "RED", "\033[31m");
1394
1265
  PyModule_AddStringConstant(module, "GREEN", "\033[32m");
1395
1266
  PyModule_AddStringConstant(module, "BLUE", "\033[34m");
@@ -1404,6 +1275,5 @@ PyMODINIT_FUNC PyInit_ConsoleUtils(void) {
1404
1275
  PyModule_AddStringConstant(module, "BG_BLUE", "\033[44m");
1405
1276
  PyModule_AddStringConstant(module, "BOLD", "\033[1m");
1406
1277
  PyModule_AddStringConstant(module, "UNDERLINE", "\033[4m");
1407
-
1408
1278
  return module;
1409
1279
  }
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ConsoleFramework
3
- Version: 1.2.1
3
+ Version: 1.3.0
4
4
  Summary: The best Console Library of the Python.
5
5
  Author: Suleiman
6
6
  Author-email: steal.apet@mail.ru
@@ -1,9 +1,12 @@
1
+ MANIFEST.in
1
2
  setup.py
3
+ ConsoleFramework/__init__.py
4
+ ConsoleFramework/core.cpp
2
5
  ConsoleFramework.egg-info/PKG-INFO
3
6
  ConsoleFramework.egg-info/SOURCES.txt
4
7
  ConsoleFramework.egg-info/dependency_links.txt
5
8
  ConsoleFramework.egg-info/not-zip-safe
6
9
  ConsoleFramework.egg-info/top_level.txt
7
- ConsoleTools/core.cpp
8
- consoletools/__init__.py
9
- consoletools/core.cpp
10
+ consoleframework/__init__.py
11
+ consoleframework/core.cpp
12
+ consoleframework/core.cpython-313-aarch64-linux-android.so
@@ -0,0 +1 @@
1
+ ConsoleFramework
@@ -0,0 +1,4 @@
1
+ include consoleframework/*
2
+ include consoleframework/core.cpp
3
+ include consoleframework/__init__.py
4
+ recursive-include consoleframework *.py *.cpp
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ConsoleFramework
3
- Version: 1.2.1
3
+ Version: 1.3.0
4
4
  Summary: The best Console Library of the Python.
5
5
  Author: Suleiman
6
6
  Author-email: steal.apet@mail.ru
@@ -2,8 +2,8 @@ from setuptools import setup, Extension
2
2
 
3
3
  ext_modules = [
4
4
  Extension(
5
- "consoletools.core",
6
- sources=["consoletools/core.cpp"],
5
+ "ConsoleFramework.core",
6
+ sources=["ConsoleFramework/core.cpp"],
7
7
  language="c++",
8
8
  extra_compile_args=["-std=c++11", "-O3"],
9
9
  ),
@@ -11,15 +11,16 @@ ext_modules = [
11
11
 
12
12
  setup(
13
13
  name="ConsoleFramework",
14
- version="1.2.1",
14
+ version="1.3.0",
15
15
  description="The best Console Library of the Python.",
16
16
  long_description="ConsoleFramework - C++ library for Python console rendering.",
17
17
  long_description_content_type="text/plain",
18
18
  author="Suleiman",
19
19
  author_email="steal.apet@mail.ru",
20
20
  license="MIT",
21
- packages=["consoletools"],
21
+ packages=["ConsoleFramework"],
22
22
  ext_modules=ext_modules,
23
23
  python_requires=">=3.6",
24
24
  zip_safe=False,
25
+ include_package_data=True,
25
26
  )
@@ -1 +0,0 @@
1
- consoletools