Created
July 5, 2012 06:03
-
-
Save yesidays/3051660 to your computer and use it in GitHub Desktop.
Ejemplo three.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE HTML> | |
<html lang="en"> | |
<head> | |
<title>Three.js</title> | |
<meta charset="utf-8"> | |
<style type="text/css"> | |
body { | |
background-color: #FFFFFF; | |
margin: 0px; | |
overflow: hidden; | |
} | |
</style> | |
</head> | |
<body> | |
<script src="Three.js"></script> | |
<script> | |
var camera, scene, renderer, mouseX = 0, mouseY = 0, spheres = []; | |
init(); | |
function init() { | |
camera = new THREE.PerspectiveCamera(120, window.innerWidth / window.innerHeight, 1, 1500 ); | |
camera.position.z = 800; | |
scene = new THREE.Scene(); | |
scene.add(camera); | |
renderer = new THREE.CanvasRenderer(); | |
renderer.setSize( window.innerWidth, window.innerHeight ); | |
document.body.appendChild(renderer.domElement); | |
makespheres(); | |
setInterval(update, 2000 / 100); | |
} | |
function update() { | |
updatespheres(); | |
renderer.render( scene, camera ); | |
} | |
function makespheres() { | |
var sphere, material; | |
for (var zpos =- 100; zpos < 500; zpos += 50) { | |
var radius = Math.random() * 50; | |
segments = 20, rings = 10; | |
var letter = ["A", "B", "C", "D", "E", "F"]; | |
var value1 = Math.floor((Math.random()*100)+1); | |
var value2 = Math.floor((Math.random()*100)+1); | |
var vletter1 = Math.floor((Math.random()*6)+1); | |
var vletter2 = Math.floor((Math.random()*6)+1); | |
var newColor = "0x"+letter[vletter1] + letter[vletter1] + value1 + value2; | |
var sphereMaterial = new THREE.MeshLambertMaterial({ color: newColor }); | |
var sphere = new THREE.Mesh(new THREE.SphereGeometry(radius, segments, rings), sphereMaterial); | |
sphere.position.x = Math.floor((Math.random()*1000)+1); | |
sphere.position.y = Math.floor((Math.random()*1000)+1); | |
sphere.position.z = zpos * 100; | |
sphere.scale.x = sphere.scale.y = 5 ; | |
scene.add( sphere ); | |
spheres.push(sphere); | |
} | |
} | |
function updatespheres() { | |
for(var i=0; i<spheres.length; i++) { | |
sphere = spheres[i]; | |
sphere.position.z += mouseY * 0.1; | |
if(sphere.position.z > 200) sphere.position.z -= 100; | |
} | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment