* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
background: #0f172a;
overflow: hidden;
}
#canvas-container {
width: 100vw;
height: 100vh;
position: relative;
}
.ui-overlay {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
pointer-events: none;
z-index: 10;
}
.header {
position: absolute;
top: 30px;
left: 50%;
transform: translateX(-50%);
background: rgba(15, 23, 42, 0.95);
backdrop-filter: blur(10px);
padding: 16px 28px;
border-radius: 50px;
color: white;
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
border: 1px solid rgba(255, 255, 255, 0.1);
pointer-events: auto;
text-align: center;
}
.title {
font-size: 24px;
font-weight: 700;
margin-bottom: 4px;
background: linear-gradient(135deg, #60a5fa, #a78bfa);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-clip: text;
}
.subtitle {
font-size: 13px;
color: #94a3b8;
}
.controls {
position: absolute;
bottom: 30px;
left: 50%;
transform: translateX(-50%);
display: flex;
gap: 12px;
background: rgba(15, 23, 42, 0.9);
backdrop-filter: blur(10px);
padding: 16px;
border-radius: 50px;
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
border: 1px solid rgba(255, 255, 255, 0.1);
pointer-events: auto;
}
.control-btn {
width: 48px;
height: 48px;
border-radius: 50%;
background: rgba(59, 130, 246, 0.2);
border: 2px solid rgba(59, 130, 246, 0.3);
color: #60a5fa;
display: flex;
align-items: center;
justify-content: center;
cursor: pointer;
transition: all 0.3s;
font-size: 24px;
}
.control-btn:hover {
background: rgba(59, 130, 246, 0.4);
border-color: rgba(59, 130, 246, 0.6);
transform: scale(1.1);
}
.control-btn.active {
background: rgba(59, 130, 246, 0.6);
border-color: #3b82f6;
color: white;
}
.info-panel {
position: absolute;
top: 30px;
right: 30px;
background: rgba(15, 23, 42, 0.9);
backdrop-filter: blur(10px);
padding: 20px;
border-radius: 16px;
color: white;
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
border: 1px solid rgba(255, 255, 255, 0.1);
min-width: 200px;
pointer-events: auto;
}
.info-title {
font-size: 14px;
font-weight: 600;
color: #60a5fa;
margin-bottom: 12px;
text-transform: uppercase;
}
.info-item {
display: flex;
justify-content: space-between;
padding: 8px 0;
font-size: 13px;
border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}
.info-item:last-child {
border-bottom: none;
}
.info-label {
color: #94a3b8;
}
.info-value {
color: #e2e8f0;
font-weight: 600;
}
.settings-panel {
position: absolute;
bottom: 30px;
right: 30px;
background: rgba(15, 23, 42, 0.9);
backdrop-filter: blur(10px);
padding: 20px;
border-radius: 16px;
color: white;
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
border: 1px solid rgba(255, 255, 255, 0.1);
min-width: 250px;
pointer-events: auto;
}
.setting-group {
margin-bottom: 20px;
}
.setting-group:last-child {
margin-bottom: 0;
}
.setting-label {
font-size: 12px;
color: #94a3b8;
margin-bottom: 8px;
text-transform: uppercase;
font-weight: 600;
}
.slider-container {
display: flex;
align-items: center;
gap: 12px;
}
.slider {
flex: 1;
height: 6px;
border-radius: 3px;
background: rgba(59, 130, 246, 0.2);
outline: none;
-webkit-appearance: none;
}
.slider::-webkit-slider-thumb {
-webkit-appearance: none;
width: 16px;
height: 16px;
border-radius: 50%;
background: #3b82f6;
cursor: pointer;
box-shadow: 0 2px 8px rgba(59, 130, 246, 0.4);
}
.slider::-moz-range-thumb {
width: 16px;
height: 16px;
border-radius: 50%;
background: #3b82f6;
cursor: pointer;
border: none;
}
.slider-value {
min-width: 40px;
text-align: right;
font-size: 12px;
color: #60a5fa;
font-weight: 600;
}
.mode-buttons {
display: flex;
gap: 8px;
}
.mode-btn {
flex: 1;
padding: 10px;
background: rgba(59, 130, 246, 0.2);
border: 2px solid rgba(59, 130, 246, 0.3);
color: #60a5fa;
border-radius: 8px;
font-size: 12px;
font-weight: 600;
cursor: pointer;
transition: all 0.3s;
}
.mode-btn:hover {
background: rgba(59, 130, 246, 0.3);
}
.mode-btn.active {
background: rgba(59, 130, 246, 0.6);
border-color: #3b82f6;
color: white;
}
.instructions {
position: absolute;
bottom: 30px;
left: 30px;
background: rgba(15, 23, 42, 0.9);
backdrop-filter: blur(10px);
padding: 16px 20px;
border-radius: 16px;
color: white;
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
border: 1px solid rgba(255, 255, 255, 0.1);
max-width: 200px;
font-size: 12px;
color: #94a3b8;
pointer-events: auto;
}
@media (max-width: 768px) {
.header,
.info-panel,
.instructions {
display: none;
}
.settings-panel {
bottom: 100px;
right: 20px;
left: 20px;
min-width: auto;
}
.controls {
bottom: 20px;
}
}
let scene, camera, renderer, mesh, geometry, material;
let mouseX = 0, mouseY = 0;
let targetRotationX = 0, targetRotationY = 0;
let isAutoRotating = false;
let currentMode = 'plane';
let depthValue = 0.5;
let segmentCount = 50;
const container = document.getElementById('canvas-container');
function init() {
// Scene
scene = new THREE.Scene();
scene.background = new THREE.Color(0x0f172a);
// Camera
camera = new THREE.PerspectiveCamera(
75,
window.innerWidth / window.innerHeight,
0.1,
1000
);
camera.position.z = 5;
// Renderer
renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(window.devicePixelRatio);
container.appendChild(renderer.domElement);
// Lighting
const ambientLight = new THREE.AmbientLight(0xffffff, 0.6);
scene.add(ambientLight);
const directionalLight = new THREE.DirectionalLight(0xffffff, 0.8);
directionalLight.position.set(5, 5, 5);
scene.add(directionalLight);
// Create 3D image
createImage();
// Event listeners
document.addEventListener('mousemove', onMouseMove);
document.addEventListener('wheel', onWheel, { passive: false });
window.addEventListener('resize', onResize);
// Controls
document.getElementById('rotateBtn').addEventListener('click', toggleAutoRotate);
document.getElementById('resetBtn').addEventListener('click', resetView);
document.getElementById('wireframeBtn').addEventListener('click', toggleWireframe);
document.getElementById('depthSlider').addEventListener('input', updateDepth);
document.getElementById('segmentSlider').addEventListener('input', updateSegments);
// Mode buttons
document.querySelectorAll('.mode-btn').forEach(btn => {
btn.addEventListener('click', (e) => {
document.querySelectorAll('.mode-btn').forEach(b => b.classList.remove('active'));
e.target.classList.add('active');
currentMode = e.target.dataset.mode;
createImage();
});
});
animate();
}
function createImage() {
if (mesh) {
scene.remove(mesh);
geometry.dispose();
material.dispose();
}
// Load texture
const loader = new THREE.TextureLoader();
const texture = loader.load('https://images.unsplash.com/photo-1506905925346-21bda4d32df4?w=1200&h=800&fit=crop');
// Create geometry based on mode
if (currentMode === 'plane') {
geometry = new THREE.PlaneGeometry(4, 3, segmentCount, segmentCount);
applyDepthToPlane();
} else if (currentMode === 'sphere') {
geometry = new THREE.SphereGeometry(2, segmentCount, segmentCount);
} else if (currentMode === 'wave') {
geometry = new THREE.PlaneGeometry(4, 3, segmentCount, segmentCount);
applyWaveEffect();
}
material = new THREE.MeshPhongMaterial({
map: texture,
side: THREE.DoubleSide
});
mesh = new THREE.Mesh(geometry, material);
scene.add(mesh);
}
function applyDepthToPlane() {
const positions = geometry.attributes.position;
for (let i = 0; i < positions.count; i++) {
const x = positions.getX(i);
const y = positions.getY(i);
const distance = Math.sqrt(x * x + y * y);
const z = Math.sin(distance * 0.5) * depthValue;
positions.setZ(i, z);
}
positions.needsUpdate = true;
geometry.computeVertexNormals();
}
function applyWaveEffect() {
const positions = geometry.attributes.position;
const time = Date.now() * 0.001;
for (let i = 0; i < positions.count; i++) {
const x = positions.getX(i);
const y = positions.getY(i);
const z = Math.sin(x * 2 + time) * 0.3 + Math.cos(y * 2 + time) * 0.3;
positions.setZ(i, z * depthValue);
}
positions.needsUpdate = true;
geometry.computeVertexNormals();
}
function onMouseMove(e) {
mouseX = (e.clientX / window.innerWidth) * 2 - 1;
mouseY = -(e.clientY / window.innerHeight) * 2 + 1;
if (!isAutoRotating) {
targetRotationX = mouseY * Math.PI * 0.3;
targetRotationY = mouseX * Math.PI * 0.3;
}
}
function onWheel(e) {
e.preventDefault();
camera.position.z += e.deltaY * 0.01;
camera.position.z = Math.max(2, Math.min(10, camera.position.z));
document.getElementById('zoomLevel').textContent = camera.position.z.toFixed(1);
}
function onResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
}
function toggleAutoRotate() {
isAutoRotating = !isAutoRotating;
const btn = document.getElementById('rotateBtn');
btn.classList.toggle('active');
}
function resetView() {
targetRotationX = 0;
targetRotationY = 0;
camera.position.z = 5;
isAutoRotating = false;
document.getElementById('rotateBtn').classList.remove('active');
document.getElementById('zoomLevel').textContent = '5.0';
}
function toggleWireframe() {
material.wireframe = !material.wireframe;
document.getElementById('wireframeBtn').classList.toggle('active');
}
function updateDepth(e) {
depthValue = parseFloat(e.target.value);
document.getElementById('depthValue').textContent = depthValue.toFixed(1);
createImage();
}
function updateSegments(e) {
segmentCount = parseInt(e.target.value);
document.getElementById('segmentValue').textContent = segmentCount;
createImage();
}
function animate() {
requestAnimationFrame(animate);
if (mesh) {
if (isAutoRotating) {
mesh.rotation.x += 0.005;
mesh.rotation.y += 0.01;
} else {
mesh.rotation.x += (targetRotationX - mesh.rotation.x) * 0.05;
mesh.rotation.y += (targetRotationY - mesh.rotation.y) * 0.05;
}
if (currentMode === 'wave') {
applyWaveEffect();
}
// Update info panel
const rotX = (mesh.rotation.x * 180 / Math.PI) % 360;
const rotY = (mesh.rotation.y * 180 / Math.PI) % 360;
document.getElementById('rotationX').textContent = Math.round(rotX) + '°';
document.getElementById('rotationY').textContent = Math.round(rotY) + '°';
}
renderer.render(scene, camera);
}
init();
Impressive 😍