Skip to content

Instantly share code, notes, and snippets.

@dalmaer
Created April 11, 2011 02:50
Show Gist options
  • Save dalmaer/913000 to your computer and use it in GitHub Desktop.
Save dalmaer/913000 to your computer and use it in GitHub Desktop.
Paul Hayes' example of spheres with CSS
var panels = p || this.panels,
rounds = r || this.rounds,
rotationPerPanel = 360/panels,
rotationPerRound = 360/2/rounds,
yRotation, xRotation,
width = this.panelWidth,
zTranslate = (width/2) / Math.tan(rotationPerPanel * Math.PI/180),
$container = this.el,
$ul, $li, i, j;
this.el.html('');
for(i = 0; i < rounds; i++) {
$ul = $('<ul>');
xRotation = rotationPerRound * i;
$ul[0].style.webkitTransform = "rotateX("+ xRotation + "deg)";
for(j = 0; j < panels; j++) {
$li = $('<li>');
yRotation = rotationPerPanel * j;
$li[0].style.webkitTransform = "rotateY("+ yRotation +"deg)
translateZ("+ zTranslate +"px)";
$ul.append($li);
}
$container.append($ul);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment