Prompt specification
Build or customize the Three.js 3D scene "Two cell types sharing a sequence" inside the active workspace.
Engineering Constraints:
1. Runtime & Orbit: Use Three.js r160 with OrbitControls (damping enabled) and ACESFilmicToneMapping.
2. Frame Timing: Drive all motion strictly with clock.getDelta() so animation speed is FPS-independent.
3. Viewport Hygiene: Handle window resize cleanly, cap DPR at Math.min(window.devicePixelRatio, 2), and dispose geometries/materials/renderer on unmount.
Scene Metadata:
Scene: Two cell types sharing a sequence
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/two-cell-types-sharing-a-sequence-x0906
Scene Description Prompt:
Two stylized cell types share identical DNA but activate different genes and produce different outputs. Three.js from cdnjs, one HTML file.
Working Three.js Starter (two-cell-types-sharing-a-sequence-x0906):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Same DNA. Different Cells.</title>
<style>
:root {
--cyan: #56e5e7;
--cyan-soft: rgba(86, 229, 231, 0.14);
--orange: #ff8b62;
--orange-soft: rgba(255, 139, 98, 0.14);
--violet: #a99af5;
--text: #edf6f6;
--muted: #91a6ad;
--panel: rgba(9, 22, 29, 0.78);
--line: rgba(166, 210, 216, 0.16);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 50% 46%, #10242d 0%, #09151c 42%, #050c11 100%);
color: var(--text);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
body::before {
content: "";
position: fixed;
inset: 0;
pointer-events: none;
background:
linear-gradient(rgba(255,255,255,0.015) 1px, transparent 1px),
linear-gradient(90deg, rgba(255,255,255,0.015) 1px, transparent 1px);
background-size: 44px 44px;
mask-image: radial-gradient(circle at center, black, transparent 78%);
opacity: 0.45;
z-index: 0;
}
canvas {
position: fixed;
inset: 0;
display: block;
z-index: 1;
touch-action: none;
}
.ui {
position: fixed;
inset: 0;
z-index: 2;
pointer-events: none;
}
header {
position: absolute;
top: 30px;
left: 34px;
width: min(470px, calc(100vw - 68px));
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 12px;
color: var(--cyan);
font-size: 11px;
font-weight: 700;
letter-spacing: 0.19em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 24px;
height: 1px;
background: currentColor;
box-shadow: 0 0 10px currentColor;
}
h1 {
margin: 0;
font-size: clamp(34px, 4vw, 58px);
line-height: 0.98;
letter-spacing: -0.055em;
font-weight: 620;
}
h1 span {
color: #849ba4;
}
header p {
max-width: 430px;
margin: 17px 0 0;
color: var(--muted);
font-size: 14px;
line-height: 1.6;
}
.genome-badge {
position: absolute;
top: 30px;
right: 32px;
display: flex;
align-items: center;
gap: 16px;
padding: 12px 14px 12px 16px;
border: 1px solid var(--line);
border-radius: 14px;
background: rgba(8, 19, 25, 0.65);
backdrop-filter: blur(16px);
-webkit-backdrop-filter: blur(16px);
pointer-events: auto;
}
.genome-badge .copy {
display: grid;
gap: 3px;
}
.genome-badge strong {
font-size: 10px;
letter-spacing: 0.14em;
text-transform: uppercase;
color: #dbe9ec;
}
.genome-badge small {
font-size: 11px;
color: var(--muted);
}
.identity-bars {
display: flex;
align-items: flex-end;
gap: 3px;
height: 23px;
}
.identity-bars i {
display: block;
width: 3px;
border-radius: 3px;
background: var(--violet);
box-shadow: 0 0 7px rgba(169, 154, 245, 0.55);
}
.identity-bars i:nth-child(1) { height: 9px; }
.identity-bars i:nth-child(2) { height: 18px; }
.identity-bars i:nth-child(3) { height: 13px; }
.identity-bars i:nth-child(4) { height: 21px; }
.identity-bars i:nth-child(5) { height: 15px; }
.identity-bars i:nth-child(6) { height: 19px; }
.identity-bars i:nth-child(7) { height: 11px; }
.reset {
position: absolute;
top: 100px;
right: 32px;
padding: 8px 12px;
border: 1px solid var(--line);
border-radius: 9px;
background: rgba(8, 19, 25, 0.55);
color: #b4c6ca;
font: inherit;
font-size: 11px;
cursor: pointer;
pointer-events: auto;
transition: 160ms ease;
}
.reset:hover {
color: white;
border-color: rgba(86, 229, 231, 0.45);
background: rgba(86, 229, 231, 0.08);
}
.scene-label,
.output-label {
position: absolute;
left: 0;
top: 0;
opacity: 0;
transform: translate(-50%, -50%);
white-space: nowrap;
will-change: left, top, opacity;
}
.scene-label {
display: flex;
align-items: center;
gap: 8px;
padding: 8px 11px;
border: 1px solid var(--line);
border-radius: 999px;
background: rgba(5, 15, 20, 0.72);
backdrop-filter: blur(10px);
-webkit-backdrop-filter: blur(10px);
color: #f1f8f9;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.16em;
text-transform: uppercase;
box-shadow: 0 8px 30px rgba(0,0,0,0.2);
}
.scene-label .dot {
width: 6px;
height: 6px;
border-radius: 50%;
background: currentColor;
box-shadow: 0 0 10px currentColor;
}
.scene-label small {
padding-left: 7px;
border-left: 1px solid var(--line);
color: var(--muted);
font-size: 9px;
font-weight: 500;
letter-spacing: 0.06em;
}
.scene-label.neuron {
color: var(--cyan);
}
.scene-label.beta {
color: var(--orange);
}
.output-label {
padding: 7px 10px;
border-radius: 8px;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.17em;
text-transform: uppercase;
backdrop-filter: blur(10px);
-webkit-backdrop-filter: blur(10px);
}
.output-label.neuron {
color: var(--cyan);
border: 1px solid rgba(86, 229, 231, 0.28);
background: rgba(24, 84, 88, 0.48);
}
.output-label.beta {
color: var(--orange);
border: 1px solid rgba(255, 139, 98, 0.28);
background: rgba(99, 49, 35, 0.48);
}
.info-grid {
position: absolute;
left: 50%;
bottom: 25px;
display: grid;
grid-template-columns: minmax(230px, 1fr) minmax(240px, 0.9fr) minmax(230px, 1fr);
gap: 13px;
width: min(1160px, calc(100vw - 48px));
transform: translateX(-50%);
pointer-events: auto;
}
.cell-card,
.genome-card {
min-height: 146px;
border: 1px solid var(--line);
border-radius: 18px;
background: var(--panel);
backdrop-filter: blur(18px);
-webkit-backdrop-filter: blur(18px);
box-shadow: 0 18px 55px rgba(0, 0, 0, 0.28);
}
.cell-card {
position: relative;
width: 100%;
padding: 18px 19px 16px;
overflow: hidden;
color: inherit;
text-align: left;
font: inherit;
cursor: pointer;
transition:
transform 180ms ease,
border-color 180ms ease,
background 180ms ease;
}
.cell-card::before {
content: "";
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 2px;
background: currentColor;
box-shadow: 0 0 18px currentColor;
opacity: 0.75;
}
.cell-card.neuron {
color: var(--cyan);
}
.cell-card.beta {
color: var(--orange);
}
.cell-card:hover,
.cell-card.selected {
transform: translateY(-4px);
background: rgba(13, 31, 39, 0.9);
}
.cell-card.neuron:hover,
.cell-card.neuron.selected {
border-color: rgba(86, 229, 231, 0.48);
box-shadow: 0 20px 60px rgba(20, 102, 108, 0.18);
}
.cell-card.beta:hover,
.cell-card.beta.selected {
border-color: rgba(255, 139, 98, 0.48);
box-shadow: 0 20px 60px rgba(123, 55, 32, 0.18);
}
.card-kicker {
display: flex;
align-items: center;
justify-content: space-between;
color: currentColor;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.17em;
text-transform: uppercase;
}
.card-kicker .index {
color: var(--muted);
}
.cell-card h2 {
margin: 9px 0 3px;
color: #eff8f8;
font-size: 21px;
letter-spacing: -0.035em;
font-weight: 620;
}
.cell-card .role {
color: var(--muted);
font-size: 11px;
}
.genes {
display: flex;
flex-wrap: wrap;
gap: 5px;
margin-top: 13px;
}
.gene {
padding: 4px 7px;
border: 1px solid currentColor;
border-radius: 5px;
color: currentColor;
background: rgba(255,255,255,0.025);
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 9px;
letter-spacing: 0.04em;
opacity: 0.9;
}
.output {
display: flex;
align-items: center;
gap: 8px;
margin-top: 12px;
color: #a8bcc1;
font-size: 9px;
letter-spacing: 0.11em;
text-transform: uppercase;
}
.output::before {
content: "";
width: 20px;
height: 1px;
background: currentColor;
}
.genome-card {
display: flex;
flex-direction: column;
justify-content: center;
padding: 18px 21px;
background:
radial-gradient(circle at 50% 120%, rgba(169,154,245,0.14), transparent 58%),
var(--panel);
}
.genome-title {
display: flex;
align-items: center;
gap: 10px;
color: var(--violet);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.dna-mark {
position: relative;
width: 15px;
height: 24px;
}
.dna-mark::before,
.dna-mark::after {
content: "";
position: absolute;
top: 2px;
width: 5px;
height: 20px;
border: 1px solid var(--violet);
border-radius: 50%;
transform: rotate(18deg);
}
.dna-mark::before { left: 1px; }
.dna-mark::after { right: 1px; }
.match {
margin: 9px 0 4px;
color: #f1f7f8;
font-size: 29px;
font-weight: 650;
letter-spacing: -0.05em;
}
.match span {
color: var(--violet);
font-size: 12px;
font-weight: 600;
letter-spacing: 0;
vertical-align: middle;
}
.genome-card p {
margin: 0;
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
.sequence {
display: flex;
gap: 3px;
height: 13px;
margin-top: 12px;
overflow: hidden;
}
.sequence i {
flex: 1;
border-radius: 2px;
background: var(--violet);
opacity: 0.68;
}
.sequence i:nth-child(3n) { opacity: 0.25; }
.sequence i:nth-child(5n) { background: #d0c9ff; }
.help {
position: absolute;
left: 34px;
bottom: 188px;
display: flex;
align-items: center;
gap: 9px;
color: rgba(169, 190, 196, 0.55);
font-size: 9px;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.help svg {
opacity: 0.7;
}
@media (max-width: 850px) {
header {
top: 20px;
left: 20px;
}
header p {
max-width: 330px;
font-size: 12px;
}
.genome-badge {
top: 20px;
right: 18px;
padding: 9px;
}
.genome-badge .copy {
display: none;
}
.reset {
top: 80px;
right: 18px;
}
.info-grid {
grid-template-columns: 1fr 1fr;
bottom: 14px;
width: calc(100vw - 24px);
gap: 9px;
}
.genome-card {
grid-column: 1 / -1;
grid-row: 1;
min-height: 92px;
padding: 13px 17px;
}
.match {
margin-top: 5px;
font-size: 23px;
}
.sequence {
margin-top: 8px;
}
.cell-card {
min-height: 142px;
padding: 15px;
}
.help {
display: none;
}
}
@media (max-width: 560px) {
h1 {
font-size: 31px;
}
header p {
display: none;
}
.scene-label small {
display: none;
}
.cell-card h2 {
font-size: 17px;
}
.role {
display: none;
}
.cell-card {
min-height: 124px;
}
.output {
font-size: 8px;
}
}
</style>
</head>
<body>
<div class="ui">
<header>
<div class="eyebrow">Cell identity lab / 01</div>
<h1>Same DNA.<br /><span>Different cells.</span></h1>
<p>
A neuron's action potential and a pancreatic β-cell's insulin release
begin with identical DNA. Different genes switch on, producing different
structures, behaviors, and outputs.
</p>
</header>
<div class="genome-badge" aria-label="Identical DNA">
<div class="identity-bars" aria-hidden="true">
<i></i><i></i><i></i><i></i><i></i><i></i><i></i>
</div>
<div class="copy">
<strong>Identical DNA</strong>
<small>100% sequence match</small>
</div>
</div>
<button class="reset" id="resetView" type="button">Reset view</button>
<div class="scene-label neuron" id="neuronLabel">
<span class="dot"></span>
Neuron
<small>electrical output</small>
</div>
<div class="scene-label beta" id="betaLabel">
<span class="dot"></span>
Pancreatic β-cell
<small>hormonal output</small>
</div>
<div class="output-label neuron" id="neuronOutput">Action potential</div>
<div class="output-label beta" id="betaOutput">Insulin release</div>
<div class="help">
<svg width="17" height="17" viewBox="0 0 24 24" fill="none" aria-hidden="true">
<path d="M8 7V4.8a1.8 1.8 0 0 1 3.6 0V11m0-3.2a1.8 1.8 0 0 1 3.6 0V11m0-2a1.8 1.8 0 0 1 3.6 0v4.4c0 4-2.5 6.6-6.2 6.6H11c-2.1 0-3.5-.9-4.7-2.5l-2.5-3.4a1.7 1.7 0 0 1 2.7-2.1L8 15.4V7Z" stroke="currentColor" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round"/>
</svg>
Drag to orbit · Scroll or pinch to zoom · Select a cell
</div>
<section class="info-grid" aria-label="Cell expression comparison">
<button class="cell-card neuron selected" data-cell="0" type="button">
<div class="card-kicker">
<span>Cell A</span>
<span class="index">01 / excitable</span>
</div>
<h2>Neuron</h2>
<div class="role">Specialized for rapid electrical communication</div>
<div class="genes">
<span class="gene">SNAP25</span>
<span class="gene">CACNA1A</span>
<span class="gene">SCN1A</span>
</div>
<div class="output">Output / Action potential</div>
</button>
<article class="genome-card">
<div class="genome-title">
<span class="dna-mark" aria-hidden="true"></span>
Shared human genome
</div>
<div class="match">3.2 billion <span>base pairs</span></div>
<p>Different chromatin states activate different gene sets.</p>
<div class="sequence" aria-hidden="true">
<i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i>
<i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i>
<i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i>
</div>
</article>
<button class="cell-card beta" data-cell="1" type="button">
<div class="card-kicker">
<span>Cell B</span>
<span class="index">02 / secretory</span>
</div>
<h2>Pancreatic β-cell</h2>
<div class="role">Specialized for storage and hormone secretion</div>
<div class="genes">
<span class="gene">INS</span>
<span class="gene">CHGA</span>
<span class="gene">IAPP</span>
</div>
<div class="output">Output / Secreted insulin</div>
</button>
</section>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const scene = new THREE.Scene();
scene.fog = new THREE.FogExp2(0x071219, 0.025);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
document.body.prepend(renderer.domElement);
const cyan = 0x56e5e7;
const orange = 0xff8b62;
const violet = 0xa99af5;
const clock = new THREE.Clock();
// Lighting
scene.add(new THREE.HemisphereLight(0xb8d9ff, 0x071016, 1.35));
const key = new THREE.DirectionalLight(0xffffff, 2.4);
key.position.set(4, 8, 10);
scene.add(key);
const rim = new THREE.DirectionalLight(0x7f77ff, 1.25);
rim.position.set(-7, 3, -7);
scene.add(rim);
const cyanLight = new THREE.PointLight(cyan, 30, 8, 2);
cyanLight.position.set(-4.2, 0.5, 1.6);
scene.add(cyanLight);
const orangeLight = new THREE.PointLight(orange, 30, 8, 2);
orangeLight.position.set(4.15, 0.5, 1.6);
scene.add(orangeLight);
// Ground and technical grid
const grid = new THREE.GridHelper(34, 34, 0x31505a, 0x19313a);
grid.position.y = -2.12;
grid.material.transparent = true;
grid.material.opacity = 0.18;
scene.add(grid);
function createPlatform(x, color) {
const group = new THREE.Group();
const disc = new THREE.Mesh(
new THREE.CircleGeometry(2.7, 80),
new THREE.MeshBasicMaterial({
color: 0x07151c,
transparent: true,
opacity: 0.72,
depthWrite: false
})
);
disc.rotation.x = -Math.PI / 2;
disc.position.set(x, -2.105, 0);
group.add(disc);
for (let i = 0; i < 3; i++) {
const ring = new THREE.Mesh(
new THREE.RingGeometry(2.08 + i * 0.27, 2.095 + i * 0.27, 96),
new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.24 - i * 0.055,
side: THREE.DoubleSide,
depthWrite: false
})
);
ring.rotation.x = -Math.PI / 2;
ring.position.set(x, -2.09 + i * 0.002, 0);
group.add(ring);
}
scene.add(group);
}
createPlatform(-4.2, cyan);
createPlatform(4.15, orange);
// Helpers
function cylinderBetween(a, b, radius, material, radialSegments = 8) {
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, length, radialSegments),
material
);
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
return mesh;
}
function tubeFrom(points, radius, material, segments = 32) {
const curve = new THREE.CatmullRomCurve3(
points.map(p => new THREE.Vector3(...p))
);
const mesh = new THREE.Mesh(
new THREE.TubeGeometry(curve, segments, radius, 10, false),
material
);
mesh.userData.curve = curve;
return mesh;
}
function organicGeometry(radius) {
const geometry = new THREE.SphereGeometry(1, 64, 48);
const positions = geometry.attributes.position;
for (let i = 0; i < positions.count; i++) {
const x = positions.getX(i);
const y = positions.getY(i);
const z = positions.getZ(i);
const factor =
1 +
0.045 * Math.sin(x * 5.2 + y * 2.8) * Math.cos(z * 4.1 - y * 3.3) +
0.025 * Math.sin(z * 7.1 + x * 4.4);
positions.setXYZ(i, x * factor, y * factor, z * factor);
}
geometry.computeVertexNormals();
geometry.scale(radius, radius, radius);
return geometry;
}
function createMembrane(color) {
const group = new THREE.Group();
const geometry = organicGeometry(2.02);
const shell = new THREE.Mesh(
geometry,
new THREE.MeshPhysicalMaterial({
color,
emissive: color,
emissiveIntensity: 0.08,
transparent: true,
opacity: 0.135,
roughness: 0.24,
metalness: 0.04,
side: THREE.DoubleSide,
depthWrite: false
})
);
const wire = new THREE.Mesh(
geometry,
new THREE.MeshBasicMaterial({
color,
wireframe: true,
transparent: true,
opacity: 0.035,
depthWrite: false
})
);
group.add(shell, wire);
return group;
}
function createNucleus() {
const group = new THREE.Group();
const nucleus = new THREE.Mesh(
new THREE.SphereGeometry(0.92, 36, 28),
new THREE.MeshPhysicalMaterial({
color: 0x6050a3,
emissive: 0x251b52,
emissiveIntensity: 0.3,
transparent: true,
opacity: 0.18,
roughness: 0.4,
side: THREE.DoubleSide,
depthWrite: false
})
);
const nucleusWire = new THREE.Mesh(
new THREE.SphereGeometry(0.93, 18, 12),
new THREE.MeshBasicMaterial({
color: violet,
wireframe: true,
transparent: true,
opacity: 0.095,
depthWrite: false
})
);
group.add(nucleus, nucleusWire);
return group;
}
function createDNA(accent, activeIndices) {
const group = new THREE.Group();
const strandMaterial = new THREE.MeshStandardMaterial({
color: 0x978be0,
emissive: 0x30245f,
emissiveIntensity: 0.8,
roughness: 0.32,
metalness: 0.08
});
const rungMaterial = new THREE.MeshStandardMaterial({
color: 0x506273,
emissive: 0x172330,
emissiveIntensity: 0.35,
roughness: 0.45
});
const activeRungMaterial = new THREE.MeshStandardMaterial({
color: accent,
emissive: accent,
emissiveIntensity: 1.35,
roughness: 0.28
});
const pointsA = [];
const pointsB = [];
const count = 64;
for (let i = 0; i <= count; i++) {
const t = i / count;
const angle = t * Math.PI * 4.2;
const radius = 0.22;
const y = (t - 0.5) * 1.42;
pointsA.push(new THREE.Vector3(
Math.cos(angle) * radius,
y,
Math.sin(angle) * radius
));
pointsB.push(new THREE.Vector3(
-Math.cos(angle) * radius,
y,
-Math.sin(angle) * radius
));
}
const curveA = new THREE.CatmullRomCurve3(pointsA);
const curveB = new THREE.CatmullRomCurve3(pointsB);
group.add(new THREE.Mesh(
new THREE.TubeGeometry(curveA, 120, 0.027, 8, false),
strandMaterial
));
group.add(new THREE.Mesh(
new THREE.TubeGeometry(curveB, 120, 0.027, 8, false),
strandMaterial
));
const markers = [];
for (let i = 3; i < count - 2; i += 4) {
const isActive = activeIndices.includes(i);
const a = pointsA[i];
const b = pointsB[i];
group.add(cylinderBetween(
a,
b,
isActive ? 0.021 : 0.014,
isActive ? activeRungMaterial : rungMaterial
));
const markerMaterial = new THREE.MeshStandardMaterial({
color: isActive ? accent : 0x655b83,
emissive: isActive ? accent : 0x211b36,
emissiveIntensity: isActive ? 2.1 : 0.25,
roughness: 0.25
});
const marker = new THREE.Mesh(
new THREE.SphereGeometry(isActive ? 0.075 : 0.038, 14, 10),
markerMaterial
);
marker.position.copy(a);
group.add(marker);
if (isActive) markers.push(marker);
}
group.rotation.z = -0.12;
return { group, markers };
}
function createMitochondrion(color, opacity = 0.4) {
const group = new THREE.Group();
const body = new THREE.Mesh(
new THREE.SphereGeometry(0.32, 20, 14),
new THREE.MeshStandardMaterial({
color,
emissive: color,
emissiveIntensity: 0.12,
transparent: true,
opacity,
roughness: 0.55
})
);
body.scale.set(1.7, 0.55, 0.72);
group.add(body);
for (let i = 0; i < 4; i++) {
const crease = new THREE.Mesh(
new THREE.TorusGeometry(0.13, 0.013, 6, 20, Math.PI),
new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: opacity * 0.9
})
);
crease.rotation.y = Math.PI / 2;
crease.position.x = -0.25 + i * 0.16;
group.add(crease);
}
return group;
}
// Neuron
const neuron = new THREE.Group();
neuron.position.set(-4.2, 0.35, 0);
neuron.userData.cellIndex = 0;
scene.add(neuron);
const neuronMembrane = createMembrane(cyan);
neuron.add(neuronMembrane);
const neuronNucleus = createNucleus();
neuron.add(neuronNucleus);
const neuronDNA = createDNA(cyan, [7, 19, 35, 51]);
neuronDNA.group.position.y = 0.05;
neuron.add(neuronDNA.group);
const neuronBranchMaterial = new THREE.MeshPhysicalMaterial({
color: cyan,
emissive: cyan,
emissiveIntensity: 0.22,
transparent: true,
opacity: 0.58,
roughness: 0.36,
depthWrite: false
});
const dendrites = [
tubeFrom([
[-0.8, 1.25, 0.35],
[-1.35, 1.7, 0.25],
[-1.75, 2.15, 0.05],
[-2.05, 2.25, -0.08]
], 0.075, neuronBranchMaterial),
tubeFrom([
[0.15, 1.6, 0.7],
[0.05, 2.05, 0.7],
[-0.25, 2.35, 0.55]
], 0.065, neuronBranchMaterial),
tubeFrom([
[-0.25, 1.45, -1.1],
[-0.65, 1.95, -1.35],
[-0.95, 2.2, -1.55]
], 0.065, neuronBranchMaterial)
];
dendrites.forEach(branch => neuron.add(branch));
const axon = tubeFrom([
[1.25, -0.25, 0.1],
[2.2, -0.5, 0.25],
[3.15, -0.38, 0.1],
[4.05, -0.82, 0.15]
], 0.105, neuronBranchMaterial, 48);
neuron.add(axon);
const terminalPosition = axon.userData.curve.getPoint(1);
const terminal = new THREE.Mesh(
new THREE.SphereGeometry(0.2, 18, 12),
new THREE.MeshStandardMaterial({
color: cyan,
emissive: cyan,
emissiveIntensity: 1.2,
roughness: 0.3
})
);
terminal.position.copy(terminalPosition);
neuron.add(terminal);
const pulse = new THREE.Mesh(
new THREE.SphereGeometry(0.105, 18, 12),
new THREE.MeshBasicMaterial({ color: 0xcfffff })
);
neuron.add(pulse);
const pulseHalo = new THREE.Mesh(
new THREE.TorusGeometry(0.23, 0.018, 8, 40),
new THREE.MeshBasicMaterial({
color: cyan,
transparent: true,
opacity: 0.8,
depthWrite: false
})
);
pulseHalo.position.copy(terminalPosition);
pulseHalo.rotation.y = Math.PI / 2;
neuron.add(pulseHalo);
const neuronOrganelles = [];
[
[-1.1, 0.55, 0.65, 0.5],
[0.95, 0.8, 0.6, -0.6],
[-0.8, -0.75, -0.6, 0.3],
[0.9, -0.8, 0.3, 1.2],
[-1.3, -0.1, -0.8, -0.8]
].forEach(([x, y, z, rz]) => {
const organelle = createMitochondrion(0x65c8ca, 0.34);
organelle.position.set(x, y, z);
organelle.rotation.z = rz;
neuron.add(organelle);
neuronOrganelles.push(organelle);
});
const neuronAnchor = new THREE.Object3D();
neuronAnchor.position.set(-0.25, 2.68, 0);
neuron.add(neuronAnchor);
const neuronOutputAnchor = new THREE.Object3D();
neuronOutputAnchor.position.copy(terminalPosition).add(new THREE.Vector3(0, 0.4, 0));
neuron.add(neuronOutputAnchor);
// Pancreatic beta cell
const beta = new THREE.Group();
beta.position.set(4.15, 0.35, 0);
beta.userData.cellIndex = 1;
scene.add(beta);
const betaMembrane = createMembrane(orange);
beta.add(betaMembrane);
const betaNucleus = createNucleus();
beta.add(betaNucleus);
const betaDNA = createDNA(orange, [11, 27, 43, 59]);
betaDNA.group.position.y = 0.05;
beta.add(betaDNA.group);
const betaMaterial = new THREE.MeshPhysicalMaterial({
color: orange,
emissive: orange,
emissiveIntensity: 0.2,
transparent: true,
opacity: 0.52,
roughness: 0.4,
depthWrite: false
});
// Small surface projections give the secretory cell a distinct texture.
for (let i = 0; i < 10; i++) {
const angle = (i / 10) * Math.PI * 2;
const x = Math.cos(angle) * 1.25;
const z = Math.sin(angle) * 1.25;
const y = 1.35 + Math.sin(angle * 2) * 0.15;
const projection = tubeFrom([
[x, y, z],
[x * 1.13, y + 0.32, z * 1.13],
[x * 1.18, y + 0.58, z * 1.18]
], 0.034, betaMaterial, 18);
beta.add(projection);
}
// Stylized Golgi stack
const golgi = new THREE.Group();
golgi.position.set(0, -0.78, 0.28);
golgi.rotation.z = -0.2;
for (let i = 0; i < 5; i++) {
const golgiRing = new THREE.Mesh(
new THREE.TorusGeometry(0.44 + i * 0.035, 0.043, 8, 42, Math.PI * 1.62),
new THREE.MeshStandardMaterial({
color: orange,
emissive: orange,
emissiveIntensity: 0.18,
transparent: true,
opacity: 0.55,
roughness: 0.5
})
);
golgiRing.rotation.set(Math.PI / 2, 0.12, i * 0.24);
golgiRing.position.y = i * 0.1;
golgi.add(golgiRing);
}
beta.add(golgi);
// Internal secretory vesicles
const betaVesicles = [];
for (let i = 0; i < 13; i++) {
const vesicle = new THREE.Mesh(
new THREE.SphereGeometry(0.055 + (i % 3) * 0.012, 12, 8),
new THREE.MeshStandardMaterial({
color: orange,
emissive: orange,
emissiveIntensity: 0.55,
transparent: true,
opacity: 0.78,
roughness: 0.3
})
);
const angle = i * 2.399;
const radius = 0.7 + (i % 4) * 0.22;
vesicle.userData = {
angle,
radius,
y: -0.65 + (i % 7) * 0.24,
speed: 0.12 + (i % 5) * 0.014
};
beta.add(vesicle);
betaVesicles.push(vesicle);
}
// Insulin/protein particles secreted from the beta cell
const secretedProteins = [];
const proteinGeometry = new THREE.SphereGeometry(1, 12, 8);
const proteinMaterial = new THREE.MeshStandardMaterial({
color: 0xffb18e,
emissive: orange,
emissiveIntensity: 0.95,
roughness: 0.38
});
for (let i = 0; i < 22; i++) {
const protein = new THREE.Mesh(proteinGeometry, proteinMaterial);
const angle = i * 2.399;
const radius = 0.15 + (i % 5) * 0.09;
protein.userData = {
phase: i / 22,
angle,
radius,
speed: 0.09 + (i % 6) * 0.008,
drift: 0.08 + (i % 4) * 0.025
};
beta.add(protein);
secretedProteins.push(protein);
}
const betaAnchor = new THREE.Object3D();
betaAnchor.position.set(0, 2.72, 0);
beta.add(betaAnchor);
const betaOutputAnchor = new THREE.Object3D();
betaOutputAnchor.position.set(0, 4.1, 0);
beta.add(betaOutputAnchor);
// Ambient suspended particles
const moteCount = 180;
const motePositions = new Float32Array(moteCount * 3);
for (let i = 0; i < moteCount; i++) {
motePositions[i * 3] = (Math.random() - 0.5) * 24;
motePositions[i * 3 + 1] = -2 + Math.random() * 8;
motePositions[i * 3 + 2] = (Math.random() - 0.5) * 11 - 1;
}
const moteGeometry = new THREE.BufferGeometry();
moteGeometry.setAttribute(
"position",
new THREE.BufferAttribute(motePositions, 3)
);
const motes = new THREE.Points(
moteGeometry,
new THREE.PointsMaterial({
color: 0xb9e6eb,
size: 0.025,
transparent: true,
opacity: 0.42,
depthWrite: false
})
);
scene.add(motes);
// Custom camera controls
const cameraState = {
theta: 0.02,
phi: 1.34,
radius: 16.2,
target: new THREE.Vector3(0, 0.35, 0),
thetaGoal: 0.02,
phiGoal: 1.34,
radiusGoal: 16.2,
targetGoal: new THREE.Vector3(0, 0.35, 0)
};
function updateCamera() {
cameraState.theta += (cameraState.thetaGoal - cameraState.theta) * 0.085;
cameraState.phi += (cameraState.phiGoal - cameraState.phi) * 0.085;
cameraState.radius += (cameraState.radiusGoal - cameraState.radius) * 0.085;
cameraState.target.lerp(cameraState.targetGoal, 0.085);
const sinPhi = Math.sin(cameraState.phi);
camera.position.set(
cameraState.target.x +
cameraState.radius * sinPhi * Math.sin(cameraState.theta),
cameraState.target.y +
cameraState.radius * Math.cos(cameraState.phi),
cameraState.target.z +
cameraState.radius * sinPhi * Math.cos(cameraState.theta)
);
camera.lookAt(cameraState.target);
}
const pointers = new Map();
let dragDistance = 0;
let pinchDistance = 0;
renderer.domElement.addEventListener("pointerdown", event => {
renderer.domElement.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
dragDistance = 0;
pinchDistance = getPinchDistance();
});
renderer.domElement.addEventListener("pointermove", event => {
const previous = pointers.get(event.pointerId);
if (!previous) {
updateHover(event);
return;
}
const dx = event.clientX - previous.x;
const dy = event.clientY - previous.y;
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
dragDistance += Math.abs(dx) + Math.abs(dy);
if (pointers.size === 1) {
cameraState.thetaGoal -= dx * 0.0055;
cameraState.phiGoal = THREE.MathUtils.clamp(
cameraState.phiGoal - dy * 0.0045,
0.62,
1.76
);
} else if (pointers.size === 2) {
const nextDistance = getPinchDistance();
if (pinchDistance > 0 && nextDistance > 0) {
cameraState.radiusGoal = THREE.MathUtils.clamp(
cameraState.radiusGoal * (pinchDistance / nextDistance),
7.2,
22
);
}
pinchDistance = nextDistance;
}
});
function endPointer(event) {
pointers.delete(event.pointerId);
pinchDistance = getPinchDistance();
if (dragDistance < 7 && event.type === "pointerup") {
handleSceneClick(event);
}
}
renderer.domElement.addEventListener("pointerup", endPointer);
renderer.domElement.addEventListener("pointercancel", endPointer);
renderer.domElement.addEventListener(
"wheel",
event => {
event.preventDefault();
cameraState.radiusGoal = THREE.MathUtils.clamp(
cameraState.radiusGoal + event.deltaY * 0.009,
7.2,
22
);
},
{ passive: false }
);
function getPinchDistance() {
if (pointers.size < 2) return 0;
const points = Array.from(pointers.values());
return Math.hypot(
points[0].x - points[1].x,
points[0].y - points[1].y
);
}
// Raycast interactions
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
const pickTargets = [];
neuron.traverse(object => {
if (object.isMesh) {
object.userData.cellIndex = 0;
pickTargets.push(object);
}
});
beta.traverse(object => {
if (object.isMesh) {
object.userData.cellIndex = 1;
pickTargets.push(object);
}
});
function raycastCell(event) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(pickTargets, false);
return hits.length ? hits[0].object.userData.cellIndex : null;
}
function updateHover(event) {
renderer.domElement.style.cursor = raycastCell(event) === null
? "grab"
: "pointer";
}
function handleSceneClick(event) {
const index = raycastCell(event);
if (index !== null) focusCell(index);
}
function focusCell(index) {
const group = index === 0 ? neuron : beta;
cameraState.targetGoal.set(group.position.x, 0.35, 0);
cameraState.radiusGoal = 9.1;
document.querySelectorAll(".cell-card").forEach(card => {
card.classList.toggle("selected", Number(card.dataset.cell) === index);
});
}
function resetView() {
cameraState.targetGoal.set(0, 0.35, 0);
cameraState.radiusGoal = 16.2;
cameraState.thetaGoal = 0.02;
cameraState.phiGoal = 1.34;
document.querySelectorAll(".cell-card").forEach(card => {
card.classList.toggle("selected", card.dataset.cell === "0");
});
}
document.querySelectorAll(".cell-card").forEach(card => {
card.addEventListener("click", () => {
focusCell(Number(card.dataset.cell));
});
});
document.getElementById("resetView").addEventListener("click", resetView);
// Project HTML labels onto their 3D anchors
const projected = new THREE.Vector3();
function positionLabel(element, anchor) {
anchor.getWorldPosition(projected);
projected.project(camera);
const visible = projected.z > -1 && projected.z < 1;
element.style.left = `${(projected.x * 0.5 + 0.5) * window.innerWidth}px`;
element.style.top = `${(-projected.y * 0.5 + 0.5) * window.innerHeight}px`;
element.style.opacity = visible ? "1" : "0";
}
// Animation
function animate() {
requestAnimationFrame(animate);
const elapsed = clock.getElapsedTime();
const dt = Math.min(clock.getDelta(), 0.05);
updateCamera();
const neuronPulse = 1 + Math.sin(elapsed * 2.2) * 0.012;
neuronMembrane.scale.setScalar(neuronPulse);
const betaPulse = 1 + Math.sin(elapsed * 1.8 + 1.4) * 0.009;
betaMembrane.scale.setScalar(betaPulse);
neuronNucleus.rotation.y = elapsed * 0.08;
betaNucleus.rotation.y = -elapsed * 0.07;
neuronDNA.group.rotation.y = elapsed * 0.17;
betaDNA.group.rotation.y = elapsed * 0.15;
neuronDNA.markers.forEach((marker, i) => {
marker.material.emissiveIntensity =
1.65 + Math.sin(elapsed * 3 + i * 0.9) * 0.7;
});
betaDNA.markers.forEach((marker, i) => {
marker.material.emissiveIntensity =
1.65 + Math.sin(elapsed * 3.2 + i * 0.8) * 0.7;
});
neuronOrganelles.forEach((organelle, i) => {
organelle.rotation.x += dt * (0.07 + i * 0.005);
});
// Traveling action potential
const axProgress = (elapsed * 0.34) % 1;
const pulsePosition = axon.userData.curve.getPoint(axProgress);
pulse.position.copy(pulsePosition);
pulse.scale.setScalar(1 + Math.sin(elapsed * 13) * 0.18);
const haloProgress = (elapsed * 0.7) % 1;
pulseHalo.scale.setScalar(1 + haloProgress * 2.7);
pulseHalo.material.opacity = (1 - haloProgress) * 0.75;
// Internal beta-cell vesicles
betaVesicles.forEach(vesicle => {
const data = vesicle.userData;
const angle = data.angle + elapsed * data.speed;
vesicle.position.set(
Math.cos(angle) * data.radius,
data.y + Math.sin(elapsed * 0.7 + data.angle) * 0.1,
Math.sin(angle) * data.radius + 0.25
);
});
// Released proteins travel upward and disperse
secretedProteins.forEach(protein => {
const data = protein.userData;
const progress = (elapsed * data.speed + data.phase) % 1;
const spread = progress * progress * 1.3;
protein.position.set(
Math.cos(data.angle) * (data.radius + spread),
1.55 + progress * 2.7,
Math.sin(data.angle) * (data.radius + spread)
);
const size = 0.065 + (data.phase % 0.25) * 0.15;
protein.scale.setScalar(size);
protein.rotation.y = elapsed * 0.8 + data.phase * 6;
});
golgi.rotation.z = -0.2 + Math.sin(elapsed * 0.32) * 0.05;
motes.rotation.y = elapsed * 0.008;
positionLabel(document.getElementById("neuronLabel"), neuronAnchor);
positionLabel(document.getElementById("betaLabel"), betaAnchor);
positionLabel(document.getElementById("neuronOutput"), neuronOutputAnchor);
positionLabel(document.getElementById("betaOutput"), betaOutputAnchor);
renderer.render(scene, camera);
}
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
resetView();
animate();
</script>
</body>
</html>
```