dyna3/engine-proto/ganja-test/ganja-test.html
Aaron Fenyes 06a9dda5bb Play with reflections
Try configuration of five tangent spheres.
2024-06-25 13:40:40 -07:00

65 lines
1.4 KiB
HTML

<!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>
<p><button onclick="flip()">Flip</button></p>
<script>
// in the default view, e4 + e5 is the point at infinity
let CGA3 = Algebra(4, 1);
let v = [
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)()
];
// create scene function
let scene = () => [
0xff00b0, v[0],
0x00ffb0, v[1],
0x00b0ff, v[2],
0x8040ff, v[3],
0xc0c0c0, v[4]
];
// initialize graph
let gr = CGA3.graph(
scene,
{
conformal: true, gl: true, grid: true
}
)
document.body.appendChild(gr);
function flip() {
for (let n = 0; n < 4; ++n) {
// reflect
v[n] = CGA3.Mul(CGA3.Mul(v[4], v[n]), v[4]);
// de-noise
for (let k = 6; k < v[n].length; ++k) {
v[n][k] = 0;
}
}
requestAnimationFrame(gr.update.bind(gr, scene));
}
</script>
</body>
</html>