Skip to content

Instantly share code, notes, and snippets.

@wagenet
Created September 3, 2010 21:52
Show Gist options
  • Save wagenet/564626 to your computer and use it in GitHub Desktop.
Save wagenet/564626 to your computer and use it in GitHub Desktop.
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Morphing Power Cubes</title>
<style type="text/css" media="screen">
body {
background-color: black;
color: white;
font-family: 'Lucida Grande', Verdana, Arial;
font-size: 12px;
}
#container {
width: 100%;
height: 700px;
-webkit-perspective: 800; /* For compatibility with iPhone 3.0, we leave off the units here */
-webkit-perspective-origin: 50% 250px;
}
#stage {
overflow: hidden;
margin: 0 auto;
-webkit-transition: -webkit-transform 2s;
-webkit-transform-style: preserve-3d;
}
#shape {
position: relative;
margin: 0 auto;
-webkit-transform-style: preserve-3d;
}
.plane {
position: absolute;
-webkit-backface-visibility: hidden;
}
#shape {
-webkit-animation: spin 30s infinite linear;
}
@-webkit-keyframes spin {
from { -webkit-transform: rotateY(0); }
to { -webkit-transform: rotateY(-360deg); }
}
</style>
<script type="text/javascript">
var SEGMENTS = 36,
Y_SCALE = 2,
R_SCALE = 0.98;
function init(){
var stage = document.getElementById('stage'),
shape = document.getElementById('shape'),
img = new Image(),
idx, plane, ctx;
//img.src = 'http://yuiblog.com/assets/slicing/img/pan6.jpg';
img.src = 'http://www.gdargaud.net/Antarctica/Bases/PanoDdU.jpg';
var sW = Math.floor(img.width / SEGMENTS),
pW = sW * Y_SCALE,
h = img.height,
r = Math.floor((pW * SEGMENTS) / (2*Math.PI)) * R_SCALE, // Shrink slightly to avoid gaps
vW = r * 1.6;
stage.style.width = vW+'px';
stage.style.height = h+'px';
shape.style.width = pW+'px';
shape.style.height = h+'px';
for (idx=0; idx < SEGMENTS; idx++) {
plane = document.createElement('canvas');
plane.width = pW;
plane.height = h;
plane.style.width = pW;
plane.style.width = h;
ctx = plane.getContext('2d');
ctx.drawImage(img, (SEGMENTS-1-idx)*sW, 0, sW, h, 0, 0, pW, h);
plane.className = 'plane';
plane.style.webkitTransform = 'rotateY('+((360/SEGMENTS)*idx)+'deg) translateZ(-'+r+'px)';
shape.appendChild(plane);
}
};
window.addEventListener('load', init);
</script>
</head>
<body>
<div id="container">
<div id="stage">
<div id="shape" class="ring">
</div>
</div>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment