2024-06-25 02:37:57 +00:00
|
|
|
<!DOCTYPE html>
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<style>
|
|
|
|
body {
|
|
|
|
background-color: #ffe0f0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* needed to keep Ganja canvas from blowing up */
|
|
|
|
canvas {
|
|
|
|
min-width: 600px;
|
|
|
|
max-width: 600px;
|
|
|
|
min-height: 600px;
|
|
|
|
max-height: 600px;
|
|
|
|
}
|
|
|
|
</style>
|
|
|
|
<script src="https://unpkg.com/ganja.js"></script>
|
|
|
|
</head>
|
|
|
|
<body>
|
2024-06-25 20:40:40 +00:00
|
|
|
<p><button onclick="flip()">Flip</button></p>
|
2024-06-25 02:37:57 +00:00
|
|
|
<script>
|
2024-06-25 08:54:01 +00:00
|
|
|
// in the default view, e4 + e5 is the point at infinity
|
2024-06-25 09:07:39 +00:00
|
|
|
let CGA3 = Algebra(4, 1);
|
2024-06-26 00:57:16 +00:00
|
|
|
let elements = [
|
2024-06-25 20:40:40 +00:00
|
|
|
CGA3.inline(() => Math.sqrt(0.5)*( 1e1 + 1e2 + 1e3 + 1e5))(),
|
|
|
|
CGA3.inline(() => Math.sqrt(0.5)*( 1e1 - 1e2 - 1e3 + 1e5))(),
|
|
|
|
CGA3.inline(() => Math.sqrt(0.5)*(-1e1 + 1e2 - 1e3 + 1e5))(),
|
|
|
|
CGA3.inline(() => Math.sqrt(0.5)*(-1e1 - 1e2 + 1e3 + 1e5))(),
|
|
|
|
CGA3.inline(() => -Math.sqrt(3)*1e4 + Math.sqrt(2)*1e5)()
|
2024-06-25 10:11:50 +00:00
|
|
|
];
|
2024-06-26 00:57:16 +00:00
|
|
|
|
|
|
|
// set up palette
|
|
|
|
var colorIndex;
|
|
|
|
var palette = [0xff00b0, 0x00ffb0, 0x00b0ff, 0x8040ff, 0xc0c0c0];
|
|
|
|
function nextColor() {
|
|
|
|
colorIndex = (colorIndex + 1) % palette.length;
|
|
|
|
return palette[colorIndex];
|
|
|
|
}
|
|
|
|
function resetColorCycle() {
|
|
|
|
colorIndex = palette.length - 1;
|
|
|
|
}
|
|
|
|
resetColorCycle();
|
|
|
|
|
2024-06-25 10:11:50 +00:00
|
|
|
// create scene function
|
2024-06-26 00:57:16 +00:00
|
|
|
function scene() {
|
|
|
|
commands = [];
|
|
|
|
resetColorCycle();
|
|
|
|
elements.forEach((elt) => commands.push(nextColor(), elt));
|
|
|
|
return commands;
|
|
|
|
}
|
2024-06-25 10:11:50 +00:00
|
|
|
|
|
|
|
// initialize graph
|
2024-06-26 00:57:16 +00:00
|
|
|
let graph = CGA3.graph(
|
2024-06-25 10:11:50 +00:00
|
|
|
scene,
|
2024-06-25 08:54:01 +00:00
|
|
|
{
|
|
|
|
conformal: true, gl: true, grid: true
|
|
|
|
}
|
2024-06-25 10:11:50 +00:00
|
|
|
)
|
2024-06-26 00:57:16 +00:00
|
|
|
document.body.appendChild(graph);
|
2024-06-25 10:11:50 +00:00
|
|
|
|
2024-06-25 20:40:40 +00:00
|
|
|
function flip() {
|
2024-06-26 00:57:16 +00:00
|
|
|
let last = elements.length - 1;
|
|
|
|
for (let n = 0; n < last; ++n) {
|
2024-06-25 20:40:40 +00:00
|
|
|
// reflect
|
2024-06-26 00:57:16 +00:00
|
|
|
elements[n] = CGA3.Mul(CGA3.Mul(elements[last], elements[n]), elements[last]);
|
2024-06-25 20:40:40 +00:00
|
|
|
|
|
|
|
// de-noise
|
2024-06-26 00:57:16 +00:00
|
|
|
for (let k = 6; k < elements[n].length; ++k) {
|
|
|
|
elements[n][k] = 0;
|
2024-06-25 20:40:40 +00:00
|
|
|
}
|
|
|
|
}
|
2024-06-26 00:57:16 +00:00
|
|
|
requestAnimationFrame(graph.update.bind(graph, scene));
|
2024-06-25 10:11:50 +00:00
|
|
|
}
|
2024-06-25 02:37:57 +00:00
|
|
|
</script>
|
|
|
|
</body>
|
|
|
|
</html>
|