Initializing
Liveweave
Web
expand_more
home
Home
data_object
CSS Explorer
arrow_outward
Palette
Color Explorer
arrow_outward
Polyline
Graphics Editor
arrow_outward
outbox_alt
Generative AI
arrow_outward
frame_source
Python Playground
New
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
Save
account_circle
Login
settings
Settings
expand_more
14
px
Live mode
Night mode
Line number
Mini map
Word wrap
sync_alt
Reset Settings
smart_display
Run
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8" /> <meta name='HandheldFriendly' content='True' /> <meta name='viewport' content='width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0' /> <title>Sprite3D - canvas demo</title> <!-- Paul Irish's cross-browser RequestAnimationFrame technique --> <script type="text/javascript" src="http://minimal.be/lab/Sprite3D/js/RequestAnimationFrame.js"></script> <!-- Grant Skinner's Tween engine --> <script type="text/javascript" src="http://minimal.be/lab/Sprite3D/js/Tween.js"></script> <!-- Robert Penner's easing equations --> <script type="text/javascript" src="http://minimal.be/lab/Sprite3D/js/Easing.js"></script> <!-- mr doob's Stats engine --> <script type="text/javascript" src="http://minimal.be/lab/Sprite3D/js/Stats.js"></script> <!-- boblemarin's Sprite3D utility class --> <script src="http://minimal.be/lab/Sprite3D/js/Sprite3D.js" type="text/javascript"></script> </head> <body onload="init();"> <div id="debug"></div> </body> </html>
html, body { height: 100%; } body { background-color: black; color: white; margin: 0px; padding: 0px; overflow: hidden; /* background: -webkit-gradient(radial, 50% 50%, 500, 50% 50%, 59, from(#000000), to(#7A7A7A)) */ } #debug { color: #FFF; position: absolute; bottom: 0px; left: 0px; width: 100%; text-align: center; font-family: courier; } .box { background-color: rgba( 43, 79, 211, .1 ); } .star { background-color: #8888AA; width: 2px; height: 2px; /* border: 1px solid black;*/ }
var debug, stage, container, slices = [], numSlices = 40, currentSlice = -1, sliceWidth = 800, sliceHeight = 100, lastTime, zStep = 100, zOffset = 0, zSpeed = 3000, i, x = 0, y = 0, r = 0, path, np = 20, xStep; function init() { debug = document.getElementById("debug"); // create a centered 3D stage and a container stage = Sprite3D.createCenteredContainer(); container = stage.addChild( new Sprite3D() ).setZ( 500 ).setRotateFirst(false).update(); path = []; for( i = 0; i < np; i++ ) path.push( sliceHeight >> 1 ); xStep = sliceWidth / (np-1); starContainer = stage.addChild( new Sprite3D() ); for( i = 0; i < 25; i++ ) { starContainer.addChild( new Sprite3D() .setClassName("star") .setRotateFirst(true) .setRotation( Math.random() * 360, Math.random() * 360, Math.random() * 360 ) .setPosition( 0, 0, 800 ) .update() ); } var canvas; for( i = 0; i < numSlices; i++ ) { // create an <canvas> element, wraps a sprite around, and save the reference to its context canvas = document.createElement('canvas'); canvas.width = sliceWidth; canvas.height = sliceHeight; container.addChild( new Sprite3D(canvas) .setClassName("box") .setRegistrationPoint(sliceWidth>>1, sliceHeight>>1, 0) .setPosition( 0, 0, i * -zStep ) .setProperty( 'context', canvas.getContext('2d') ) .setRotateFirst( false ) .update() ); } //msg( numSlices + ' wrapped canvas objects'); stats = new Stats(); stats.domElement.style.position = 'absolute'; stats.domElement.style.top = '0px'; document.body.appendChild(stats.domElement); // keep track of the time to tick the tween engine lastTime = new Date().getTime(); moveXYAgain() document.addEventListener( "touchstart", onTouchStart ); document.addEventListener( "touchmove", onTouchMove ); document.addEventListener( "mousemove", onMouseMove ); animate(); } function onMouseMove( event ) { var dx = ( event.pageX / window.innerWidth - .5 ); var dy = ( event.pageY / window.innerHeight - .5 ); container.x = dx * -1200; container.y = dy * -900; //starContainer.rotationZ = container.rotationZ = dx * 120; //event.preventDefault(); } function onTouchMove( event ) { var t = event.changedTouches[0]; var dx = ( t.pageX / window.innerWidth - .5 ); var dy = ( t.pageY / window.innerHeight - .5 ); container.x = dx * 1600; container.y = dy * 1000; //starContainer.rotationZ = container.rotationZ = dx * 120; event.preventDefault(); } function onTouchStart( event ) { var t = event.changedTouches[0]; var dx = ( t.pageX / window.innerWidth - .5 ); var dy = ( t.pageY / window.innerHeight - .5 ); container.x = dx * 1600; container.y = dy * 1000; //starContainer.rotationZ = container.rotationZ = dx * 120; event.preventDefault(); } function moveXYAgain() { // when the tween is over, start a new one to a random position, // and again, call this function when it's done Tween.get( this, false).to({ x: ( Math.random() - .5 ) * 1800, y: ( Math.random() - .5 ) * 1200 },Math.random()*1000+400,Easing.Quadratic.EaseInOut).call(moveXYAgain); } function animate() { requestAnimationFrame( animate ); update(); } function update() { // manually compute the elapsed time since last screen refresh, // achieving time-based rather than frame-based animation var newTime = new Date().getTime(), delta = ( newTime - lastTime ) *2; Tween.tick( newTime - lastTime ); lastTime = newTime; zOffset += delta; if ( zOffset >= zStep ) { r += Math.random() * 4; zOffset -= zStep; currentSlice = ++currentSlice % numSlices; var t = (zStep)*(numSlices); draw( container.children[currentSlice].context ); container.children[currentSlice] .setX(x) .setY(y) .setRotationZ(r); if ( currentSlice == 0 ) { // rotation de tout container.moveZ( delta - t ); for( i = 1; i < numSlices; i++ ) container.children[i].moveZ( t ); } else { container.moveZ( delta ); container.children[currentSlice].moveZ( -t ); } container.updateWithChildren(); } else { container .moveZ( delta ) .update(); } starContainer.rotateY(.03).update(); stats.update(); } function draw( ctx ) { var v; // mutate and draw ctx.clearRect( 0, 0, sliceWidth, sliceHeight ); ctx.lineWidth = 4; ctx.strokeStyle = "rgba( 255, 255, 255, .3 )"; ctx.beginPath(); // first point v = path[0]; v += ( Math.random() - .5 ) * 16; v = v < 0 ? 0 : v > sliceHeight ? sliceHeight : v; ctx.moveTo( 0, sliceHeight - v ); path[0] = v; for( i = 1; i < np; i++ ) { v = path[i]; v += ( Math.random() - .5 ) * 16; v = v < 0 ? 0 : v > sliceHeight ? sliceHeight : v; ctx.lineTo( (i+1) * xStep, sliceHeight - v ); path[i] = v; } ctx.stroke(); } function msg( t ) { debug.innerHTML = t; }