Prompt specification
Build or customize the Three.js 3D scene "Gene-switch and protein-output model" 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: Gene-switch and protein-output model
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/gene-switch-and-protein-output-model-x0905
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows gene expression. Build one schematic gene strip beside an on-off regulatory gate and symbolic protein pieces; label the relationship simplified and avoid depicting genes as independent mechanical switches universally. Low-poly.
Working Three.js Starter (gene-switch-and-protein-output-model-x0905):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="theme-color" content="#edf0e8">
<title>Gene Expression — Regulatory Context</title>
<style>
:root {
--ink: #173b3a;
--muted: #60716d;
--paper: rgba(250, 249, 244, 0.88);
--line: rgba(23, 59, 58, 0.14);
--teal: #2a9d8f;
--coral: #e76f51;
--gold: #e9b949;
--off: #a76f65;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #edf0e8;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
font: inherit;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
outline: none;
}
#scene canvas:active {
cursor: grabbing;
}
.topbar {
position: fixed;
z-index: 10;
top: 26px;
left: 30px;
right: 30px;
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 24px;
pointer-events: none;
}
.title-block {
max-width: 640px;
}
.kicker {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 8px;
color: var(--teal);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.kicker::before {
width: 8px;
height: 8px;
border-radius: 2px;
background: var(--teal);
content: "";
transform: rotate(45deg);
}
h1 {
margin: 0;
font-size: clamp(27px, 3vw, 47px);
font-weight: 720;
letter-spacing: -0.045em;
line-height: 1.03;
}
.subtitle {
max-width: 570px;
margin: 10px 0 0;
color: var(--muted);
font-size: 14px;
line-height: 1.5;
}
.control-cluster {
display: flex;
flex-direction: column;
align-items: flex-end;
gap: 9px;
pointer-events: auto;
}
.state-toggle {
display: flex;
min-width: 225px;
align-items: center;
gap: 13px;
padding: 12px 15px;
border: 1px solid var(--line);
border-radius: 15px;
background: var(--paper);
box-shadow: 0 12px 34px rgba(34, 62, 58, 0.08);
color: var(--ink);
text-align: left;
cursor: pointer;
backdrop-filter: blur(12px);
transition:
border-color 180ms ease,
transform 180ms ease;
}
.state-toggle:hover {
border-color: rgba(42, 157, 143, 0.4);
transform: translateY(-1px);
}
.state-toggle:focus-visible,
.reset-button:focus-visible {
outline: 3px solid rgba(42, 157, 143, 0.35);
outline-offset: 3px;
}
.switch {
position: relative;
width: 47px;
height: 27px;
flex: 0 0 auto;
border-radius: 999px;
background: var(--gold);
box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.07);
transition: background 240ms ease;
}
.switch::after {
position: absolute;
top: 4px;
left: 4px;
width: 19px;
height: 19px;
border-radius: 50%;
background: #fffdf6;
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.16);
content: "";
transition: transform 240ms ease;
}
.state-toggle[aria-pressed="false"] .switch {
background: var(--off);
}
.state-toggle[aria-pressed="false"] .switch::after {
transform: translateX(20px);
}
.state-copy {
display: grid;
gap: 3px;
}
.state-copy small {
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.12em;
}
.state-copy strong {
font-size: 13px;
letter-spacing: -0.01em;
}
.meter {
position: relative;
width: 100%;
height: 3px;
margin-top: 7px;
overflow: hidden;
border-radius: 99px;
background: rgba(23, 59, 58, 0.1);
}
.meter i {
position: absolute;
inset: 0;
border-radius: inherit;
background: linear-gradient(90deg, var(--teal), var(--gold), var(--coral));
transform: scaleX(1);
transform-origin: left;
transition: transform 260ms ease;
}
.view-tools {
display: flex;
align-items: center;
gap: 8px;
}
.reset-button,
.hint {
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(250, 249, 244, 0.7);
color: var(--muted);
font-size: 10px;
backdrop-filter: blur(9px);
}
.reset-button {
padding: 8px 11px;
cursor: pointer;
}
.reset-button:hover {
color: var(--ink);
}
.hint {
padding: 8px 10px;
}
#labels {
position: fixed;
z-index: 4;
inset: 0;
overflow: hidden;
pointer-events: none;
}
.scene-label {
position: absolute;
display: grid;
min-width: 145px;
gap: 3px;
padding: 8px 10px;
border: 1px solid rgba(23, 59, 58, 0.12);
border-radius: 10px;
background: rgba(250, 249, 244, 0.78);
box-shadow: 0 8px 22px rgba(23, 59, 58, 0.06);
text-align: center;
transform: translate(-50%, -100%);
backdrop-filter: blur(8px);
}
.scene-label span {
color: var(--muted);
font-size: 8px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.scene-label strong {
font-size: 11px;
font-weight: 700;
}
.scene-label.gate strong {
color: #9a6b00;
}
.scene-label.gate.off strong {
color: #8d564b;
}
.relationship {
position: fixed;
z-index: 10;
left: 30px;
bottom: 27px;
width: min(570px, calc(100vw - 60px));
padding: 15px 17px;
border: 1px solid var(--line);
border-radius: 15px;
background: var(--paper);
box-shadow: 0 15px 40px rgba(34, 62, 58, 0.09);
backdrop-filter: blur(13px);
}
.relationship-label {
margin-bottom: 6px;
color: var(--teal);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.relationship p {
margin: 0;
color: var(--ink);
font-size: 12px;
line-height: 1.55;
}
.caveat {
display: flex;
align-items: flex-start;
gap: 8px;
margin-top: 9px;
color: var(--muted);
font-size: 10px;
line-height: 1.45;
}
.caveat::before {
display: grid;
width: 15px;
height: 15px;
flex: 0 0 auto;
place-items: center;
border-radius: 50%;
background: rgba(231, 111, 81, 0.13);
color: var(--coral);
font-size: 10px;
font-weight: 900;
content: "!";
}
.legend {
position: fixed;
z-index: 9;
right: 30px;
bottom: 31px;
display: grid;
gap: 9px;
padding: 13px 15px;
border: 1px solid var(--line);
border-radius: 13px;
background: rgba(250, 249, 244, 0.72);
color: var(--muted);
font-size: 10px;
backdrop-filter: blur(10px);
}
.legend div {
display: flex;
align-items: center;
gap: 8px;
}
.swatch {
width: 9px;
height: 9px;
border-radius: 2px;
transform: rotate(45deg);
}
.swatch.gene {
background: var(--teal);
}
.swatch.gate {
background: var(--gold);
}
.swatch.protein {
background: var(--coral);
}
@media (max-width: 800px) {
.topbar {
top: 18px;
left: 18px;
right: 18px;
}
h1 {
max-width: 430px;
font-size: clamp(25px, 7vw, 37px);
}
.subtitle {
display: none;
}
.control-cluster {
align-items: flex-end;
}
.state-toggle {
min-width: 190px;
padding: 10px 12px;
}
.state-copy strong {
font-size: 11px;
}
.hint {
display: none;
}
.relationship {
left: 16px;
bottom: 16px;
width: calc(100vw - 32px);
padding: 12px 14px;
}
.legend {
display: none;
}
.scene-label {
min-width: 110px;
padding: 6px 8px;
}
.scene-label span {
font-size: 7px;
}
.scene-label strong {
font-size: 9px;
}
}
@media (max-width: 560px) {
.topbar {
display: block;
}
.title-block {
max-width: calc(100vw - 36px);
}
.control-cluster {
position: fixed;
top: 122px;
right: 16px;
}
.state-toggle {
min-width: 176px;
}
.relationship p {
font-size: 11px;
}
}
</style>
</head>
<body>
<main id="scene" aria-label="Interactive low-poly gene expression schematic"></main>
<header class="topbar">
<div class="title-block">
<div class="kicker">Gene expression · schematic</div>
<h1>Regulatory context, expression output</h1>
<p class="subtitle">
One schematic gene region, an illustrative regulatory state, and symbolic
protein pieces.
</p>
</div>
<div class="control-cluster">
<button
id="gateToggle"
class="state-toggle"
type="button"
aria-pressed="true"
aria-label="Toggle simplified regulatory gate state"
>
<span class="switch" aria-hidden="true"></span>
<span class="state-copy">
<small>SIMPLIFIED GATE STATE</small>
<strong id="stateText" aria-live="polite">ON · permissive example</strong>
<span class="meter" aria-hidden="true"><i id="meterFill"></i></span>
</span>
</button>
<div class="view-tools">
<span class="hint">Drag to orbit · wheel to zoom</span>
<button id="resetView" class="reset-button" type="button">Reset view</button>
</div>
</div>
</header>
<div id="labels" aria-hidden="true">
<div class="scene-label" id="geneLabel">
<span>One gene region</span>
<strong>Schematic gene strip</strong>
</div>
<div class="scene-label gate" id="gateLabel">
<span>Regulatory context</span>
<strong id="gateState">ON · permissive example</strong>
</div>
<div class="scene-label" id="proteinLabel">
<span>Expression output</span>
<strong>Symbolic protein pieces</strong>
</div>
</div>
<section class="relationship" aria-label="Simplified relationship explanation">
<div class="relationship-label">Relationship · simplified</div>
<p>
Regulatory conditions can permit or suppress expression from this gene.
Here, a permissive state allows the symbolic output to appear, while a
repressed state reduces it.
</p>
<div class="caveat">
The gate is a teaching metaphor, not a universal mechanical switch.
Real gene regulation is often graded, combinatorial, and context-dependent.
</div>
</section>
<aside class="legend" aria-label="Visual legend">
<div><span class="swatch gene"></span>Gene strip</div>
<div><span class="swatch gate"></span>Regulatory state</div>
<div><span class="swatch protein"></span>Protein symbols</div>
</aside>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const sceneHost = document.getElementById("scene");
const reducedMotion = window.matchMedia(
"(prefers-reduced-motion: reduce)"
).matches;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xedf0e8);
const camera = new THREE.OrthographicCamera(-7, 7, 4, -4, 0.1, 100);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.8));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
sceneHost.appendChild(renderer.domElement);
renderer.domElement.setAttribute(
"aria-label",
"A draggable three-dimensional schematic of gene expression"
);
const palette = {
teal: 0x2a9d8f,
tealDark: 0x246b65,
tealPale: 0xb8d9ce,
violet: 0x8b78a6,
gold: 0xe9b949,
coral: 0xe76f51,
coralPale: 0xf1b9a9,
ink: 0x173b3a,
cream: 0xf8f4e8,
floor: 0xe4e8df
};
const materials = {
frame: new THREE.MeshStandardMaterial({
color: palette.ink,
roughness: 0.78,
metalness: 0.04,
flatShading: true
}),
geneA: new THREE.MeshStandardMaterial({
color: palette.teal,
roughness: 0.66,
flatShading: true
}),
geneB: new THREE.MeshStandardMaterial({
color: palette.violet,
roughness: 0.68,
flatShading: true
}),
platform: new THREE.MeshStandardMaterial({
color: 0xdce4dc,
roughness: 0.92,
flatShading: true
}),
gold: new THREE.MeshStandardMaterial({
color: palette.gold,
roughness: 0.62,
metalness: 0.03,
flatShading: true
}),
cream: new THREE.MeshStandardMaterial({
color: palette.cream,
roughness: 0.82,
flatShading: true
})
};
const hemisphere = new THREE.HemisphereLight(0xfff9e8, 0x78918a, 2.25);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff3d4, 3.1);
keyLight.position.set(-4, 8, 7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -10;
keyLight.shadow.camera.right = 10;
keyLight.shadow.camera.top = 8;
keyLight.shadow.camera.bottom = -8;
keyLight.shadow.bias = -0.0004;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xb9ddff, 1.0);
fillLight.position.set(6, 2, 4);
scene.add(fillLight);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(60, 60),
new THREE.MeshStandardMaterial({
color: palette.floor,
roughness: 1,
metalness: 0
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -1.62;
floor.receiveShadow = true;
scene.add(floor);
function addPlatform(x, radius, depth = 0.14) {
const platform = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius * 1.08, depth, 8),
materials.platform
);
platform.position.set(x, -1.53, 0);
platform.scale.x = 1.08;
platform.receiveShadow = true;
platform.castShadow = true;
scene.add(platform);
return platform;
}
addPlatform(-4.0, 2.05);
addPlatform(-0.25, 1.25);
addPlatform(3.75, 2.25);
function cylinderBetween(start, end, radius, material, radialSegments = 6) {
const direction = new THREE.Vector3().subVectors(end, start);
const length = direction.length();
const geometry = new THREE.CylinderGeometry(
radius,
radius,
length,
radialSegments,
1,
false
);
const mesh = new THREE.Mesh(geometry, material);
mesh.position.copy(start).add(end).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
mesh.castShadow = true;
mesh.receiveShadow = true;
return mesh;
}
/* -------------------------------------------------------------
One schematic gene strip: two faceted rails with base-pair rungs.
-------------------------------------------------------------- */
const geneGroup = new THREE.Group();
scene.add(geneGroup);
const geneBacking = new THREE.Mesh(
new THREE.BoxGeometry(3.55, 0.08, 0.95),
new THREE.MeshStandardMaterial({
color: 0xcbdcd3,
roughness: 0.9,
flatShading: true
})
);
geneBacking.position.set(-4.0, -0.48, -0.08);
geneBacking.castShadow = true;
geneBacking.receiveShadow = true;
geneGroup.add(geneBacking);
const geneSegments = 15;
const railA = [];
const railB = [];
for (let i = 0; i <= geneSegments; i++) {
const t = i / geneSegments;
const x = THREE.MathUtils.lerp(-5.48, -2.48, t);
railA.push(
new THREE.Vector3(
x,
0.12 + Math.sin(t * Math.PI * 4.1) * 0.3,
Math.cos(t * Math.PI * 4.1) * 0.1
)
);
railB.push(
new THREE.Vector3(
x,
0.12 + Math.sin(t * Math.PI * 4.1 + Math.PI) * 0.3,
Math.cos(t * Math.PI * 4.1 + Math.PI) * 0.1
)
);
}
for (let i = 0; i < geneSegments; i++) {
geneGroup.add(
cylinderBetween(railA[i], railA[i + 1], 0.055, materials.geneA, 5)
);
geneGroup.add(
cylinderBetween(railB[i], railB[i + 1], 0.055, materials.geneB, 5)
);
const rungMaterial = i % 2 === 0 ? materials.geneA : materials.geneB;
geneGroup.add(
cylinderBetween(railA[i], railB[i], 0.034, rungMaterial, 5)
);
}
const endCapGeometry = new THREE.DodecahedronGeometry(0.09, 0);
[
[railA[0], materials.geneA],
[railB[0], materials.geneB],
[railA[geneSegments], materials.geneA],
[railB[geneSegments], materials.geneB]
].forEach(([position, material]) => {
const cap = new THREE.Mesh(endCapGeometry, material);
cap.position.copy(position);
cap.castShadow = true;
geneGroup.add(cap);
});
/* -------------------------------------------------------------
Illustrative regulatory gate. This is explicitly presented
below as a teaching metaphor rather than a universal switch.
-------------------------------------------------------------- */
const gateGroup = new THREE.Group();
gateGroup.position.x = -0.25;
scene.add(gateGroup);
const gatePickables = [];
const haloMaterial = new THREE.MeshStandardMaterial({
color: palette.gold,
emissive: 0x8b650d,
emissiveIntensity: 0.12,
roughness: 0.75,
transparent: true,
opacity: 0.24,
flatShading: true
});
const halo = new THREE.Mesh(
new THREE.CylinderGeometry(1.27, 1.27, 0.12, 6),
haloMaterial
);
halo.rotation.x = Math.PI / 2;
halo.position.set(0, 0.12, -0.42);
halo.receiveShadow = true;
gateGroup.add(halo);
gatePickables.push(halo);
function addGateFrameMesh(geometry, position) {
const mesh = new THREE.Mesh(geometry, materials.frame);
mesh.position.copy(position);
mesh.castShadow = true;
mesh.receiveShadow = true;
gateGroup.add(mesh);
gatePickables.push(mesh);
return mesh;
}
addGateFrameMesh(
new THREE.BoxGeometry(0.19, 2.15, 0.54),
new THREE.Vector3(-0.68, 0.15, 0)
);
addGateFrameMesh(
new THREE.BoxGeometry(0.19, 2.15, 0.54),
new THREE.Vector3(0.68, 0.15, 0)
);
addGateFrameMesh(
new THREE.BoxGeometry(1.55, 0.19, 0.54),
new THREE.Vector3(0, 1.22, 0)
);
addGateFrameMesh(
new THREE.BoxGeometry(1.55, 0.13, 0.58),
new THREE.Vector3(0, -0.92, 0)
);
const door = new THREE.Group();
gateGroup.add(door);
const doorMaterial = new THREE.MeshStandardMaterial({
color: palette.gold,
emissive: 0x6d4b00,
emissiveIntensity: 0.08,
roughness: 0.58,
metalness: 0.04,
flatShading: true
});
const doorBody = new THREE.Mesh(
new THREE.BoxGeometry(0.17, 1.57, 0.63),
doorMaterial
);
doorBody.castShadow = true;
doorBody.receiveShadow = true;
door.add(doorBody);
gatePickables.push(doorBody);
for (let i = -1; i <= 1; i++) {
const slat = new THREE.Mesh(
new THREE.BoxGeometry(0.205, 0.095, 0.69),
materials.cream
);
slat.position.y = i * 0.36;
slat.castShadow = true;
door.add(slat);
gatePickables.push(slat);
}
door.position.y = 1.4;
const statusMaterial = new THREE.MeshStandardMaterial({
color: palette.gold,
emissive: palette.gold,
emissiveIntensity: 0.7,
roughness: 0.42,
flatShading: true
});
const statusLight = new THREE.Mesh(
new THREE.OctahedronGeometry(0.16, 0),
statusMaterial
);
statusLight.position.set(0, 1.7, 0.02);
statusLight.castShadow = true;
gateGroup.add(statusLight);
gatePickables.push(statusLight);
const statusRing = new THREE.Mesh(
new THREE.TorusGeometry(0.235, 0.025, 4, 10),
materials.frame
);
statusRing.position.copy(statusLight.position);
gateRingSafe();
gateGroup.add(statusRing);
function gateRingSafe() {
statusRing.rotation.x = 0;
}
/* -------------------------------------------------------------
Symbolic proteins: deliberately geometric, non-literal pieces.
-------------------------------------------------------------- */
const proteinGroups = [];
function makeProtein(position, color, secondaryColor, variant) {
const group = new THREE.Group();
group.position.copy(position);
const primary = new THREE.MeshStandardMaterial({
color,
roughness: 0.68,
metalness: 0.03,
flatShading: true,
transparent: true,
opacity: 1
});
const secondary = new THREE.MeshStandardMaterial({
color: secondaryColor,
roughness: 0.75,
metalness: 0.02,
flatShading: true,
transparent: true,
opacity: 1
});
const beadGeometry = new THREE.IcosahedronGeometry(0.32, 0);
const smallGeometry = new THREE.OctahedronGeometry(0.21, 0);
const blockGeometry = new THREE.BoxGeometry(0.42, 0.34, 0.38);
const pieces = [];
if (variant === 0) {
pieces.push({
geometry: beadGeometry,
material: primary,
position: new THREE.Vector3(0, 0, 0),
scale: new THREE.Vector3(1.1, 0.85, 0.95)
});
pieces.push({
geometry: smallGeometry,
material: secondary,
position: new THREE.Vector3(0.38, 0.2, 0.03)
});
pieces.push({
geometry: blockGeometry,
material: secondary,
position: new THREE.Vector3(-0.34, -0.18, 0.08),
rotation: new THREE.Euler(0.2, 0.35, -0.18)
});
} else if (variant === 1) {
pieces.push({
geometry: beadGeometry,
material: primary,
position: new THREE.Vector3(-0.25, 0.08, 0),
scale: new THREE.Vector3(0.9, 1.15, 0.85)
});
pieces.push({
geometry: beadGeometry,
material: secondary,
position: new THREE.Vector3(0.28, 0.16, 0.08),
scale: new THREE.Vector3(0.82, 0.9, 0.75)
});
pieces.push({
geometry: smallGeometry,
material: primary,
position: new THREE.Vector3(0.02, -0.28, 0.2),
rotation: new THREE.Euler(0.3, 0.1, 0.4)
});
} else {
pieces.push({
geometry: blockGeometry,
material: primary,
position: new THREE.Vector3(-0.2, 0.08, 0),
rotation: new THREE.Euler(0.1, 0.3, 0.16)
});
pieces.push({
geometry: beadGeometry,
material: secondary,
position: new THREE.Vector3(0.28, 0.18, 0.02),
scale: new THREE.Vector3(0.9, 0.75, 0.85)
});
pieces.push({
geometry: smallGeometry,
material: primary,
position: new THREE.Vector3(0.28, -0.27, 0.1)
});
}
pieces.forEach((piece) => {
const mesh = new THREE.Mesh(piece.geometry, piece.material);
mesh.position.copy(piece.position);
if (piece.rotation) mesh.rotation.copy(piece.rotation);
if (piece.scale) mesh.scale.copy(piece.scale);
mesh.castShadow = true;
mesh.receiveShadow = true;
group.add(mesh);
});
group.userData.baseY = position.y;
group.userData.materials = [primary, secondary];
group.userData.phase = variant * 1.7;
proteinGroups.push(group);
scene.add(group);
return group;
}
makeProtein(
new THREE.Vector3(2.35, 0.23, 0.08),
palette.coral,
palette.coralPale,
0
);
makeProtein(
new THREE.Vector3(3.48, 0.58, -0.08),
0x4f8fa3,
0xa5d4dc,
1
);
makeProtein(
new THREE.Vector3(4.48, 0.13, 0.13),
palette.violet,
0xc8b9d3,
2
);
makeProtein(
new THREE.Vector3(3.65, -0.55, 0.28),
palette.gold,
0xf2d88f,
0
);
/* -------------------------------------------------------------
Expression particles: stylized flow, not literal molecules.
-------------------------------------------------------------- */
const particles = [];
const particleGeometry = new THREE.OctahedronGeometry(0.075, 0);
for (let i = 0; i < 18; i++) {
const material = new THREE.MeshStandardMaterial({
color: palette.teal,
emissive: palette.teal,
emissiveIntensity: 0.14,
roughness: 0.5,
transparent: true,
opacity: 0.8,
flatShading: true
});
const particle = new THREE.Mesh(particleGeometry, material);
particle.castShadow = true;
scene.add(particle);
particles.push(particle);
}
/* -------------------------------------------------------------
Interaction and state.
-------------------------------------------------------------- */
const gateToggle = document.getElementById("gateToggle");
const stateText = document.getElementById("stateText");
const gateState = document.getElementById("gateState");
const gateLabel = document.getElementById("gateLabel");
const meterFill = document.getElementById("meterFill");
let expressionOn = true;
let stateBlend = 1;
const onDoorColor = new THREE.Color(palette.gold);
const offDoorColor = new THREE.Color(0xaa7167);
const onStatusColor = new THREE.Color(palette.gold);
const offStatusColor = new THREE.Color(0xaa7167);
function setExpressionState(on) {
expressionOn = on;
gateToggle.setAttribute("aria-pressed", String(on));
const text = on
? "ON · permissive example"
: "OFF · repressed example";
stateText.textContent = text;
gateState.textContent = text;
gateLabel.classList.toggle("off", !on);
}
gateToggle.addEventListener("click", () => {
setExpressionState(!expressionOn);
});
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
function pickGate(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);
return raycaster.intersectObjects(gatePickables, false).length > 0;
}
/* Direct camera controls; no external controls addon. */
const cameraTarget = new THREE.Vector3(0, 0.03, 0);
let cameraAzimuth = 0;
let cameraElevation = 0.075;
let cameraZoom = 1;
function updateCamera() {
const radius = 16;
camera.position.set(
cameraTarget.x +
Math.sin(cameraAzimuth) *
Math.cos(cameraElevation) *
radius,
cameraTarget.y + Math.sin(cameraElevation) * radius,
cameraTarget.z +
Math.cos(cameraAzimuth) *
Math.cos(cameraElevation) *
radius
);
camera.lookAt(cameraTarget);
camera.updateMatrixWorld();
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
const halfHeight = Math.max(3.35, 6.65 / aspect);
camera.left = -halfHeight * aspect;
camera.right = halfHeight * aspect;
camera.top = halfHeight;
camera.bottom = -halfHeight;
camera.zoom = cameraZoom;
camera.updateProjectionMatrix();
renderer.setSize(width, height);
}
function resetView() {
cameraAzimuth = 0;
cameraElevation = 0.075;
cameraZoom = 1;
resize();
updateCamera();
}
window.addEventListener("resize", resize);
document.getElementById("resetView").addEventListener("click", resetView);
let pointerDown = null;
renderer.domElement.addEventListener("pointerdown", (event) => {
if (event.pointerType === "mouse" && event.button !== 0) return;
pointerDown = {
x: event.clientX,
y: event.clientY,
moved: false
};
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointerDown) return;
const dx = event.clientX - pointerDown.x;
const dy = event.clientY - pointerDown.y;
if (Math.abs(dx) + Math.abs(dy) > 3) {
pointerDown.moved = true;
}
cameraAzimuth = THREE.MathUtils.clamp(
cameraAzimuth - dx * 0.0045,
-0.55,
0.55
);
cameraElevation = THREE.MathUtils.clamp(
cameraElevation + dy * 0.0035,
-0.18,
0.34
);
updateCamera();
});
renderer.domElement.addEventListener("pointerup", (event) => {
if (pointerDown && !pointerDown.moved && pickGate(event)) {
setExpressionState(!expressionOn);
}
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
pointerDown = null;
});
renderer.domElement.addEventListener("pointercancel", () => {
pointerDown = null;
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
const factor = event.deltaY > 0 ? 0.92 : 1.08;
cameraZoom = THREE.MathUtils.clamp(cameraZoom * factor, 0.78, 1.42);
camera.zoom = cameraZoom;
camera.updateProjectionMatrix();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetView);
/* -------------------------------------------------------------
Projected HTML labels.
-------------------------------------------------------------- */
const geneAnchor = new THREE.Vector3(-4.0, 1.12, 0);
const gateAnchor = new THREE.Vector3(-0.25, 2.08, 0);
const proteinAnchor = new THREE.Vector3(3.65, 1.55, 0);
const labelElements = [
[document.getElementById("geneLabel"), geneAnchor],
[document.getElementById("gateLabel"), gateAnchor],
[document.getElementById("proteinLabel"), proteinAnchor]
];
const projected = new THREE.Vector3();
function positionLabels() {
const width = window.innerWidth;
const height = window.innerHeight;
labelElements.forEach(([element, anchor]) => {
projected.copy(anchor).project(camera);
const x = (projected.x * 0.5 + 0.5) * width;
const y = (-projected.y * 0.5 + 0.5) * height;
element.style.left = `${x}px`;
element.style.top = `${y}px`;
});
}
/* -------------------------------------------------------------
Animation.
-------------------------------------------------------------- */
const clock = new THREE.Clock();
const tealColor = new THREE.Color(palette.teal);
const coralColor = new THREE.Color(palette.coral);
const temporaryColor = new THREE.Color();
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
const elapsed = clock.elapsedTime;
const targetBlend = expressionOn ? 1 : 0;
stateBlend +=
(targetBlend - stateBlend) * (1 - Math.exp(-delta * 5.2));
door.position.y = THREE.MathUtils.lerp(-0.22, 1.4, stateBlend);
door.rotation.z = THREE.MathUtils.lerp(-0.09, 0.035, stateBlend);
doorMaterial.color.lerpColors(offDoorColor, onDoorColor, stateBlend);
statusMaterial.color.lerpColors(offStatusColor, onStatusColor, stateBlend);
statusMaterial.emissive.copy(statusMaterial.color);
statusMaterial.emissiveIntensity = 0.28 + stateBlend * 0.5;
haloMaterial.opacity = 0.08 + stateBlend * 0.19;
haloMaterial.emissiveIntensity = 0.03 + stateBlend * 0.16;
meterFill.style.transform = `scaleX(${0.14 + stateBlend * 0.86})`;
const lightPulse = reducedMotion
? 0
: Math.sin(elapsed * 2.2) * 0.055 * stateBlend;
statusLight.scale.setScalar(1 + lightPulse);
const particleRate = reducedMotion ? 0.035 : 0.095;
particles.forEach((particle, index) => {
const phase = (elapsed * particleRate + index / particles.length) % 1;
const travel = THREE.MathUtils.lerp(4.15, 10.55, stateBlend);
particle.position.set(
-5.65 + phase * travel,
0.14 + Math.sin(phase * Math.PI * 2 + index) * 0.12,
Math.sin(phase * Math.PI) * 0.24
);
const edgeFade = Math.sin(phase * Math.PI);
particle.material.opacity =
edgeFade * (0.24 + stateBlend * 0.76);
particle.scale.setScalar(0.72 + stateBlend * 0.35);
const colorProgress = THREE.MathUtils.clamp(
(particle.position.x + 5.65) / 10.55,
0,
1
);
temporaryColor
.copy(tealColor)
.lerp(coralColor, colorProgress);
particle.material.color.copy(temporaryColor);
particle.material.emissive.copy(temporaryColor);
});
proteinGroups.forEach((group, index) => {
group.userData.materials.forEach((material) => {
material.opacity = 0.25 + stateBlend * 0.75;
});
const scale = 0.84 + stateBlend * 0.16;
group.scale.setScalar(scale);
const floatAmount = reducedMotion
? 0
: Math.sin(elapsed * 0.8 + group.userData.phase) * 0.055;
group.position.y = group.userData.baseY + floatAmount;
});
scene.updateMatrixWorld();
camera.updateMatrixWorld();
positionLabels();
renderer.render(scene, camera);
}
resize();
updateCamera();
renderer.setAnimationLoop(animate);
</script>
</body>
</html>
```