сделай 4d визуализацию
- User
сделай 4d визуализацию
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
сделай 4d визуализацию
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Вот пример визуализации 4D гиперкуба (тессеракта) с использованием HTML5 Canvas и JavaScript. Это проекция 4D-объекта в 3D, а затем в 2D для отображения на экране. Код включает интерактивное вращение с помощью мыши.
tesseract.html.<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8">
<title>4D Тессеракт - Визуализация</title>
<style>
body {
margin: 0;
overflow: hidden;
background-color: #000;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
canvas {
background-color: #111;
display: block;
}
#info {
position: absolute;
top: 10px;
left: 10px;
color: #fff;
font-family: sans-serif;
font-size: 14px;
background: rgba(0, 0, 0, 0.6);
padding: 8px 12px;
border-radius: 5px;
}
</style>
</head>
<body>
<canvas id="canvas"></canvas>
<div id="info">Перемещайте мышь, чтобы вращать тессеракт</div>
<script>
const canvas = document.getElementById("canvas");
const ctx = canvas.getContext("2d");
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
let mouse = { x: 0, y: 0 };
let angleX = 0, angleY = 0, angleZ = 0, angleW = 0;
// Генерация вершин тессеракта (16 точек в 4D)
const vertices = [];
for (let i = 0; i < 16; i++) {
const x = (i & 1) ? 1 : -1;
const y = (i & 2) ? 1 : -1;
const z = (i & 4) ? 1 : -1;
const w = (i & 8) ? 1 : -1;
vertices.push({ x, y, z, w });
}
// Ребра тессеракта (соединения между вершинами)
const edges = [];
for (let i = 0; i < 16; i++) {
for (let j = i + 1; j < 16; j++) {
let diff = 0;
if ((i ^ j) & 1) diff++;
if ((i ^ j) & 2) diff++;
if ((i ^ j) & 4) diff++;
if ((i ^ j) & 8) diff++;
if (diff === 1) edges.push([i, j]);
}
}
// Обработчик мыши для вращения
canvas.addEventListener("mousemove", (e) => {
angleX += (e.clientY - mouse.y) * 0.001;
angleY += (e.clientX - mouse.x) * 0.001;
mouse.x = e.clientX;
mouse.y = e.clientY;
});
mouse.x = canvas.width / 2;
mouse.y = canvas.height / 2;
function rotate4D(point, a, b, angle) {
const sin = Math.sin(angle);
const cos = Math.cos(angle);
const result = { ...point };
if (a === 'x' && b === 'y') {
result.x = point.x * cos - point.y * sin;
result.y = point.x * sin + point.y * cos;
} else if (a === 'x' && b === 'z') {
result.x = point.x * cos - point.z * sin;
result.z = point.x * sin + point.z * cos;
} else if (a === 'x' && b === 'w') {
result.x = point.x * cos - point.w * sin;
result.w = point.x * sin + point.w * cos;
} else if (a === 'y' && b === 'z') {
result.y = point.y * cos - point.z * sin;
result.z = point.y * sin + point.z * cos;
} else if (a === 'y' && b === 'w') {
result.y = point.y * cos - point.w * sin;
result.w = point.y * sin + point.w * cos;
} else if (a === 'z' && b === 'w') {
result.z = point.z * cos - point.w * sin;
result.w = point.z * sin + point.w * cos;
}
return result;
}
function project4Dto3D(point4D, scale = 200, offset = 0.5) {
// Проецируем 4D -> 3D (простая ортографическая проекция)
const distance = 5;
const w = point4D.w + distance;
const scale4D = 1 / (1 + w * 0.2);
const x = point4D.x * scale4D;
const y = point4D.y * scale4D;
const z = point4D.z * scale4D;
return { x, y, z };
}
function project3Dto2D(point3D) {
// Проецируем 3D -> 2D (с перспективой)
const scale = 300;
const focalLength = 500;
const x = (point3D.x * focalLength) / (focalLength + point3D.z) * scale + canvas.width / 2;
const y = (point3D.y * focalLength) / (focalLength + point3D.z) * scale + canvas.height / 2;
return { x, y };
}
function drawTesseract() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
// Вращение в 4D
const rotated = vertices.map(v => {
let p = { ...v };
p = rotate4D(p, 'x', 'y', angleX);
p = rotate4D(p, 'x', 'z', angleY);
p = rotate4D(p, 'x', 'w', angleZ);
p = rotate4D(p, 'y', 'z', angleW);
return p;
});
// Проекция в 3D и затем в 2D
const projected = rotated.map(v => {
const p3D = project4Dto3D(v);
return project3Dto2D(p3D);
});
// Рисуем ребра
ctx.strokeStyle = "#00ffff";
ctx.lineWidth = 1;
edges.forEach(([i, j]) => {
const p1 = projected[i];
const p2 = projected[j];
if (p1 && p2) {
ctx.beginPath();
ctx.moveTo(p1.x, p1.y);
ctx.lineTo(p2.x, p2.y);
ctx.stroke();
}
});
// Рисуем вершины
ctx.fillStyle = "#ff00ff";
projected.forEach(p => {
ctx.beginPath();
ctx.arc(p.x, p.y, 3, 0, Math.PI * 2);
ctx.fill();
});
angleX += 0.01;
angleY += 0.005;
angleZ += 0.003;
angleW += 0.002;
}
function animate() {
drawTesseract();
requestAnimationFrame(animate);
}
animate();
window.addEventListener("resize", () => {
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
});
</script>
</body>
</html>
Генерация вершин тессеракта:
x, y, z, w).Соединение ребер:
Вращение в 4D:
rotate4D вращает точку вокруг выбранной плоскости (например, x-y, x-z, x-w, y-z, y-w, z-w).Проекция на 3D и 2D:
w).Отрисовка:
Интерактивность:
Если хотите, я могу добавить дополнительные функции! 🚀