Initialize with files from goal-009

This commit is contained in:
Riley Shaw 2014-03-09 23:57:59 -04:00
parent 5393155c01
commit e261f14635
14 changed files with 7578 additions and 0 deletions

7319
dist/all.js vendored Normal file

File diff suppressed because it is too large Load Diff

2
dist/all.min.js vendored Normal file

File diff suppressed because one or more lines are too long

1
dist/all.min.js.map vendored Normal file

File diff suppressed because one or more lines are too long

1
dist/main.css vendored Normal file
View File

@ -0,0 +1 @@
body{text-align:center}p{display:inline-block}span{float:left;font-family:monospace;white-space:pre}

56
gulpfile.js Normal file
View File

@ -0,0 +1,56 @@
var
gulp = require('gulp'),
jshint = require('gulp-jshint'),
mocha = require('gulp-mocha'),
stripDebug = require('gulp-strip-debug'),
concat = require('gulp-concat'),
uglify = require('gulp-uglify'),
rename = require('gulp-rename');
sass = require('gulp-ruby-sass'),
autoprefixer = require('gulp-autoprefixer'),
minifyCSS = require('gulp-minify-css');
var paths = {
src: {
firstScripts: [ 'node_modules/lodash/lodash.js', 'scripts/terra.js', 'scripts/terra.util.js' ],
scripts: 'scripts/*.js',
tests: 'tests/*.js',
stylesheets: 'stylesheets/*.sass'
}
};
gulp.task('lint', function() {
return gulp.src(paths.src.scripts)
.pipe(jshint())
.pipe(jshint.reporter('default'));
});
gulp.task('test', function() {
return gulp.src(paths.src.tests)
.pipe( mocha( { reporter: 'spec' } ) )
});
gulp.task('scripts', function() {
return gulp.src( [ paths.src.firstScripts[0], paths.src.firstScripts[1], paths.src.firstScripts[2], paths.src.scripts ] )
.pipe(stripDebug())
.pipe(concat('all.js'))
.pipe(gulp.dest('dist'))
.pipe(rename('all.min.js'))
.pipe(uglify( { outSourceMap: true } ))
.pipe(gulp.dest('dist'));
});
gulp.task('sass', function () {
return gulp.src(paths.src.stylesheets)
.pipe(sass())
.pipe(autoprefixer())
.pipe(minifyCSS())
.pipe(gulp.dest('dist'))
});
gulp.task('watch', function() {
gulp.watch(paths.src.scripts, ['lint', 'scripts']);
gulp.watch(paths.src.stylesheets, ['sass']);
});
gulp.task( 'default', [ 'lint', 'scripts', 'sass', 'watch' ] );

12
index.html Normal file
View File

@ -0,0 +1,12 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Awesome Terrarium!</title>
<link rel="stylesheet" href="dist/main.css">
</head>
<body>
<p id='terra'>Life</p>
<script src="dist/all.min.js"></script>
</body>
</html>

32
package.json Normal file
View File

@ -0,0 +1,32 @@
{
"name": "terra",
"version": "0.0.2",
"description": "A JavaScript framework for generating, analysing, and displaying simple biological interactions in an abstract, digital terrarium.",
"main": "scripts/terra.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
"terrarium",
"simulator",
"cellular",
"automata"
],
"author": "rileyjshaw",
"license": "BSD-2-Clause",
"devDependencies": {
"gulp": "~3.5.2",
"gulp-rename": "~1.1.0",
"gulp-autoprefixer": "0.0.6",
"gulp-uglify": "~0.2.1",
"gulp-minify-css": "~0.3.0",
"gulp-strip-debug": "~0.1.1",
"gulp-jshint": "~1.4.2",
"gulp-concat": "~2.1.7",
"gulp-ruby-sass": "~0.3.1",
"gulp-mocha": "~0.4.1"
},
"dependencies": {
"lodash": "~2.4.1"
}
}

