Skip to content

Instantly share code, notes, and snippets.

@clr
Created August 27, 2012 22:05
Show Gist options
  • Select an option

  • Save clr/3492764 to your computer and use it in GitHub Desktop.

Select an option

Save clr/3492764 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html lang="en">
<head>
<title>WebGLiak</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<style>
body {
color: #808080;
font-family:Monospace;
font-size:13px;
text-align:center;
background-color: #fff;
margin: 0px;
overflow: hidden;
}
</style>
</head>
<body>
<div id="container"></div>
<script src="http://mrdoob.github.com/three.js/build/three.min.js"></script>
<script src="http://mrdoob.github.com/three.js/examples/js/Detector.js"></script>
<script src="http://mrdoob.github.com/three.js/examples/js/Stats.js"></script>
<script>
if ( ! Detector.webgl ) Detector.addGetWebGLMessage();
var container, stats;
var controls, camera, scene, renderer;
var groups = [];
var mesh, group1, group2, group3, light;
var mouseX = 0, mouseY = 0;
var windowHalfX = window.innerWidth / 2;
var windowHalfY = window.innerHeight / 2;
init();
animate();
function init() {
container = document.getElementById( 'container' );
camera = new THREE.PerspectiveCamera( 20, window.innerWidth / window.innerHeight, 1, 10000 );
camera.position.z = 1800;
controls = new THREE.TrackballControls( camera );
controls.target.set( 0, 0, 0 )
scene = new THREE.Scene();
light = new THREE.DirectionalLight( 0xffffff );
light.position.set( 0, 0, 1 );
scene.add( light );
sCount = 7;
for(i = 0; i < sCount; i++){
x = Math.cos(i * (Math.PI * 2 / sCount)) * 200;
y = Math.sin(i * (Math.PI * 2 / sCount)) * 200;
createSphere(scene, x, y);
}
renderer = new THREE.WebGLRenderer( { antialias: true } );
renderer.setSize( window.innerWidth, window.innerHeight );
container.appendChild( renderer.domElement );
stats = new Stats();
stats.domElement.style.position = 'absolute';
stats.domElement.style.top = '0px';
container.appendChild( stats.domElement );
window.addEventListener( 'resize', onWindowResize, false );
}
function createSphere(scene, x, y) {
var faceIndices = [ 'a', 'b', 'c', 'd' ];
var color, f, p, n, vertexIndex,
radius = 50,
widthSegments = 27,
heightSegments = 27,
geometry = new THREE.SphereGeometry( radius, widthSegments, heightSegments );
var materials = [
new THREE.MeshLambertMaterial( { color: 0xff0000, shading: THREE.FlatShading, vertexColors: THREE.VertexColors } )
];
group = THREE.SceneUtils.createMultiMaterialObject( geometry, materials );
group.position.x = x;
group.position.y = y;
scene.add(group);
groups.push(materials);
}
function onWindowResize() {
windowHalfX = window.innerWidth / 2;
windowHalfY = window.innerHeight / 2;
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize( window.innerWidth, window.innerHeight );
}
function animate() {
requestAnimationFrame( animate );
render();
stats.update();
}
function render() {
renderer.render( scene, camera );
for(i = 0; i < groups.length; i++) {
groups[i][0].color.setRGB(Math.random(), 1, 1);
}
controls.update();
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment