Got it! I’m going to create a single HTML file that uses Three.js for 3D rendering, and vanilla JavaScript for UI controls. The page will:
- Let you select different mushroom types from a dropdown.
- Show a 3D model of the mushroom growing from spore to fully grown based on a slider.
- Display info about the selected mushroom in a panel on the right.
I’ll keep the mushroom models simple but visually distinct, using procedural geometry to simulate growth stages.
Features:
- Dropdown to select mushroom type.
- Slider for lifespan (0 = spore, 100 = fully grown).
- 3D canvas with Three.js showing the mushroom growing.
- Info panel with mushroom details.
Mushrooms included:
- Fly Agaric (Amanita muscaria)
- Shiitake (Lentinula edodes)
- Morel (Morchella)
- Oyster Mushroom (Pleurotus ostreatus)
Here is the full single HTML file:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>3D Mushroom Growth Simulator</title>
<style>
body, html {
margin: 0; height: 100%; overflow: hidden;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background: #222;
color: #eee;
display: flex;
}
#container {
flex: 1;
position: relative;
}
#ui {
width: 320px;
background: #111;
padding: 20px;
box-sizing: border-box;
display: flex;
flex-direction: column;
gap: 20px;
}
label {
font-weight: bold;
margin-bottom: 6px;
display: block;
}
select, input[type=range] {
width: 100%;
}
#info {
background: #222;
padding: 15px;
border-radius: 8px;
font-size: 14px;
line-height: 1.4;
flex-grow: 1;
overflow-y: auto;
}
canvas {
display: block;
}
h1 {
margin: 0 0 10px 0;
font-size: 22px;
text-align: center;
}
</style>
</head>
<body>
<div id="container"></div>
<div id="ui">
<h1>Mushroom Growth Simulator</h1>
<div>
<label for="mushroomSelect">Select Mushroom Type:</label>
<select id="mushroomSelect">
<option value="flyAgaric">Fly Agaric (Amanita muscaria)</option>
<option value="shiitake">Shiitake (Lentinula edodes)</option>
<option value="morel">Morel (Morchella)</option>
<option value="oyster">Oyster Mushroom (Pleurotus ostreatus)</option>
</select>
</div>
<div>
<label for="lifespanSlider">Fungi Lifespan (Growth Stage):</label>
<input type="range" id="lifespanSlider" min="0" max="100" value="0" />
</div>
<div id="info">
<h2 id="mushroomName">Fly Agaric (Amanita muscaria)</h2>
<p id="mushroomDescription">
The Fly Agaric is a striking red mushroom with white spots, known for its psychoactive properties. It grows in symbiosis with trees and is iconic in folklore.
</p>
<p><strong>Habitat:</strong> Woodlands, especially birch and pine forests.</p>
<p><strong>Lifespan:</strong> From spore to mature fruiting body in about 1-2 weeks.</p>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/three@0.152.2/build/three.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/three@0.152.2/examples/js/controls/OrbitControls.min.js"></script>
<script>
(() => {
// Mushroom data
const mushrooms = {
flyAgaric: {
name: "Fly Agaric (Amanita muscaria)",
description: "The Fly Agaric is a striking red mushroom with white spots, known for its psychoactive properties. It grows in symbiosis with trees and is iconic in folklore.",
habitat: "Woodlands, especially birch and pine forests.",
lifespan: "From spore to mature fruiting body in about 1-2 weeks.",
colorCap: 0xff2200,
colorStem: 0xf5f5dc,
spots: true,
model: createFlyAgaricModel
},
shiitake: {
name: "Shiitake (Lentinula edodes)",
description: "Shiitake mushrooms are popular edible fungi with a brown, umbrella-shaped cap and a woody stem. They are cultivated worldwide for culinary use.",
habitat: "Decaying hardwood logs, especially oak.",
lifespan: "Fruiting bodies develop in 7-10 days.",
colorCap: 0x8b5a2b,
colorStem: 0xd2b48c,
spots: false,
model: createShiitakeModel
},
morel: {
name: "Morel (Morchella)",
description: "Morels are prized edible mushrooms with a honeycomb-like cap. They are highly sought after by foragers and chefs.",
habitat: "Woodlands, often near ash, elm, and apple trees.",
lifespan: "Fruiting bodies appear in spring and mature quickly.",
colorCap: 0x7b5e2e,
colorStem: 0xc2b280,
spots: false,
model: createMorelModel
},
oyster: {
name: "Oyster Mushroom (Pleurotus ostreatus)",
description: "Oyster mushrooms have broad, oyster-shaped caps and grow in shelf-like clusters on trees. They are widely cultivated and eaten.",
habitat: "Decaying hardwood trees.",
lifespan: "Fruiting bodies develop in 5-7 days.",
colorCap: 0xdcdcdc,
colorStem: 0xf0f0f0,
spots: false,
model: createOysterModel
}
};
// Setup Three.js scene
const container = document.getElementById('container');
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x222222);
const camera = new THREE.PerspectiveCamera(45, container.clientWidth / container.clientHeight, 0.1, 100);
camera.position.set(0, 2, 5);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setSize(container.clientWidth, container.clientHeight);
container.appendChild(renderer.domElement);
// Controls
const controls = new THREE.OrbitControls(camera, renderer.domElement);
controls.enableDamping = true;
controls.dampingFactor = 0.1;
controls.minDistance = 2;
controls.maxDistance = 10;
controls.target.set(0, 1, 0);
// Lights
const hemiLight = new THREE.HemisphereLight(0xffffff, 0x444444, 1.2);
hemiLight.position.set(0, 5, 0);
scene.add(hemiLight);
const dirLight = new THREE.DirectionalLight(0xffffff, 0.8);
dirLight.position.set(3, 10, 10);
scene.add(dirLight);
// Ground plane
const groundGeo = new THREE.PlaneGeometry(10, 10);
const groundMat = new THREE.MeshPhongMaterial({ color: 0x223322, depthWrite: false });
const ground = new THREE.Mesh(groundGeo, groundMat);
ground.rotation.x = -Math.PI / 2;
ground.position.y = 0;
scene.add(ground);
// Current mushroom group
let mushroomGroup = new THREE.Group();
scene.add(mushroomGroup);
// UI Elements
const mushroomSelect = document.getElementById('mushroomSelect');
const lifespanSlider = document.getElementById('lifespanSlider');
const mushroomName = document.getElementById('mushroomName');
const mushroomDescription = document.getElementById('mushroomDescription');
const infoPanel = document.getElementById('info');
// Create mushroom models (procedural)
// Fly Agaric: red cap with white spots, white stem
function createFlyAgaricModel() {
const group = new THREE.Group();
// Stem - cylinder grows taller
const stemGeo = new THREE.CylinderGeometry(0.15, 0.2, 1, 16, 1, true);
const stemMat = new THREE.MeshPhongMaterial({ color: mushrooms.flyAgaric.colorStem });
const stem = new THREE.Mesh(stemGeo, stemMat);
stem.position.y = 0.5;
group.add(stem);
// Cap - hemisphere grows from tiny to big
const capGeo = new THREE.SphereGeometry(0.7, 32, 16, 0, Math.PI * 2, 0, Math.PI / 2);
const capMat = new THREE.MeshPhongMaterial({ color: mushrooms.flyAgaric.colorCap, shininess: 80 });
const cap = new THREE.Mesh(capGeo, capMat);
cap.position.y = 1.1;
group.add(cap);
// Spots - white spheres on cap
const spots = [];
const spotGeo = new THREE.SphereGeometry(0.07, 8, 8);
const spotMat = new THREE.MeshPhongMaterial({ color: 0xffffff });
const spotPositions = [
[0.3, 1.3, 0.3],
[-0.25, 1.25, 0.4],
[0.1, 1.35, -0.3],
[-0.3, 1.3, -0.2],
[0, 1.4, 0]
];
for (const pos of spotPositions) {
const spot = new THREE.Mesh(spotGeo, spotMat);
spot.position.set(...pos);
spots.push(spot);
group.add(spot);
}
return { group, stem, cap, spots };
}
// Shiitake: brown umbrella cap, thick stem
function createShiitakeModel() {
const group = new THREE.Group();
// Stem - thick cylinder
const stemGeo = new THREE.CylinderGeometry(0.2, 0.25, 1.2, 16);
const stemMat = new THREE.MeshPhongMaterial({ color: mushrooms.shiitake.colorStem });
const stem = new THREE.Mesh(stemGeo, stemMat);
stem.position.y = 0.6;
group.add(stem);
// Cap - umbrella shape (cone with rounded edges)
const capGeo = new THREE.ConeGeometry(0.8, 0.6, 32, 1, true);
const capMat = new THREE.MeshPhongMaterial({ color: mushrooms.shiitake.colorCap, shininess: 40 });
const cap = new THREE.Mesh(capGeo, capMat);
cap.position.y = 1.2;
cap.rotation.x = Math.PI;
group.add(cap);
return { group, stem, cap };
}
// Morel: honeycomb cap, tall stem
function createMorelModel() {
const group = new THREE.Group();
// Stem - tall cylinder
const stemGeo = new THREE.CylinderGeometry(0.15, 0.15, 1.5, 12);
const stemMat = new THREE.MeshPhongMaterial({ color: mushrooms.morel.colorStem });
const stem = new THREE.Mesh(stemGeo, stemMat);
stem.position.y = 0.75;
group.add(stem);
// Cap - elongated sphere with honeycomb texture (simulated with geometry)
const capGeo = new THREE.SphereGeometry(0.5, 16, 16);
capGeo.scale(1, 2, 1);
const capMat = new THREE.MeshPhongMaterial({ color: mushrooms.morel.colorCap, shininess: 20 });
const cap = new THREE.Mesh(capGeo, capMat);
cap.position.y = 1.8;
// Create honeycomb pattern by modifying vertices (simple noise)
for (let i = 0; i < capGeo.attributes.position.count; i++) {
const y = capGeo.attributes.position.getY(i);
const x = capGeo.attributes.position.getX(i);
const z = capGeo.attributes.position.getZ(i);
// Create ridges by modulating y with sine waves
const offset = 0.05 * Math.sin(10 * x) * Math.cos(10 * z);
capGeo.attributes.position.setY(i, y + offset);
}
capGeo.attributes.position.needsUpdate = true;
capGeo.computeVertexNormals();
group.add(cap);
return { group, stem, cap };
}
// Oyster: shelf-like caps stacked, white/grayish
function createOysterModel() {
const group = new THREE.Group();
// Stem - short stubby cylinder
const stemGeo = new THREE.CylinderGeometry(0.1, 0.15, 0.5, 12);
const stemMat = new THREE.MeshPhongMaterial({ color: mushrooms.oyster.colorStem });
const stem = new THREE.Mesh(stemGeo, stemMat);
stem.position.y = 0.25;
group.add(stem);
// Caps - multiple overlapping curved plates
const caps = [];
const capMat = new THREE.MeshPhongMaterial({ color: mushrooms.oyster.colorCap, shininess: 60, side: THREE.DoubleSide });
for (let i = 0; i < 3; i++) {
const capGeo = new THREE.CircleGeometry(0.8 - i * 0.2, 32);
// Bend the circle to create a shelf shape
for (let j = 0; j < capGeo.attributes.position.count; j++) {
const x = capGeo.attributes.position.getX(j);
const y = capGeo.attributes.position.getY(j);
// Bend along x axis
const bend = 0.3 * (1 - Math.abs(x) / 0.8);
capGeo.attributes.position.setZ(j, bend);
}
capGeo.attributes.position.needsUpdate = true;
capGeo.computeVertexNormals();
const cap = new THREE.Mesh(capGeo, capMat);
cap.position.set(0, 0.6 + i * 0.3, -0.1 * i);
cap.rotation.x = -Math.PI / 2;
caps.push(cap);
group.add(cap);
}
return { group, stem, caps };
}
// Current mushroom model parts
let currentModel = null;
// Update mushroom info panel
function updateInfo(mushroomKey) {
const m = mushrooms[mushroomKey];
mushroomName.textContent = m.name;
mushroomDescription.innerHTML = `
${m.description}
<p><strong>Habitat:</strong> ${m.habitat}</p>
<p><strong>Lifespan:</strong> ${m.lifespan}</p>
`;
}
// Remove old mushroom from scene
function clearMushroom() {
if (currentModel) {
scene.remove(currentModel.group);
mushroomGroup.remove(currentModel.group);
currentModel = null;
}
}
// Add new mushroom model to scene
function addMushroom(mushroomKey) {
clearMushroom();
const modelCreator = mushrooms[mushroomKey].model;
currentModel = modelCreator();
mushroomGroup.add(currentModel.group);
}
// Animate growth based on slider value (0-100)
function updateGrowth(stage) {
if (!currentModel) return;
const s = stage / 100;
// Different mushrooms have different growth logic
switch (mushroomSelect.value) {
case 'flyAgaric':
// Stem grows taller from 0.1 to 1
currentModel.stem.scale.y = THREE.MathUtils.lerp(0.1, 1, s);
currentModel.stem.position.y = currentModel.stem.scale.y / 2;
// Cap grows radius and height
currentModel.cap.scale.setScalar(s);
currentModel.cap.position.y = currentModel.stem.position.y + currentModel.stem.scale.y / 2 + 0.1 * s;
// Spots appear gradually
currentModel.spots.forEach((spot, i) => {
spot.visible = s > (i + 1) / currentModel.spots.length;
spot.scale.setScalar(s);
});
break;
case 'shiitake':
// Stem grows taller
currentModel.stem.scale.y = THREE.MathUtils.lerp(0.1, 1, s);
currentModel.stem.position.y = currentModel.stem.scale.y / 2;
// Cap grows from flat to full size
currentModel.cap.scale.setScalar(s);
currentModel.cap.position.y = currentModel.stem.position.y + currentModel.stem.scale.y / 2 + 0.1 * s;
break;
case 'morel':
// Stem grows taller
currentModel.stem.scale.y = THREE.MathUtils.lerp(0.1, 1, s);
currentModel.stem.position.y = currentModel.stem.scale.y / 2;
// Cap grows elongated
currentModel.cap.scale.set(1, s * 2, 1);
currentModel.cap.position.y = currentModel.stem.position.y + currentModel.stem.scale.y / 2 + 0.5 * s;
break;
case 'oyster':
// Stem grows taller
currentModel.stem.scale.y = THREE.MathUtils.lerp(0.1, 1, s);
currentModel.stem.position.y = currentModel.stem.scale.y / 2;
// Caps appear one by one and grow
currentModel.caps.forEach((cap, i) => {
if (s > i / currentModel.caps.length) {
cap.visible = true;
const localS = THREE.MathUtils.clamp((s - i / currentModel.caps.length) * currentModel.caps.length, 0, 1);
cap.scale.set(localS, localS, localS);
} else {
cap.visible = false;
}
});
break;
}
}
// Initial setup
function init() {
addMushroom(mushroomSelect.value);
updateInfo(mushroomSelect.value);
updateGrowth(lifespanSlider.value);
}
// Event listeners
mushroomSelect.addEventListener('change', () => {
addMushroom(mushroomSelect.value);
updateInfo(mushroomSelect.value);
updateGrowth(lifespanSlider.value);
});
lifespanSlider.addEventListener('input', () => {
updateGrowth(lifespanSlider.value);
});
// Handle resize
window.addEventListener('resize', () => {
camera.aspect = container.clientWidth / container.clientHeight;
camera.updateProjectionMatrix();
renderer.setSize(container.clientWidth, container.clientHeight);
});
// Animation loop
function animate() {
requestAnimationFrame(animate);
controls.update();
renderer.render(scene, camera);
}
init();
animate();
})();
</script>
</body>
</html>
How it works:
- The mushroom is built from simple geometries (cylinders, cones, spheres).
- The slider controls the scale and visibility of parts to simulate growth.
- The info panel updates with mushroom details.
- You can orbit around the mushroom with mouse drag.
Open this file in any modern browser and enjoy your interactive 3D mushroom growth simulator! If you want me to add more mushrooms or improve visuals, just ask!