37
scripts/terra.create.js Normal file
View File

@ -0,0 +1,37 @@
// consider changing name, adding ability to pause, reset, etc.
/*
terra.create = function ( selector, map, fps, steps ) {
// Imports...
Terrarium = terra.util.Terrarium;
if ( typeof selector !== 'string' ) {
throw new Error( 'You need to pass an element selector (string) as the first argument of terra.create (received "' + selector + '")');
}
map = map || terra.maps.mSmall( [ '*', 'C', ' ', '#' ] );
fps = fps || 60;
steps = steps || 1;
var startTick = function ( fn ) {
var tick = function () {
setTimeout( function () {
fn();
requestAnimationFrame( tick );
}, 1000 / fps );
};
requestAnimationFrame( tick );
};
var level = new Terrarium( map, selector );
startTick( function () {
for ( var i = steps; i; i-- ) {
level.step();
}
level.toDom();
});
};
*/

View File

@ -0,0 +1,13 @@
;( function ( exports ) {
var creature = function ( config, my ) {
var
color = [ 230, 180, 25 ],
instance = {},
character = config.character,
energy = config.energy || 20,
speed = config.speed || 1;
};
})( terra.creatures = terra.creatures || {} );

10
scripts/terra.js Normal file
View File

@ -0,0 +1,10 @@
;( function () {
if ( typeof terra !== 'undefined' &&
terra !== document.getElementsByName( 'terra' ) &&
terra !== document.getElementById( 'terra' )
) {
throw 'Variable "terra" already exists, that\'s a problem.';
} else {
terra = {}; // global
}
} )();

51
scripts/terra.maps.js Normal file
View File

@ -0,0 +1,51 @@
/*;( function ( exports ) {
// Imports...
randomElement = terra.util.randomElement;
var mGameOfLife =
[ '############################',
'# L #',
'# L #',
'# L #',
'# #',
'# L #',
'# L #',
'# LLL #',
'# L #',
'# L #',
'# #',
'############################' ];
var mapGen = function ( height, width, characters ) {
var level = new Array('');
for ( var col = height - 1; col >= 0; col--) {
for ( var row = width - 1; row >= 0; row--) {
if ( row == width - 1 ) {
character = '';
level[ col ] = '#';
} else if ( !col || !row || col == height - 1 ) {
character = '#';
} else {
character = randomElement( characters );
}
level[ col ] += character;
}
}
return level;
};
exports.mGameOfLife = mGameOfLife;
exports.mSmall = function ( characters ) {
return mapGen( 24, 48, characters );
};
exports.mMedium = function ( characters ) {
return mapGen( 48, 96, characters );
};
exports.mBig = function ( characters ) {
return mapGen( 56, 144, characters );
};
exports.mapGen = mapGen;
})( terra.maps = terra.maps || {} );
*/

25
scripts/terra.util.js Normal file
View File

@ -0,0 +1,25 @@
// Utility and helper functions
;( function ( exports ) {
var arrayOfArrays = function ( height, width ) {
var instance;
if ( typeof height !== 'number' || typeof width !== 'number' ) {
throw 'Input error: arrayOfArrays() requires two numbers as inputs';
}
instance = new Array( height );
while( width-- ) {
instance[ width ] = [];
}
return instance;
};
var grid = new arrayOfArrays(500, 800);
// grid.map
exports.grid = grid;
})( terra.util = terra.util || {} );

10
stylesheets/main.sass Normal file
View File

@ -0,0 +1,10 @@
body
text-align: center
p
display: inline-block
span
float: left
font-family: monospace
white-space: pre

9
tests/test.js Normal file
View File

@ -0,0 +1,9 @@
var assert = require("assert")
describe('Array', function(){
describe('#indexOf()', function(){
it('should return -1 when the value is not present', function(){
assert.equal(-1, [1,2,3].indexOf(5));
assert.equal(-1, [1,2,3].indexOf(0));
})
})
})