Maison > Article > interface Web > Le canevas HTML5 permet d'obtenir des compétences de didacticiel effect_html5 dans la danse des flocons de neige en 3D
var conteneur;
var particule;
var caméra;
var scène;
var renderer;
var sourisX = 0;
var sourisY = 0;
var windowHalfX = window.innerWidth / 2;
var windowHalfY = window.innerHeight / 2;
var particules = [];
var particuleImage = new Image();//THREE.ImageUtils.loadTexture( "img/ParticleSmoke.png" );
particuleImage.src = 'images/ParticleSmoke.png';
function init() {
conteneur = document.createElement('div');
document.body.appendChild(container);
camera = new THREE.PerspectiveCamera( 75, SCREEN_WIDTH / SCREEN_HEIGHT, 1, 10000 );
camera.position.z = 1000;
scene = new THREE.Scene();
scene.add(camera);
renderer = new THREE.CanvasRenderer();
renderer.setSize(SCREEN_WIDTH, SCREEN_HEIGHT);
var materials = new THREE.ParticleBasicMaterial( { map: new THREE.Texture(particleImage) } );
for (var i = 0; i < 500; i ) {
particule = new Particle3D( matériau);
particule.position.x = Math.random() * 2000 - 1000;
particule.position.y = Math.random() * 2000 - 1000;
particule .position.z = Math.random() * 2000 - 1000;
particule.scale.x = particule.scale.y = 1;
scene.add( particule );
particules. pousser(particule);
}
conteneur.appendChild( renderer.domElement );
document.addEventListener( 'mousemove', onDocumentMouseMove, false );
document.addEventListener( 'touchstart', onDocumentTouchStart, false );
document.addEventListener( 'touchmove', onDocumentTouchMove, false );
setInterval( boucle, 1000 / 60 );
}
function onDocumentMouseMove( événement ) {
mouseX = event.clientX - windowHalfX;
mouseY = event.clientY - windowHalfY;
}
function onDocumentTouchStart( événement ) {
si ( event.touches.length == 1 ) {
event.preventDefault();
mouseX = event.touches[ 0 ].pageX - windowHalfX;
mouseY = event.touches[ 0 ].pageY - windowHalfY;
}
}
function onDocumentTouchMove( événement ) {
si ( event.touches.length == 1 ) {
event.preventDefault();
mouseX = event.touches[ 0 ].pageX - windowHalfX;
mouseY = event.touches[ 0 ].pageY - windowHalfY;
}
}
//
fonction boucle() {
for(var i = 0; i
var particule = particules[i];
particule.updatePhysics();
avec(particle.position)
{
if(y<-1000) y =2000;
si(x>1000) x-=2000;
sinon if(x<-1000) x =2000;
si(z>1000) z-=2000;
sinon if(z<-1000) z =2000;
}
}
camera.position.x = ( mouseX - camera.position.x ) * 0.05;
camera.position.y = ( - mouseY - camera.position.y ) * 0.05;
camera.lookAt(scene.position);
renderer.render( scène, caméra );
}