Skip to content

Instantly share code, notes, and snippets.

@toto-castaldi
Last active October 13, 2015 21:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save toto-castaldi/64e5dd9abed0a2140563 to your computer and use it in GitHub Desktop.
Save toto-castaldi/64e5dd9abed0a2140563 to your computer and use it in GitHub Desktop.
three.js mesh sphere scaling with a Math.sin
<body></body>
<script src="http://gamingJS.com/Three.js"></script>
<script src="http://gamingJS.com/ChromeFixes.js"></script>
<script src="http://gamingJS.com/Tween.js"></script>
<script>
var scene = new THREE.Scene();
var width = window.innerWidth - 20;
var height = window.innerHeight - 20;
var aspect_ratio = width / height;
var camera = new THREE.PerspectiveCamera(75, aspect_ratio, 1, 10000);
camera.position.z = 500;
scene.add(camera);
var renderer = new THREE.WebGLRenderer();
renderer.shadowMapEnabled = true;
renderer.setSize(width, height);
document.body.appendChild(renderer.domElement);
//##############################################
var cover = new THREE.MeshNormalMaterial();
var sphereShape = new THREE.SphereGeometry(100, 20, 15);
var sphereMesh = new THREE.Mesh(sphereShape, cover);
scene.add(sphereMesh);
var clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
var t = clock.getElapsedTime();
sphereMesh.scale.x = Math.sin(clock.getElapsedTime()*5) * 2;;
renderer.render(scene, camera);
}
animate();
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment