Liveweave: Generative AI Web Editor & HTML/CSS/JS Playground
Initializing
Liveweave
Web
expand_more
home
Home
Palette
Color Explorer
arrow_outward
Polyline
Graphics Editor
arrow_outward
frame_source
Python Playground
arrow_outward
build
Tools
expand_more
restart_alt
Load "Hello Weaver!"
post_add
Generate Lorem ipsum...
code
Format HTML
code_blocks
Format CSS
data_object
Format JavaScript
library_add
Library
expand_more
A
Algolia JS
Animate CSS
Apex Charts JS
B
Bulma CSS
Bootstrap
C
Chart JS
Chartist
Create JS
D
D3
Dojo
F
Foundation
Fullpage JS
G
Granim JS
Google Charts
H
Halfmoon
J
jQuery
M
Materialize
Moment JS
Masonry JS
Milligram CSS
P
Pure CSS
Primer CSS
Popper JS
Pattern CSS
Picnic CSS
R
React JS
Raphael JS
Raisin CSS
S
Semantic UI
Skeleton CSS
Spectre CSS
Tachyons CSS
T
Tailwind
Three JS
U
UI Kit
Vis JS
W
Water CSS
download
Download
expand_more
developer_mode
Download as HTML
folder_zip
Download as .ZIP
cloud_upload
Fork
account_circle
Login
settings
Settings
expand_more
Editor font
14
px
A
A
Night mode
Line number
Mini map
Word wrap
sync_alt
Reset Settings
smart_display
Run
left_panel_close
AI Assistant
dashboard
All
HTML
CSS
JS
visibility
Preview
bolt
Live Preview
terminal
JS Console
<!DOCTYPE html> <html> <head> <title>3D sculpture morphing demo</title> <script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script> </head> <body> <!-- Start your code here --> <div id="art"></div> <!-- End your code here --> </body> </html>
* { margin: 0; padding: 0; box-sizing: border-box; } html, body { width: 100%; height: 100%; overflow: hidden; background: #03040a; } #art { position: fixed; inset: 0; overflow: hidden; cursor: crosshair; } #art canvas { display: block; width: 100%; height: 100%; }
(() => { const container = document.getElementById("art"); const scene = new THREE.Scene(); scene.background = new THREE.Color(0x03040a); scene.fog = new THREE.FogExp2(0x03040a, 0.022); const camera = new THREE.PerspectiveCamera( 42, window.innerWidth / window.innerHeight, 0.1, 100 ); camera.position.set(0, 0, 15); const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: false, powerPreference: "high-performance" }); renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.7)); renderer.setSize(window.innerWidth, window.innerHeight); renderer.outputEncoding = THREE.sRGBEncoding; renderer.toneMapping = THREE.ACESFilmicToneMapping; renderer.toneMappingExposure = 1.25; container.appendChild(renderer.domElement); scene.add(new THREE.AmbientLight(0x6677bb, 0.65)); const lightA = new THREE.PointLight(0x5d8aff, 35, 40); lightA.position.set(5, 4, 7); scene.add(lightA); const lightB = new THREE.PointLight(0xff4ca6, 30, 35); lightB.position.set(-5, -3, 5); scene.add(lightB); const lightC = new THREE.PointLight(0x55ffe0, 25, 30); lightC.position.set(0, 5, -5); scene.add(lightC); const sculpture = new THREE.Group(); scene.add(sculpture); const mouse = new THREE.Vector2(0, 0); const targetMouse = new THREE.Vector2(0, 0); let time = 0; let pulse = 0; let transformation = 0; let transformationTarget = 0; const ribbons = []; const ribbonCount = 9; const segments = 110; const widthSegments = 10; const materials = [ new THREE.MeshPhysicalMaterial({ color: 0x8c7aff, metalness: 0.65, roughness: 0.19, clearcoat: 1, clearcoatRoughness: 0.08, side: THREE.DoubleSide }), new THREE.MeshPhysicalMaterial({ color: 0x38d9e9, metalness: 0.55, roughness: 0.16, clearcoat: 1, side: THREE.DoubleSide }), new THREE.MeshPhysicalMaterial({ color: 0xf15aa9, metalness: 0.55, roughness: 0.2, clearcoat: 1, side: THREE.DoubleSide }), new THREE.MeshPhysicalMaterial({ color: 0xffc56d, metalness: 0.7, roughness: 0.22, clearcoat: 1, side: THREE.DoubleSide }) ]; function createRibbon(index) { const geometry = new THREE.BufferGeometry(); const vertexCount = (segments + 1) * (widthSegments + 1); const positions = new Float32Array(vertexCount * 3); const uvs = new Float32Array(vertexCount * 2); const indices = []; for (let i = 0; i <= segments; i++) { for (let j = 0; j <= widthSegments; j++) { const k = i * (widthSegments + 1) + j; uvs[k * 2] = i / segments; uvs[k * 2 + 1] = j / widthSegments; if (i < segments && j < widthSegments) { const a = k; const b = k + widthSegments + 1; const c = b + 1; const d = a + 1; indices.push(a, b, d, b, c, d); } } } geometry.setAttribute( "position", new THREE.BufferAttribute(positions, 3) ); geometry.setAttribute( "uv", new THREE.BufferAttribute(uvs, 2) ); geometry.setIndex(indices); const mesh = new THREE.Mesh( geometry, materials[index % materials.length] ); mesh.frustumCulled = false; sculpture.add(mesh); ribbons.push({ mesh, positions, phase: index * Math.PI * 2 / ribbonCount, width: 0.28 + Math.random() * 0.18, speed: 0.6 + Math.random() * 0.5, index }); } for (let i = 0; i < ribbonCount; i++) { createRibbon(i); } // Fine luminous filaments around the sculpture. const filamentMaterial = new THREE.LineBasicMaterial({ color: 0x91aaff, transparent: true, opacity: 0.18, blending: THREE.AdditiveBlending }); const filaments = []; for (let i = 0; i < 5; i++) { const points = []; const radius = 4.2 + i * 0.28; for (let j = 0; j <= 180; j++) { const a = j / 180 * Math.PI * 2; points.push(new THREE.Vector3( Math.cos(a) * radius, Math.sin(a) * radius * 0.68, Math.sin(a * 3 + i) * 0.4 )); } const curve = new THREE.CatmullRomCurve3(points); const line = new THREE.Line( new THREE.BufferGeometry().setFromPoints(curve.getPoints(240)), filamentMaterial ); sculpture.add(line); filaments.push(line); } // Tiny background stars. const starCount = 650; const starPositions = new Float32Array(starCount * 3); for (let i = 0; i < starCount; i++) { starPositions[i * 3] = (Math.random() - 0.5) * 45; starPositions[i * 3 + 1] = (Math.random() - 0.5) * 30; starPositions[i * 3 + 2] = (Math.random() - 0.5) * 25; } const starGeometry = new THREE.BufferGeometry(); starGeometry.setAttribute( "position", new THREE.BufferAttribute(starPositions, 3) ); const stars = new THREE.Points( starGeometry, new THREE.PointsMaterial({ color: 0x7788bb, size: 0.025, transparent: true, opacity: 0.55, sizeAttenuation: true }) ); scene.add(stars); function ribbonPoint(t, v, ribbon, out) { const phase = ribbon.phase; const index = ribbon.index; const morph = transformation; const distortion = pulse; const angle = t * Math.PI * 2; const wave = Math.sin(angle * 3 + phase + time * 0.7); const wave2 = Math.cos(angle * 2 - phase + time * 0.45); const radius = 2.25 + Math.sin(angle * 2 + phase) * 0.75 + Math.sin(angle * 5 - phase + time * 0.3) * 0.3; const twist = angle * (1.1 + morph * 2.2) + phase; const centerX = Math.cos(angle + phase * 0.12) * radius; const centerY = Math.sin(angle + phase * 0.12) * radius * 0.75; const centerZ = wave * 1.45 + wave2 * 0.55; const nextAngle = angle + 0.002; const nextRadius = 2.25 + Math.sin(nextAngle * 2 + phase) * 0.75 + Math.sin(nextAngle * 5 - phase + time * 0.3) * 0.3; const nextX = Math.cos(nextAngle + phase * 0.12) * nextRadius; const nextY = Math.sin(nextAngle + phase * 0.12) * nextRadius * 0.75; const nextZ = Math.sin(nextAngle * 3 + phase + time * 0.7) * 1.45 + Math.cos(nextAngle * 2 - phase + time * 0.45) * 0.55; let tx = nextX - centerX; let ty = nextY - centerY; let tz = nextZ - centerZ; const tl = Math.sqrt(tx * tx + ty * ty + tz * tz) || 1; tx /= tl; ty /= tl; tz /= tl; let nx = -ty; let ny = tx; let nz = 0; const nl = Math.sqrt(nx * nx + ny * ny) || 1; nx /= nl; ny /= nl; const bx = ty * nz - tz * ny; const by = tz * nx - tx * nz; const bz = tx * ny - ty * nx; const width = ribbon.width * (0.3 + Math.pow(Math.sin(Math.PI * t), 0.55)) * (0.75 + Math.sin(angle * 4 + phase + time) * 0.22); const across = (v - 0.5) * 2; const fold = Math.sin(twist + across * 2.3 + time * ribbon.speed); const ripple = Math.cos(angle * 7 + across * 4 + phase + time); const bend = mouse.x * Math.sin(angle + phase) * 0.6; const lift = mouse.y * Math.cos(angle * 1.5 + phase) * 0.6; const deformation = 1 + morph * Math.sin(angle * 4 + phase); out.x = centerX * deformation + nx * across * width * 3.2; out.y = centerY * deformation + ny * across * width * 3.2; out.z = centerZ + across * width * fold * 2.8; out.x += nx * fold * 0.22 + bend; out.y += ny * fold * 0.22 + lift; out.z += ripple * 0.14 + distortion * Math.sin(angle * 2 + phase) * 0.4; } const temp = new THREE.Vector3(); function updateRibbon(ribbon) { const array = ribbon.positions; for (let i = 0; i <= segments; i++) { const t = i / segments; for (let j = 0; j <= widthSegments; j++) { const v = j / widthSegments; const index = (i * (widthSegments + 1) + j) * 3; ribbonPoint(t, v, ribbon, temp); array[index] = temp.x; array[index + 1] = temp.y; array[index + 2] = temp.z; } } ribbon.mesh.geometry.attributes.position.needsUpdate = true; ribbon.mesh.geometry.computeVertexNormals(); } function animate() { requestAnimationFrame(animate); const delta = Math.min(clockDelta.getDelta(), 0.035); time += delta; mouse.lerp(targetMouse, 0.035); pulse *= 0.965; transformation += (transformationTarget - transformation) * 0.025; ribbons.forEach(updateRibbon); sculpture.rotation.y += delta * 0.09; sculpture.rotation.x = Math.sin(time * 0.22) * 0.12 + mouse.y * 0.12; sculpture.rotation.z = Math.sin(time * 0.18) * 0.08 + mouse.x * 0.1; const scale = 1 + Math.sin(time * 0.8) * 0.025 + pulse * 0.2; sculpture.scale.setScalar(scale); lightA.position.x = 5 + mouse.x * 3; lightB.position.y = -3 + mouse.y * 3; stars.rotation.y += delta * 0.003; stars.rotation.x = mouse.y * 0.015; renderer.render(scene, camera); } const clockDelta = new THREE.Clock(); renderer.domElement.addEventListener("pointermove", event => { const rect = renderer.domElement.getBoundingClientRect(); targetMouse.x = ((event.clientX - rect.left) / rect.width - 0.5) * 2; targetMouse.y = -((event.clientY - rect.top) / rect.height - 0.5) * 2; }); renderer.domElement.addEventListener("pointerleave", () => { targetMouse.set(0, 0); }); renderer.domElement.addEventListener("click", () => { pulse = 1; transformationTarget = transformationTarget > 0.5 ? 0 : 1; }); window.addEventListener("resize", () => { camera.aspect = window.innerWidth / window.innerHeight; camera.updateProjectionMatrix(); renderer.setSize(window.innerWidth, window.innerHeight); }); animate(); })();
terminal
JavaScript Console
Preview
Clear
close
›
Run