Skip to content

Instantly share code, notes, and snippets.

@1wheel
Last active August 22, 2016 03:06
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 1wheel/0ef8f288bd82bc361143 to your computer and use it in GitHub Desktop.
Save 1wheel/0ef8f288bd82bc361143 to your computer and use it in GitHub Desktop.
threejs-stars
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style>
body {
background-color: #ffffff;
margin: 0;
overflow: hidden;
}
</style>
</head>
<body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r73/three.min.js"></script>
<script>
var camera, scene, renderer;
var geometry, material, mesh;
function setup() {
var W = window.innerWidth, H = window.innerHeight;
renderer = new THREE.WebGLRenderer();
renderer.setSize( W, H );
document.body.appendChild( renderer.domElement );
camera = new THREE.PerspectiveCamera( 50, W/H, 1, 10000 );
camera.position.z = 500;
scene = new THREE.Scene();
// paste your code from the geometryGUI here
geometry = new THREE.Geometry();
for ( i = 0; i < 10; i ++ ) {
var vertex = new THREE.Vector3();
vertex.x = Math.round((1000 * Math.random() - 500)/20)*20;
vertex.y = Math.round((1000 * Math.random() - 500)/20)*20;
vertex.z = Math.round((1000 * Math.random() - 500)/20)*20;
geometry.vertices.push( vertex );
}
material = new THREE.PointsMaterial( { size: 2, sizeAttenuation: false, transparent: true } );
material.color.setHex( );
particles = new THREE.Points( geometry, material );
particles.sortParticles = true;
scene.add( particles );
}
var color = [10, 100, 200]
function draw() {
camera.position.x = Math.sin( Date.now() * 0.003 ) * 10
+ Math.cos( Date.now() * 0.003 ) * 10;
camera.position.y = Math.cos( Date.now() * 0.006 ) * 10;
camera.rotation.z = Math.cos( Date.now() * 0.00006 ) * 50 +500;
color = color.map(function(d, i){ return (d + 1 + i) % 256 })
geometry = new THREE.Geometry();
material.color.set( new THREE.Color(color[2], color[2], color[2]))
material.color.set( new THREE.Color('red'))
for ( i = 0; i < 60; i ++ ) {
var vertex = new THREE.Vector3();
vertex.x = Math.round((1000 * Math.random() - 500)/20)*20;
vertex.y = Math.round((1000 * Math.random() - 500)/20)*20;
vertex.z = Math.round((1000 * Math.random() - 500)/20)*20;
geometry.vertices.push( vertex );
}
particles = new THREE.Points( geometry, material );
particles.sortParticles = true;
scene.add( particles );
requestAnimationFrame( draw );
renderer.render( scene, camera );
}
setup();
draw();
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment