summaryrefslogtreecommitdiff
path: root/cube.py
diff options
context:
space:
mode:
authorЕгор Львов <workregor@mail.ru>2023-03-27 11:25:27 +0300
committerЕгор Львов <workregor@mail.ru>2023-03-27 11:25:27 +0300
commit3c0a3b8413ee58a3e5678075c862e95f7c8395c6 (patch)
tree8ca9eba9378f921636788fee7664c2bd63bc40ff /cube.py
Начальный коммит
Diffstat (limited to 'cube.py')
-rw-r--r--cube.py73
1 files changed, 73 insertions, 0 deletions
diff --git a/cube.py b/cube.py
new file mode 100644
index 0000000..1b13586
--- /dev/null
+++ b/cube.py
@@ -0,0 +1,73 @@
+import math
+import time
+
+# Определение вершин куба
+vertices = [
+ [-1, -1, -1],
+ [-1, 1, -1],
+ [1, 1, -1],
+ [1, -1, -1],
+ [-1, -1, 1],
+ [-1, 1, 1],
+ [1, 1, 1],
+ [1, -1, 1]
+]
+
+# Определение ребер куба
+edges = [
+ [0, 1],
+ [1, 2],
+ [2, 3],
+ [3, 0],
+ [4, 5],
+ [5, 6],
+ [6, 7],
+ [7, 4],
+ [0, 4],
+ [1, 5],
+ [2, 6],
+ [3, 7]
+]
+
+# Определение угла вращения куба
+theta = 0
+
+while True:
+ # Очистка экрана
+ print("\033c", end="")
+
+ # Изменение угла вращения
+ theta += 0.05
+
+ # Создание матрицы вращения
+ rotation_matrix = [
+ [math.cos(theta), -math.sin(theta), 0],
+ [math.sin(theta), math.cos(theta), 0],
+ [0, 0, 1]
+ ]
+
+ # Применение матрицы вращения к вершинам куба
+ rotated_vertices = []
+ for vertex in vertices:
+ rotated_vertex = [0, 0, 0]
+ for i in range(3):
+ for j in range(3):
+ rotated_vertex[i] += rotation_matrix[i][j] * vertex[j]
+ rotated_vertices.append(rotated_vertex)
+
+ # Проекция вершин на экран
+ projected_vertices = []
+ for vertex in rotated_vertices:
+ x = int(vertex[0] * 10 / vertex[2] + 50)
+ y = int(vertex[1] * 10 / vertex[2] + 25)
+ projected_vertices.append([x, y])
+
+ # Отрисовка ребер куба
+ for edge in edges:
+ start = projected_vertices[edge[0]]
+ end = projected_vertices[edge[1]]
+ print(f"\033[{start[1]};{start[0]}H+", end="")
+ print(f"\033[{end[1]};{end[0]}H+")
+
+ # Ожидание
+ time.sleep(0.05)