Skip to content

Commit

Permalink
added a package info and made first point release
Browse files Browse the repository at this point in the history
  • Loading branch information
Tavistock committed Jun 15, 2015
1 parent 51304ec commit 770d664
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 7 deletions.
16 changes: 16 additions & 0 deletions gulpfile.js
@@ -1,4 +1,5 @@
var gulp = require('gulp');
var uglify = require('gulp-uglify');
var sourcemaps = require('gulp-sourcemaps');
var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');
Expand Down Expand Up @@ -33,7 +34,22 @@ function watch() {
return compile(true);
};

function production() {
var bundler = browserify('./src/index.js').transform(babel);

function rebundle() {
bundler.bundle()
.pipe(source('prod.js'))
.pipe(buffer())
.pipe(uglify())
.pipe(gulp.dest('./build'));
}

rebundle();
}

gulp.task('build', function() { return compile(); });
gulp.task('prod', function() { return production(); });
gulp.task('watch', function() { return watch(); });

gulp.task('default', ['watch']);
3 changes: 2 additions & 1 deletion index.html
@@ -1,7 +1,8 @@
<!DOCTYPE html>
<html>
<body>
<div id='game-of-life'></div>
<div id='loading' style='position:fixed;top:0;left:0;width:100%;height:100%;background-color:#323232;display: flex;align-items: center;justify-content:center;color:#f2f2f2;z-index:100;'>Loading...</div>
<div id='game-of-life' style='display:none;'></div>
<script src="./build/build.js"></script>
</body>
</html>
42 changes: 42 additions & 0 deletions package.json
@@ -0,0 +1,42 @@
{
"name": "geodesic-game-of-life",
"version": "1.0.0",
"description": "Game of Life on a geodesic using THREE.js",
"main": "gulpfile.js",
"dependencies": {
"babelify": "^6.1.2",
"browserify": "^10.2.4",
"dat-gui": "^0.5.0",
"gulp": "^3.9.0",
"gulp-babel": "^5.1.0",
"gulp-sourcemaps": "^1.5.2",
"gulp-uglify": "^1.2.0",
"immutable": "^3.7.3",
"three": "^0.71.0",
"three-orbit-controls": "^69.0.4",
"vinyl-buffer": "^1.0.0",
"vinyl-source-stream": "^1.1.0",
"watchify": "^3.2.2"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/Tavistock/geodesic-game-of-life.git"
},
"keywords": [
"game-of-life",
"3d",
"cellular",
"automata",
"THREE.js"
],
"author": "Travis McNeill <tavistock91@gmail.com>",
"license": "ISC",
"bugs": {
"url": "https://github.com/Tavistock/geodesic-game-of-life/issues"
},
"homepage": "https://github.com/Tavistock/geodesic-game-of-life#readme"
}
81 changes: 75 additions & 6 deletions src/index.js
Expand Up @@ -74,12 +74,13 @@ var GameControls = function () {
this.log = function () {console.log(this);}
}

var params = new GameControls();
// GUI

var params = new GameControls();
var gui = new DAT.GUI();

gui.add(params, 'log');
gui.add(params, 'speed', 50, 1000);
//gui.add(params, 'log');
gui.add(params, 'speed', 50, 1000).step(50);

var ruleFolder = gui.addFolder('Rules');
for (var x in params.rules) {
Expand All @@ -92,8 +93,12 @@ boardFolder.add(params, 'blankBoard');
boardFolder.add(params, 'randomBoard');

var colorFolder = gui.addFolder('Colors');
colorFolder.addColor(params.colors, 'alive').listen();
colorFolder.addColor(params.colors, 'dead').listen();
colorFolder.addColor(params.colors, 'alive')
.onChange((value) => paint(mesh, board))
.listen();
colorFolder.addColor(params.colors, 'dead')
.onChange((value) => paint(mesh, board))
.listen();
colorFolder.addColor(params.colors, 'background')
.onChange((value) => renderer.setClearColor(value))
.listen();
Expand All @@ -120,6 +125,28 @@ animate();

initGol();

// loading


function onReady(callback) {
var intervalID = window.setInterval(checkReady, 1000);
function checkReady() {
if (neighborsCache.count() > 0) {
window.clearInterval(intervalID);
callback.call(this);
}
}
}

function show(id, value) {
document.getElementById(id).style.display = value ? 'block' : 'none';
}

onReady(function () {
show('game-of-life', true);
show('loading', false);
});

// Painting the board

function randomColor() {
Expand Down Expand Up @@ -265,10 +292,52 @@ function createMesh(subdivisions) {
return new THREE.Mesh(baseGeo, baseMat);
}

// interaction
var mouse = new THREE.Vector2();

function mouseLocation(event){
// calculate mouse position in normalized device coordinates
// (-1, +1)
mouse.x = ( event.clientX / window.innerWidth ) * 2 - 1;
mouse.y = - ( event.clientY / window.innerHeight ) * 2 + 1;
}

function mouseUp (event) {
var down = mouse.clone();
mouseLocation(event);
var xTravel = Math.abs(down.x - mouse.x);
var yTravel = Math.abs(down.y - mouse.y);
var travel = ((xTravel + yTravel) * 100);
if (travel< 5) {
handlePick(event);
}
}

function handlePick(event){
var raycaster = new THREE.Raycaster();
raycaster.setFromCamera(mouse, camera);
var intersects = raycaster.intersectObjects(scene.children);
if (0 < intersects.length) {
var inverter = (val) => {
if (val == 1) {
return 0;
} else {
return 1;
}
};
var f = intersects[0].face
board = board.update(gol.Coord3({a:f.a, b:f.b, c:f.c}), inverter);
paint(mesh, board);
}
}

addEventListener('mousedown', mouseLocation);
addEventListener('mouseup', mouseUp);

window.renderer = renderer;
window.scene = scene;
window.mesh = mesh;
window.paint = paint;
window.board = board;

window.stop = stop;
window.run = run;
Expand Down

0 comments on commit 770d664

Please sign in to comment.