From 3c0a3b8413ee58a3e5678075c862e95f7c8395c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=95=D0=B3=D0=BE=D1=80=20=D0=9B=D1=8C=D0=B2=D0=BE=D0=B2?= Date: Mon, 27 Mar 2023 11:25:27 +0300 Subject: =?UTF-8?q?=D0=9D=D0=B0=D1=87=D0=B0=D0=BB=D1=8C=D0=BD=D1=8B=D0=B9?= =?UTF-8?q?=20=D0=BA=D0=BE=D0=BC=D0=BC=D0=B8=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cube.py | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 cube.py (limited to 'cube.py') 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) -- cgit v1.2.3