Jello
by Chantal Roth
HTML
<div id="container"></div>
<script async src="https://unpkg.com/es-module-shims@1.6.3/dist/es-module-shims.js"></script>
<script type="importmap">
{
"imports": {
"three": "https://unpkg.com/three@0.150.1/build/three.module.js",
"three/addons/": "https://unpkg.com/three@0.150.1/examples/jsm/"
}
}
</script>
CSS
body {
margin: 0;
overflow: hidden;
background-color: #000;
}
#container {
width: 100%;
height: 100vh;
}
JavaScript
import * as THREE from 'three';
import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
import { GUI } from 'three/addons/libs/lil-gui.module.min.js';
let container, camera, scene, renderer, controls;
let jelloMesh, gridMesh, probeMesh;
let jelloOriginalPos, gridOriginalPos;
let clock = new THREE.Clock();
// Matrix DOM elements
let matrixDiv, matrixContainer, matrixTitle;
let matrixCells = [];
// Simulation Parameters
const params = {
color: 0x00aaff,
opacity: 0.9,
shininess: 90,
// Visual Toggles
showGrid: false,
showMetric: true,
tensorMode: '3D Spatial', // Options: '3D Spatial', '4D Spacetime'
// Probe Position (Where we measure)
probeX: 0.5,
probeY: 0.5,
probeZ: 0.5,
// Static Deformations (Relativity)
stretchX: 1.0, stretchY: 1.0, stretchZ: 1.0,
bendX: 0.0, bendY: 0.0, bendZ: 0.0,
twist: 0.0,
// Dynamic Jiggles
waveEnabled: false, waveSpeed: 2.0, waveFrequency: 2.0, waveAmplitude: 0.1,
pulseEnabled: false, pulseSpeed: 3.0, pulseFrequency: 1.5, pulseAmplitude: 0.05,
wobbleEnabled: false, wobbleSpeed: 4.0, wobbleAmplitude: 0.2,
twistWaveEnabled: false, twistWaveSpeed: 3.0, twistWaveFreq: 3.0, twistWaveAmp: 0.5,
};
init();
animate();
function init() {
injectCSS();
createMatrixUI();
rebuildMatrixGrid();
container = document.getElementById('container');
// Scene Setup
scene = new THREE.Scene();
scene.background = new THREE.Color(0x050505);
camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 0.1, 100);
camera.position.set(5, 4, 6);
renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(window.devicePixelRatio);
renderer.setSize(window.innerWidth, window.innerHeight);
container.appendChild(renderer.domElement);
controls = new OrbitControls(camera, renderer.domElement);
...