Skip to content
Browse files

Merge pull request #42 from doug-martin/transcompile

v0.1.5
  • Loading branch information...
2 parents d568f34 + f61d04f commit 7fa0fa5ee7f95079e02fcf6f047cef47f765ae2f @doug-martin doug-martin committed Jun 17, 2013
Showing with 19,683 additions and 4,091 deletions.
  1. +2 −2 Gruntfile.js
  2. +3 −0 Makefile
  3. +1 −1 benchmark/manners/benchmark.js
  4. +3 −3 bin/assets/compile_wrapper.tmpl
  5. +13 −1 bin/nools
  6. +6 −0 docs-md/examples.md
  7. +13 −0 docs/History.html
  8. +201 −0 docs/examples.html
  9. +3 −0 docs/examples/browser/assets/arguments-extended.js
  10. +174 −0 docs/examples/browser/assets/conways.css
  11. +3 −0 docs/examples/browser/assets/declare.js
  12. +3 −0 docs/examples/browser/assets/extended.js
  13. +3 −0 docs/examples/browser/assets/extender.js
  14. +3 −0 docs/examples/browser/assets/function-extended.js
  15. +3 −0 docs/examples/browser/assets/is-extended.js
  16. +364 −0 docs/examples/browser/assets/orbit_controls.js
  17. +214 −0 docs/examples/browser/conways_2d.html
  18. +123 −0 docs/examples/browser/conways_3d.html
  19. +117 −0 docs/examples/browser/fibonacci.html
  20. +144 −0 docs/examples/browser/manners.html
  21. +62 −0 docs/examples/browser/rules/conways.nools
  22. +84 −0 docs/examples/browser/rules/conways3d.nools
  23. +50 −0 docs/examples/browser/rules/fibonacci.nools
  24. +181 −0 docs/examples/browser/rules/manners.nools
  25. +64 −0 docs/examples/browser/src/cell.js
  26. +94 −0 docs/examples/browser/src/common.js
  27. +291 −0 docs/examples/browser/src/conway_3d.js
  28. +6,139 −0 docs/examples/browser/src/guests.js
  29. +151 −0 docs/examples/browser/src/patterns.js
  30. +222 −0 docs/examples/browser/src/patterns3d.js
  31. +2 −0 docs/index.html
  32. +10 −0 docs/nools.js
  33. +3 −0 examples/browser/assets/arguments-extended.js
  34. +174 −0 examples/browser/assets/conways.css
  35. +3 −0 examples/browser/assets/declare.js
  36. +3 −0 examples/browser/assets/extended.js
  37. +3 −0 examples/browser/assets/extender.js
  38. +3 −0 examples/browser/assets/function-extended.js
  39. +3 −0 examples/browser/assets/is-extended.js
  40. +364 −0 examples/browser/assets/orbit_controls.js
  41. +214 −0 examples/browser/conways_2d.html
  42. +123 −0 examples/browser/conways_3d.html
  43. +0 −56 examples/browser/fibonacci.dsl.html
  44. +55 −31 examples/browser/fibonacci.html
  45. +122 −321 examples/browser/manners.html
  46. +0 −57 examples/browser/parse.html
  47. +62 −0 examples/browser/rules/conways.nools
  48. +84 −0 examples/browser/rules/conways3d.nools
  49. +0 −1 examples/browser/rules/fibonacci.js
  50. +0 −1 examples/browser/rules/manners.js
  51. +2 −6 examples/browser/rules/manners.nools
  52. +64 −0 examples/browser/src/cell.js
  53. +94 −0 examples/browser/src/common.js
  54. +291 −0 examples/browser/src/conway_3d.js
  55. +6,139 −0 examples/browser/src/guests.js
  56. +151 −0 examples/browser/src/patterns.js
  57. +222 −0 examples/browser/src/patterns3d.js
  58. +0 −102 examples/conways/assets/conways.css
  59. +0 −123 examples/conways/index.html
  60. +0 −83 examples/conways/index.js
  61. +0 −89 examples/conways/patterns.json
  62. +0 −1 examples/conways/rules/conways.js
  63. +0 −137 examples/conways/rules/conways.nools
  64. +9 −0 history.md
  65. +51 −39 lib/agenda.js
  66. +0 −240 lib/compile.js
  67. +56 −0 lib/compile/common.js
  68. +189 −0 lib/compile/index.js
  69. +150 −0 lib/compile/transpile.js
  70. +16 −21 lib/context.js
  71. +2 −3 lib/extended.js
  72. +54 −48 lib/index.js
  73. +53 −0 lib/linkedList.js
  74. +12 −10 lib/nodes/joinNode.js
  75. +19 −11 lib/nodes/joinReferenceNode.js
  76. +2 −2 lib/nodes/node.js
  77. +18 −14 lib/nodes/notNode.js
  78. +1 −1 lib/rule.js
  79. +7 −25 lib/workingMemory.js
  80. +2,018 −2,441 nools.js
  81. +7 −7 nools.min.js
  82. +69 −66 package.json
  83. +8 −16 test/flow.compiled.test.js
  84. +3 −1 test/flow.dsl.test.js
  85. +6 −4 test/flow.test.js
  86. +1 −1 test/rules/agenda-group-compiled.js
  87. +1 −1 test/rules/auto-focus-compiled.js
  88. +1 −49 test/rules/diagnosis-compiled.js
  89. +1 −1 test/rules/fibonacci-compiled.js
  90. +1 −24 test/rules/notRule-compiled.js
  91. +1 −24 test/rules/orRule-compiled.js
  92. +1 −1 test/rules/scope-compiled.js
  93. +1 −26 test/rules/simple-compiled.js
View
4 Gruntfile.js
@@ -29,8 +29,8 @@ module.exports = function (grunt) {
'<%= grunt.template.today("yyyy-mm-dd") %>\n' +
'<%= pkg.homepage ? "* " + pkg.homepage + "\\n" : "" %>' +
'* Copyright (c) <%= grunt.template.today("yyyy") %> <%= pkg.author %>;' +
- ' Licensed <%= pkg.license %> */\n',
- report: 'gzip'
+ ' Licensed <%= pkg.license %> */\n'
+ //report: 'gzip'
},
min: {
files: {
View
3 Makefile
@@ -9,6 +9,9 @@ docs: docclean
docclean :
rm -rf docs/*
+ mkdir -p ./docs/examples/browser
+ cp -r ./examples/browser/ ./docs/examples/browser
+ cp ./nools.min.js ./docs/nools.js
benchmarks:
for file in $(BENCHMARKS) ; do \
View
2 benchmark/manners/benchmark.js
@@ -4,7 +4,7 @@
nools = require("../../index");
var flow = nools.compile(__dirname + "/manners.nools");
- var guests = data.load(flow).manners16;
+ var guests = data.load(flow).manners32;
var session = flow.getSession.apply(flow, guests);
session.assert(new (flow.getDefined("count"))({value: 1}));
var start = new Date();
View
6 bin/assets/compile_wrapper.tmpl
@@ -1,18 +1,18 @@
(function(){
function _getCompiled(nools){
- return nools.compile({source}, {name : "{name}"});
+ return {source}
}
if ("undefined" !== typeof exports) {
if ("undefined" !== typeof module && module.exports) {
- return _getCompiled(require("{noolsLocation}"));
+ module.exports = _getCompiled(require("{noolsLocation}"));
}
} else if ("function" === typeof define && define.amd) {
define(["{noolsLocation}"], function (nools) {
return _getCompiled(nools);
});
} else {
- _getCompiled(this.nools);
+ _getCompiled(this.nools)();
}
}).call(this);
View
14 bin/nools
@@ -7,8 +7,18 @@ var nools = require(".."),
path = require("path"),
template = fs.readFileSync(path.join(__dirname, "assets", "compile_wrapper.tmpl"), "utf8"),
str = require("string-extended"),
+ uglifyjs = require("uglify-js"),
program = require('commander');
+function uglify(source) {
+ try {
+ return uglifyjs.minify(source, {fromString: true, mangle: false, output: {beautify: true}}).code;
+ } catch (e) {
+ console.error(e.message);
+ console.error(e.stack);
+ }
+}
+
program
.version('0.0.1');
@@ -24,10 +34,12 @@ program.command("compile")
var noolsLocation = program["nools_location"] || "nools";
files.forEach(function (file) {
var name = program.name || path.basename(file, path.extname(file));
- console.log(str.format(template, { source: JSON.stringify(nools.parse(path.resolve(process.cwd(), file))), name: name, noolsLocation: noolsLocation}).replace(/\s+/g, " "));
+ console.log(str.format(template, { source: uglify(nools.transpile(path.resolve(process.cwd(), file), {name: name})), noolsLocation: noolsLocation}).replace(/\s+/g, " "));
});
});
+//return uglifyjs.minify(ret.join(""), {fromString: true, mangle: false, output: {beautify: true}}).code;
+
program.parse(process.argv);
View
6 docs-md/examples.md
@@ -0,0 +1,6 @@
+## Examples
+
+ * [Conways 2D](./examples/browser/conways_2d.html)
+ * [Conways 3D](./examples/browser/conways_3d.html)
+ * [Fibonacci](./examples/browser/fibonacci.html)
+ * [Miss Manners](./examples/browser/manners.html)
View
13 docs/History.html
@@ -148,6 +148,8 @@
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Docs<b class="caret"></b></a>
<ul class="dropdown-menu">
+ <li><a href="./examples.html">Examples</a></li>
+
<li><a href="./History.html">Change Log</a></li>
</ul>
@@ -176,6 +178,17 @@
+<h1>v0.1.5 / 2012-06-17</h1>
+<ul>
+<li>More Examples</li>
+<li>Changed nools compile to transpile to Javascript!</li>
+<li>Better performance<ul>
+<li>Simple Benchmark: Before ~600ms, Now ~350ms</li>
+<li>Manners Benchmark (32): Before ~10s, Now ~4sec</li>
+<li>WaltzDB: Before ~30sec, Now ~15sec</li>
+</ul>
+</li>
+</ul>
<h1>v0.1.4 / 2012-05-25</h1>
<ul>
<li>Added new agenda-group (#29)</li>
View
201 docs/examples.html
@@ -0,0 +1,201 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <meta charset="utf-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
+ <title>nools</title>
+ <link rel="stylesheet" href="./assets/css/bootstrap.min.css">
+ <link rel="stylesheet" href="./assets/css/prettify.css">
+ <style type="text/css">
+
+
+/*.subnav-inner {*/
+ /*width: 100%;*/
+ /*height: 36px;*/
+ /*background-color: #EEE;*/
+ /*background-repeat: repeat-x;*/
+ /*background-image: -moz-linear-gradient(top, whiteSmoke 0%, #EEE 100%);*/
+ /*background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0%, whiteSmoke), color-stop(100%, #EEE));*/
+ /*background-image: -webkit-linear-gradient(top, whiteSmoke 0%, #EEE 100%);*/
+ /*background-image: -ms-linear-gradient(top, whiteSmoke 0%, #EEE 100%);*/
+ /*background-image: -o-linear-gradient(top, whiteSmoke 0%, #EEE 100%);*/
+ /*filter: progid:DXImageTransform.Microsoft.gradient(startColorstr = '#f5f5f5', endColorstr = '#eeeeee', GradientType = 0);*/
+ /*background-image: linear-gradient(top, whiteSmoke 0%, #EEE 100%);*/
+ /*-webkit-border-radius: 4px;*/
+ /*-moz-border-radius: 4px;*/
+ /*border-radius: 4px;*/
+/*}*/
+
+/*.subnav .nav > li > a:hover {*/
+ /*color: black !important;*/
+/*}*/
+
+/*.subnav .nav li.dropdown .dropdown-toggle .caret,*/
+/*.subnav .nav li.dropdown.open .caret {*/
+ /*border-top-color: #999 !important;*/
+ /*border-bottom-color: #999 !important;*/
+/*}*/
+
+/*.subnav-fixed {*/
+ /*position: fixed;*/
+ /*width : 90%;*/
+ /*margin-right: auto;*/
+ /*margin-left: auto;*/
+ /*top: 40px;*/
+ /*left: 0;*/
+ /*right: 0;*/
+ /*z-index: 1020;*/
+ /*border-color: #D5D5D5;*/
+ /*border-width: 0 0 1px;*/
+ /*-webkit-border-radius: 0;*/
+ /*-moz-border-radius: 0;*/
+ /*border-radius: 0;*/
+ /*-webkit-box-shadow: inset 0 1px 0 #fff, 0 1px 5px rgba(0,0,0,.1);*/
+ /*-moz-box-shadow: inset 0 1px 0 #fff, 0 1px 5px rgba(0,0,0,.1);*/
+ /*box-shadow: inset 0 1px 0 #fff, 0 1px 5px rgba(0,0,0,.1);*/
+ /*filter: progid:DXImageTransform.Microsoft.gradient(enabled=false);*/
+/*}*/
+
+/*.navbar .nav .dropdown-menu {*/
+ /*max-height: 500px;*/
+ /*overflow: auto;*/
+/*}​*/
+
+ </style>
+ <style type="text/css">
+ body {
+ padding: 90px;
+ }
+
+ .subnav{
+ margin-top: 40px;
+ margin-right: auto;
+ margin-left: auto;
+ z-index: 1000;
+ }
+
+ .dropdown-menu{
+ max-height: 500px;
+ overflow-y: auto;
+ }
+
+ @media (max-width:979px) {
+ .subnav{
+ margin-top: auto;
+ }
+ }
+ </style>
+ <link rel="stylesheet" href="./assets/css/bootstrap-responsive.min.css">
+ <script type="text/javascript">
+ var init = (function () {
+ "use strict";
+
+ var processScroll = (function () {
+ var curr = null, prev = null;
+ return function (nav) {
+ var $win = $(window);
+ $('.subnav').each(function () {
+ var nav = $(this);
+ var navTop = $win.width() < 980 ? 0 : nav.offset().top - 40;
+
+ var scrollTop = $win.scrollTop();
+ if (scrollTop >= navTop && curr != nav) {
+ if(curr){
+ curr.removeClass('subnav-fixed')
+ prev = curr;
+ }
+ curr = nav;
+ curr.addClass('subnav-fixed')
+ } else if (curr == nav && scrollTop <= navTop) {
+ curr.removeClass('subnav-fixed');
+ prev.addClass('subnav-fixed');
+ curr = prev;
+ }else{
+ nav.removeClass('subnav-fixed');
+ }
+ });
+ };
+ })();
+
+ return function () {
+ window.prettyPrint && prettyPrint();
+ $(".collapse").collapse();
+ var $window = $(window);
+ //$(".subnav").affix ();
+ // fix sub nav on scroll
+// processScroll();
+// $(window).on('scroll', processScroll)
+ }
+ })();
+ </script>
+</head>
+<body onload="init()">
+<div class="navbar navbar-fixed-top navbar-inverse">
+ <div class="navbar-inner">
+ <div class="container">
+ <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
+ <span class="icon-bar"></span>
+ <span class="icon-bar"></span>
+ <span class="icon-bar"> </span>
+ </a>
+
+ <a href="./index.html" class="brand">nools</a>
+
+ <div class="nav-collapse">
+ <ul class="nav">
+
+ <li class="dropdown">
+ <a href="#" class="dropdown-toggle" data-toggle="dropdown">Docs<b class="caret"></b></a>
+ <ul class="dropdown-menu">
+
+ <li><a href="./examples.html">Examples</a></li>
+
+ <li><a href="./History.html">Change Log</a></li>
+
+ </ul>
+
+
+
+
+ </ul>
+
+ <ul class="nav pull-right">
+
+ <li class="divider-vertical"></li>
+ <li><a href="https://github.com/C2FO/nools" target="#github" class="pull-right">github</a></li>
+ </ul>
+
+ </div>
+ </div>
+ </div>
+</div>
+
+
+
+<div class="container-fluid">
+ <a name="top"></a>
+ <div class="container">
+
+
+
+<h2>Examples</h2>
+<ul>
+<li><a href="./examples/browser/conways_2d.html">Conways 2D</a></li>
+<li><a href="./examples/browser/conways_3d.html">Conways 3D</a></li>
+<li><a href="./examples/browser/fibonacci.html">Fibonacci</a></li>
+<li><a href="./examples/browser/manners.html">Miss Manners</a></li>
+</ul>
+
+<hr>
+
+Documentation generated using <a href="https://github.com/doug-martin/coddoc">coddoc</a>.
+
+
+</div>
+</div>
+<script type="text/javascript" src="./assets/js/jquery.js"></script>
+<script type="text/javascript" src="./assets/js/bootstrap.min.js"></script>
+<script type="text/javascript" src="./assets/js/prettify.js"></script>
+
+</body>
+</html>
View
3 docs/examples/browser/assets/arguments-extended.js
@@ -0,0 +1,3 @@
+/*! arguments-extended - v0.0.3 - 2013-06-06
+ * Copyright (c) 2013 Doug Martin; Licensed MIT */
+(function(){"use strict";function e(e,t){function n(e,t){var n=-1,r=0,d=e.length,i=[];for(t=t||0,n+=t;d>++n;)i[r++]=e[n];return i}var r=(Array.prototype.slice,t.isArguments);return e.define(r,{toArray:n}).expose({argsToArray:n})}"undefined"!=typeof exports?"undefined"!=typeof module&&module.exports&&(module.exports=e(require("extended"),require("is-extended"))):"function"==typeof define&&define.amd?define(["../../../","is-extended"],function(t,n){return e(t,n)}):this.argumentsExtended=e(this.extended,this.isExtended)}).call(this);
View
174 docs/examples/browser/assets/conways.css
@@ -0,0 +1,174 @@
+body {
+ font-size: 12px;
+ line-height: 24px;
+ font-weight: bold;
+ font-family: 'Londrina Shadow', cursive;
+ width: 100%;
+ height: 100%;
+ overflow: hidden;
+}
+
+#editor {
+ position: absolute;
+ width: 100%;
+ height: 100%;
+}
+
+#fibonacci div.inline {
+ height: 100%;
+ margin: 10px;
+}
+
+#manners {
+ width: 50%;
+ padding: 10px;
+ border: 1px solid rgba(0, 0, 0, 0.1);
+ -webkit-box-shadow: 0px 0px 8px rgba(0, 0, 0, 0.1);
+ -moz-box-shadow: 0px 0px 8px rgba(0, 0, 0, 0.1);
+ box-shadow: 0px 0px 8px rgba(0, 0, 0, 0.1);
+
+}
+
+#manners #results_container {
+ overflow: auto;
+ height: 400px;
+ width: 95%;
+ background: #dfdfdf;
+ color: #09C;
+ font-family: Tahoma, Geneva, sans-serif;
+ padding: 10px;
+ border-radius: 10px;
+}
+
+.container > header {
+ text-align: center;
+ text-align: center;
+ height: 100px;
+}
+
+.container {
+ overflow: hidden;
+}
+
+.controls {
+ position: absolute;
+ top: 25px;
+ left: 25px;
+ background-color: white;
+ border: 1px solid rgba(0, 0, 0, 0.1);
+ -webkit-box-shadow: 0px 0px 8px rgba(0, 0, 0, 0.1);
+ -moz-box-shadow: 0px 0px 8px rgba(0, 0, 0, 0.1);
+ box-shadow: 0px 0px 8px rgba(0, 0, 0, 0.1);
+}
+
+.middle {
+ position: static;
+ width: auto;
+ margin-right: auto;
+ margin-left: auto;
+}
+
+hr {
+ margin: 10px;
+ border: 1px solid rgba(0, 0, 0, 0.1);
+ -webkit-box-shadow: 0px 0px 8px rgba(0, 0, 0, 0.1);
+ -moz-box-shadow: 0px 0px 8px rgba(0, 0, 0, 0.1);
+ box-shadow: 0px 0px 8px rgba(0, 0, 0, 0.1);
+}
+
+input[type="submit"], input[type="button"] {
+ width: 100px;
+ right: 20px;
+ bottom: 20px;
+ background: #09C;
+ color: #fff;
+ font-family: Tahoma, Geneva, sans-serif;
+ height: 30px;
+ -webkit-border-radius: 15px;
+ -moz-border-radius: 15px;
+ border-radius: 15px;
+ border: 1px solid #999;
+ margin: 10px;
+}
+
+#grid {
+
+ overflow: hidden;
+ width: 100%;
+ height: 100%;
+ margin-left: auto;
+ margin-right: auto;
+ -webkit-box-shadow: 0px 0px 8px rgba(0, 0, 0, 0.1);
+ -moz-box-shadow: 0px 0px 8px rgba(0, 0, 0, 0.1);
+ box-shadow: 0px 0px 8px rgba(0, 0, 0, 0.1);
+ -webkit-border-radius: 10px;
+ -moz-border-radius: 10px;
+ border-radius: 10px;
+ padding: 3px;
+ overflow: hidden;
+
+}
+
+.detail {
+ font-size: 14pt;
+ background-color: white;
+ display: table-cell;
+ border: 1px solid #cbcbcb;
+ content: " ", -webkit-box-shadow : 0 px 0 px 8 px rgba ( 0, 0, 0, 0.2 );
+ -moz-box-shadow: 0px 0px 8px rgba(0, 0, 0, 0.2);
+ box-shadow: 0px 0px 8px rgba(0, 0, 0, 0.2);
+ position: absolute;
+ bottom: 5px;
+}
+
+.row {
+ display: table-row;
+}
+
+.col {
+ width: 20px;
+ height: 20px;
+ display: table-cell;
+ border: 1px solid #cbcbcb;
+ content: " ", -webkit-box-shadow : 0 px 0 px 8 px rgba ( 0, 0, 0, 0.2 );
+ -moz-box-shadow: 0px 0px 8px rgba(0, 0, 0, 0.2);
+ box-shadow: 0px 0px 8px rgba(0, 0, 0, 0.2);
+}
+
+.col.live {
+ background-color: black;
+}
+
+.col.dead {
+ background-color: white;
+}
+
+.inline {
+ display: inline-block;
+ vertical-align: middle;
+}
+
+.large {
+ font-size: 50px;
+}
+
+.right {
+ float: right;
+}
+
+.errors {
+ color: #f90008;
+}
+
+input[type="text"] {
+ margin-top: 30px;
+ margin-bottom: 20px;
+ width: 100%;
+ display: block;
+ border: 1px solid #999;
+ height: 20px;
+ font-size: 20px;
+ -webkit-box-shadow: 0px 0px 8px rgba(0, 0, 0, 0.3);
+ -moz-box-shadow: 0px 0px 8px rgba(0, 0, 0, 0.3);
+ box-shadow: 0px 0px 8px rgba(0, 0, 0, 0.3);
+}
View
3 docs/examples/browser/assets/declare.js
@@ -0,0 +1,3 @@
+/*! declare.js - v0.0.5 - 2013-06-05
+ * Copyright (c) 2013 Doug Martin (doug@dougamartin.com); Licensed MIT */
+!function(){function a(){function a(a,b){return b=b||0,x.call(a,b)}function b(a){return"[object Array]"===Object.prototype.toString.call(a)}function c(a){var b;return null!==a&&a!==b&&"object"==typeof a}function d(a){var b=c(a);return b&&a.constructor===Object}function e(a,b){if(a&&a.length)for(var c=0,d=a.length;d>c;c++)if(a[c]===b)return c;return-1}function f(a,b,c){var d,f;for(d in b)b.hasOwnProperty(d)&&-1===e(c,d)&&(f=b[d],d in a&&a[d]===f||(a[d]=f));return a}function g(a){var c=this.__meta,d=c.supers,e=d.length,f=c.superMeta,g=f.pos;if(e>g){a=a?B(a)||b(a)?a:[a]:[];var h,i=f.name,j=f.f;do if(h=d[g][i],"function"==typeof h&&(h=h._f||h)!==j)return f.pos=1+g,h.apply(this,a);while(e>++g)}return null}function h(){var a=this.__meta,b=a.supers,c=b.length,d=a.superMeta,e=d.pos;if(c>e){var f,g=d.name,h=d.f;do if(f=b[e][g],"function"==typeof f&&(f=f._f||f)!==h)return d.pos=1+e,f.bind(this);while(c>++e)}return null}function i(a){var b=this.__getters__;return b.hasOwnProperty(a)?b[a].apply(this):this[a]}function j(b,c){var e=this.__setters__;if(!d(b))return e.hasOwnProperty(b)?e[b].apply(this,a(arguments,1)):this[b]=c;for(var f in b){var g=b[f];e.hasOwnProperty(f)?e[b].call(this,g):this[f]=g}}function k(){var a=this.__meta||{},b=a.supers,c=b.length,d=a.superMeta,e=d.pos;if(c>e){var f,g=d.name,h=d.f;do if(f=b[e][g],"function"==typeof f&&(f=f._f||f)!==h)return d.pos=1+e,f.apply(this,arguments);while(c>++e)}return null}function l(a,b){if(a.toString().match(A)){var c=function(){var c,d=this.__meta||{},e=d.superMeta;switch(d.superMeta={f:a,pos:0,name:b},arguments.length){case 0:c=a.call(this);break;case 1:c=a.call(this,arguments[0]);break;case 2:c=a.call(this,arguments[0],arguments[1]);break;case 3:c=a.call(this,arguments[0],arguments[1],arguments[2]);break;default:c=a.apply(this,arguments)}return d.superMeta=e,c};return c._f=a,c}return a._f=a,a}function m(a,b){var c=b.setters||{},d=a.__setters__,e=a.__getters__;for(var f in c)d.hasOwnProperty(f)||(d[f]=c[f]);c=b.getters||{};for(f in c)e.hasOwnProperty(f)||(e[f]=c[f]);for(var g in b)if("getters"!==g&&"setters"!==g){var h=b[g];"function"==typeof h?a.hasOwnProperty(g)||(a[g]=l(k,g)):a[g]=h}}function n(){for(var b=a(arguments),c=b.length,d=this.prototype,e=d.__meta,f=this.__meta,g=d.__meta.bases,h=g.slice(),i=f.supers||[],j=e.supers||[],k=0;c>k;k++){var l=b[k],n=l.prototype,p=n.__meta,q=l.__meta;!p&&(p=n.__meta={proto:n||{}}),!q&&(q=l.__meta={proto:l.__proto__||{}}),m(d,p.proto||{}),m(this,q.proto||{}),o(l.prototype,j,g),o(l,i,h)}return this}function o(a,b,c){var d=a.__meta;!d&&(d=a.__meta={});var f=a.__meta.unique;if(!f&&(d.unique="declare"+ ++y),-1===e(c,f)){c.push(f);for(var g=a.__meta.supers||[],h=g.length-1||0;h>=0;)o(g[h--],b,c);b.unshift(a)}}function p(a,b){var c=b.setters,d=a.__setters__,e=a.__getters__;if(c)for(var f in c)d[f]=c[f];if(c=b.getters||{})for(f in c)e[f]=c[f];for(f in b)if("getters"!=f&&"setters"!=f){var g=b[f];if("function"==typeof g){var h=g.__meta||{};a[f]=h.isConstructor?g:l(g,f)}else a[f]=g}}function q(a,b){return a&&b?a[b]=this:a.exports=a=this,this}function r(a){return u(this,a)}function s(a){z.prototype=a.prototype;var b=new z;return z.prototype=null,b}function t(a,c,e){var i={},j=[],m="declare"+ ++y,q=[],r=[],t=[],u=[],v={supers:t,unique:m,bases:q,superMeta:{f:null,pos:0,name:null}},x={supers:u,unique:m,bases:r,isConstructor:!0,superMeta:{f:null,pos:0,name:null}};if(d(c)&&!e&&(e=c,c=w),"function"==typeof c||b(c)?(j=b(c)?c:[c],c=j.shift(),a.__meta=x,i=s(c),i.__meta=v,i.__getters__=f({},i.__getters__||{}),i.__setters__=f({},i.__setters__||{}),a.__getters__=f({},a.__getters__||{}),a.__setters__=f({},a.__setters__||{}),o(c.prototype,t,q),o(c,u,r)):(a.__meta=x,i.__meta=v,i.__getters__=i.__getters__||{},i.__setters__=i.__setters__||{},a.__getters__=a.__getters__||{},a.__setters__=a.__setters__||{}),a.prototype=i,e){var z=v.proto=e.instance||{},A=x.proto=e.static||{};A.init=A.init||k,p(i,z),p(a,A),i.constructor=z.hasOwnProperty("constructor")?l(z.constructor,"constructor"):z.constructor=l(k,"constructor")}else v.proto={},x.proto={},a.init=l(k,"init"),i.constructor=l(k,"constructor");j.length&&n.apply(a,j),c&&f(a,f(f({},c),a)),i._super=a._super=g,i._getSuper=a._getSuper=h,i._static=a}function u(a,b){function c(){this.constructor.apply(this,arguments)}return t(c,a,b),c.init()||c}function v(a,b){function c(){return d||(this.constructor.apply(this,arguments),d=this),d}var d;return t(c,a,b),c.init()||c}var w,x=Array.prototype.slice,y=0,z=new Function,A=/(super)/g,B=function(a){return"[object Arguments]"===Object.prototype.toString.call(a)};return B(arguments)||(B=function(a){return!(!a||!a.hasOwnProperty("callee"))}),w=u({instance:{get:i,set:j},"static":{get:i,set:j,mixin:n,extend:r,as:q}}),u.singleton=v,u}"undefined"!=typeof exports?"undefined"!=typeof module&&module.exports&&(module.exports=a()):"function"==typeof define&&define.amd?define(a):this.declare=a()}();
View
3 docs/examples/browser/assets/extended.js
@@ -0,0 +1,3 @@
+/*! extended - v0.0.5 - 2013-06-05
+ * Copyright (c) 2013 Doug Martin; Licensed MIT */
+(function(){"use strict";function e(e){function n(){var n=e.define();return n.expose({register:function(e,t){t||(t=e,e=null);var r=typeof t;if(e)n[e]=t;else if(t&&"function"===r)n.extend(t);else{if("object"!==r)throw new TypeError("extended.register must be called with an extender function");n.expose(t)}return n},define:function(){return e.define.apply(e,arguments)}}),n}function t(){return n()}return function(){function e(e,n){var t,r;for(t in n)n.hasOwnProperty(t)&&(r=n[t],t in e&&e[t]===r||(e[t]=r));return e}return function(n){n||(n={});for(var t=1,r=arguments.length;r>t;t++)e(n,arguments[t]);return n}}(),t.define=function(){return e.define.apply(e,arguments)},t}"undefined"!=typeof exports?"undefined"!=typeof module&&module.exports&&(module.exports=e(require("extender"))):"function"==typeof define&&define.amd?define(["../../../"],function(n){return e(n)}):this.extended=e(this.extender)}).call(this);
View
3 docs/examples/browser/assets/extender.js
@@ -0,0 +1,3 @@
+/*! extender - v0.0.8 - 2013-06-05
+ * Copyright (c) 2013 Doug Martin (blog.dougamartin.com); Licensed MIT */
+(function(){function n(n){function e(n,e){if(n&&n.length)for(var t=0,r=n.length;r>t;t++)if(n[t]===e)return t;return-1}function t(n){return"[object Array]"===Object.prototype.toString.call(n)}function r(e){function t(n,e,t){if("function"!=typeof t)throw new TypeError("when extending type you must provide a function");var r;r="constructor"===e?function(){this._super(arguments),t.apply(this,arguments)}:function r(){var n=o.call(arguments);n.unshift(this._value);var e=t.apply(this,n);return e!==u?this.__extender__(e):this},n[e]=r}function r(n,e,t){if("function"!=typeof t)throw new TypeError("when extending type you must provide a function");var r;r="constructor"===e?function(){this._super(arguments),t.apply(this,arguments)}:function r(){var n=o.call(arguments);return n.unshift(this._value),t.apply(this,n)},n[e]=r}function f(n,e,u){for(var o in e)e.hasOwnProperty(o)&&("getters"!==o&&"setters"!==o?"noWrap"===o?f(n,e[o],!0):u?r(n,o,e[o]):t(n,o,e[o]):n[o]=e[o])}function s(n){var e,t,r=n;if(!(n instanceof d)){var u=d;for(e=0,t=p.length;t>e;e++){var o=p[e];o[0](n)&&(u=u.extend({instance:o[1]}))}r=new u(n),r.__extender__=s}return r}function c(){return!0}function a(n,e){if(arguments.length){"object"==typeof n&&(e=n,n=c),e=e||{};var r={};f(r,e),r.hasOwnProperty("constructor")||(e.hasOwnProperty("constructor")?t(r,"constructor",e.constructor):r.constructor=function(){this._super(arguments)}),p.push([n,r])}return s}function _(n){return n&&n.hasOwnProperty("__defined__")&&(s.__defined__=p=p.concat(n.__defined__)),i(s,n,["define","extend","expose","__defined__"]),s}e=e||[];var d=n({instance:{constructor:function(n){this._value=n},value:function(){return this._value},eq:function(n){return this.__extender__(this._value===n)},neq:function(n){return this.__extender__(this._value!==n)},print:function(){return console.log(this._value),this}}}),p=[];return s.define=a,s.extend=_,s.expose=function(){for(var n,e=0,t=arguments.length;t>e;e++)n=arguments[e],"object"==typeof n&&i(s,n,["define","extend","expose","__defined__"]);return s},s.__defined__=p,s}var u,o=Array.prototype.slice,i=function(){function n(n,t,r){var u,o;for(u in t)t.hasOwnProperty(u)&&-1===e(r,u)&&(o=t[u],u in n&&n[u]===o||(n[u]=o));return n}return function(e){e||(e={});var r=arguments.length,u=arguments[arguments.length-1];t(u)?r--:u=[];for(var o=1;r>o;o++)n(e,arguments[o],u);return e}}();return{define:function(){return r().define.apply(r,arguments)},extend:function(n){return r().define().extend(n)}}}"undefined"!=typeof exports?"undefined"!=typeof module&&module.exports&&(module.exports=n(require("declare.js"))):"function"==typeof define&&define.amd?define(["declare"],function(e){return n(e)}):this.extender=n(this.declare)}).call(this);
View
3 docs/examples/browser/assets/function-extended.js
@@ -0,0 +1,3 @@
+/*! function-extended - v0.0.6 - 2013-06-06
+ * Copyright (c) 2013 Doug Martin; Licensed MIT */
+!function(){"use strict";function a(a,b,c){function d(a,b,c){if(c=o(arguments,2),m(b)&&!(b in a))throw new Error(b+" property not defined in scope");if(!m(b)&&!n(b))throw new Error(b+" is not a function");return m(b)?function(){var d=a[b];if(n(d)){var e=c.concat(o(arguments));return d.apply(a,e)}return d}:c.length?function(){var d=c.concat(o(arguments));return b.apply(a,d)}:function(){return b.apply(a,arguments)}}function e(a,b){if(b=o(arguments,1),!m(a)&&!n(a))throw new Error(a+" must be the name of a property or function to execute");return m(a)?function(){var c=o(arguments),d=c.shift(),e=d[a];return n(e)?(c=b.concat(c),e.apply(d,c)):e}:function(){var c=o(arguments),d=c.shift();return c=b.concat(c),a.apply(d,c)}}function f(a,b,c){if(c=o(arguments,2),m(b)&&!(b in a))throw new Error(b+" property not defined in scope");if(!m(b)&&!n(b))throw new Error(b+" is not a function");return m(b)?function(){var d=a[b];return n(d)?d.apply(a,c):d}:function(){return b.apply(a,c)}}function g(a){var b=o(arguments,1);if(!l(a)&&!n(a))throw new TypeError("scope must be an object");if(1===b.length&&k(b[0])&&(b=b[0]),!b.length){b=[];for(var c in a)a.hasOwnProperty(c)&&n(a[c])&&b.push(c)}for(var e=0,f=b.length;f>e;e++)a[b[e]]=d(a,a[b[e]]);return a}function h(a,b){if(b=o(arguments,1),!m(a)&&!n(a))throw new Error(a+" must be the name of a property or function to execute");return m(a)?function(){var c=this[a];if(n(c)){var d=b.concat(o(arguments));return c.apply(this,d)}return c}:function(){var c=b.concat(o(arguments));return a.apply(this,c)}}function i(a,b){return function(){var c=o(arguments);return b?a.apply(this,arguments):function(){return a.apply(this,c.concat(o(arguments)))}}}function j(a,b,c){var e;if(e=c?d(c,b):b,a)for(var f=a-1,g=f;g>=0;g--)e=i(e,g===f);return e}var k=b.isArray,l=b.isObject,m=b.isString,n=b.isFunction,o=c.argsToArray;return a.define(l,{bind:d,bindAll:g,bindIgnore:f,curry:function(a,b,c){return j(b,c,a)}}).define(n,{bind:function(a,b){return d.apply(this,[b,a].concat(o(arguments,2)))},bindIgnore:function(a,b){return f.apply(this,[b,a].concat(o(arguments,2)))},partial:h,applyFirst:e,curry:function(a,b,c){return j(b,a,c)},noWrap:{f:function(){return this.value()}}}).define(m,{bind:function(a,b){return d(b,a)},bindIgnore:function(a,b){return f(b,a)},partial:h,applyFirst:e,curry:function(a,b,c){return j(b,a,c)}}).expose({bind:d,bindAll:g,bindIgnore:f,partial:h,applyFirst:e,curry:j})}"undefined"!=typeof exports?"undefined"!=typeof module&&module.exports&&(module.exports=a(require("extended"),require("is-extended"),require("arguments-extended"))):"function"==typeof define&&define.amd?define(["../../../","is-extended","arguments-extended"],function(b,c,d){return a(b,c,d)}):this.functionExtended=a(this.extended,this.isExtended,this.argumentsExtended)}.call(this);
View
3 docs/examples/browser/assets/is-extended.js
@@ -0,0 +1,3 @@
+/*! is-extended - v0.0.9 - 2013-06-05
+ * Copyright (c) 2013 Doug Martin; Licensed MIT */
+(function(){"use strict";function n(n){function t(n,t){return t=t||0,P.call(n,t)}function e(n){var t=[];for(var e in n)z.call(n,e)&&t.push(e);return t}function r(n,t){if(n===t)return!0;if("undefined"!=typeof Buffer&&Buffer.isBuffer(n)&&Buffer.isBuffer(t)){if(n.length!==t.length)return!1;for(var e=0;n.length>e;e++)if(n[e]!==t[e])return!1;return!0}return g(n)&&g(t)?n.getTime()===t.getTime():p(n)&&p(t)?n.source===t.source&&n.global===t.global&&n.multiline===t.multiline&&n.lastIndex===t.lastIndex&&n.ignoreCase===t.ignoreCase:y(n)&&y(t)&&n!==t?!1:"object"!=typeof n&&"object"!=typeof t?n===t:i(n,t)}function i(n,t){var i;if(a(n)||a(t))return!1;if(n.prototype!==t.prototype)return!1;if(M(n))return M(t)?(n=P.call(n),t=P.call(t),r(n,t)):!1;try{var u,o=e(n),f=e(t);if(o.length!==f.length)return!1;for(o.sort(),f.sort(),u=o.length-1;u>=0;u--)if(o[u]!==f[u])return!1;for(u=o.length-1;u>=0;u--)if(i=o[u],!r(n[i],t[i]))return!1}catch(c){return!1}return!0}function u(n){return null!==n&&"object"==typeof n}function o(n){var t=u(n);return t&&n.constructor===Object&&!n.nodeType&&!n.setInterval}function f(n){return M(n)?0===n.length:u(n)?0===e(n).length:y(n)||Q(n)?0===n.length:!0}function c(n){return n===!0||n===!1||"[object Boolean]"===J.call(n)}function s(n){return n===void 0}function l(n){return!s(n)}function a(n){return s(n)||h(n)}function h(n){return null===n}function d(n,t){return K(t)?n instanceof t:!1}function p(n){return"[object RegExp]"===J.call(n)}function g(n){return"[object Date]"===J.call(n)}function y(n){return"[object String]"===J.call(n)}function b(n){return"[object Number]"===J.call(n)}function v(n){return n===!0}function m(n){return n===!1}function j(n){return!h(n)}function w(n,t){return n==t}function x(n,t){return n!=t}function _(n,t){return n===t}function A(n,t){return n!==t}function N(n,t){if(Q(t)&&Array.prototype.indexOf||y(t))return t.indexOf(n)>-1;if(Q(t))for(var e=0,r=t.length;r>e;e++)if(w(n,t[e]))return!0;return!1}function O(n,t){return!N(n,t)}function E(n,t){return t>n}function B(n,t){return t>=n}function q(n,t){return n>t}function L(n,t){return n>=t}function T(n,t){return y(t)?null!==(""+n).match(t):p(t)?t.test(n):!1}function I(n,t){return!T(n,t)}function S(n,t){return N(t,n)}function C(n,t){return!N(t,n)}function F(n,t,e){return Q(n)&&n.length>e?w(n[e],t):!1}function D(n,t,e){return Q(n)?!w(n[e],t):!1}function k(n,t){return z.call(n,t)}function G(n,t){return!k(n,t)}function H(n,t){return k(n,"length")?n.length===t:!1}function R(n,t){return k(n,"length")?n.length!==t:!1}function U(n){X[n]=function(){this._testers.push(V[n])}}function W(n){Y[n]=function(){var e,r=t(arguments,1),i=V[n],u=!0;if(r.length<=i.length-1)throw new TypeError("A handler must be defined when calling using switch");if(e=r.pop(),c(e)&&(u=e,e=r.pop()),!K(e))throw new TypeError("handler must be defined");this._cases.push(function(n){return i.apply(V,n.concat(r))?[u,e.apply(this,n)]:[!1]})}}var P=Array.prototype.slice,z=Object.prototype.hasOwnProperty,J=Object.prototype.toString,K=function(n){return"[object Function]"===J.call(n)};"undefined"==typeof window||K(window.alert)||function(n){K=function(t){return"[object Function]"===J.call(t)||t===n}}(window.alert);var M=function(n){return"[object Arguments]"===J.call(n)};M(arguments)||(M=function(n){return!(!n||!z.call(n,"callee"))});var Q=Array.isArray||function Q(n){return"[object Array]"===J.call(n)},V={isFunction:K,isObject:u,isEmpty:f,isHash:o,isNumber:b,isString:y,isDate:g,isArray:Q,isBoolean:c,isUndefined:s,isDefined:l,isUndefinedOrNull:a,isNull:h,isArguments:M,instanceOf:d,isRegExp:p,deepEqual:r,isTrue:v,isFalse:m,isNotNull:j,isEq:w,isNeq:x,isSeq:_,isSneq:A,isIn:N,isNotIn:O,isLt:E,isLte:B,isGt:q,isGte:L,isLike:T,isNotLike:I,contains:S,notContains:C,has:k,notHas:G,isLength:H,isNotLength:R,containsAt:F,notContainsAt:D},X={constructor:function(){this._testers=[]},noWrap:{tester:function(){var n=this._testers;return function(t){for(var e=!1,r=0,i=n.length;i>r&&!e;r++)e=n[r](t);return e}}}},Y={constructor:function(){this._cases=[],this.__default=null},def:function(n,t){this.__default=t},noWrap:{switcher:function(){var n=this._cases,e=this.__default;return function(){for(var r,i=!1,u=t(arguments),o=0,f=n.length;f>o&&!i;o++)if(r=n[o](u),r.length>1&&(r[1]||r[0]))return r[1];return!i&&e?e.apply(this,u):void 0}}}};for(var Z in V)z.call(V,Z)&&(W(Z),U(Z));var $=n.define(V).expose(V);return $.tester=n.define(X),$.switcher=n.define(Y),$}"undefined"!=typeof exports?"undefined"!=typeof module&&module.exports&&(module.exports=n(require("extended"))):"function"==typeof define&&define.amd?define(["../../../"],function(t){return n(t)}):this.isExtended=n(this.extended)}).call(this);
View
364 docs/examples/browser/assets/orbit_controls.js
@@ -0,0 +1,364 @@
+/**
+ * @author qiao / https://github.com/qiao
+ * @author mrdoob / http://mrdoob.com
+ * @author alteredq / http://alteredqualia.com/
+ * @author WestLangley / http://github.com/WestLangley
+ */
+
+THREE.OrbitControls = function ( object, domElement ) {
+
+ this.object = object;
+ this.domElement = ( domElement !== undefined ) ? domElement : document;
+
+ // API
+
+ this.enabled = true;
+
+ this.center = new THREE.Vector3();
+
+ this.userZoom = true;
+ this.userZoomSpeed = 1.0;
+
+ this.userRotate = true;
+ this.userRotateSpeed = 1.0;
+
+ this.userPan = true;
+ this.userPanSpeed = 2.0;
+
+ this.autoRotate = false;
+ this.autoRotateSpeed = 2.0; // 30 seconds per round when fps is 60
+
+ this.minPolarAngle = 0; // radians
+ this.maxPolarAngle = Math.PI; // radians
+
+ this.minDistance = 0;
+ this.maxDistance = Infinity;
+
+ this.keys = { LEFT: 37, UP: 38, RIGHT: 39, BOTTOM: 40 };
+
+ // internals
+
+ var scope = this;
+
+ var EPS = 0.000001;
+ var PIXELS_PER_ROUND = 1800;
+
+ var rotateStart = new THREE.Vector2();
+ var rotateEnd = new THREE.Vector2();
+ var rotateDelta = new THREE.Vector2();
+
+ var zoomStart = new THREE.Vector2();
+ var zoomEnd = new THREE.Vector2();
+ var zoomDelta = new THREE.Vector2();
+
+ var phiDelta = 0;
+ var thetaDelta = 0;
+ var scale = 1;
+
+ var lastPosition = new THREE.Vector3();
+
+ var STATE = { NONE: -1, ROTATE: 0, ZOOM: 1, PAN: 2 };
+ var state = STATE.NONE;
+
+ // events
+
+ var changeEvent = { type: 'change' };
+
+
+ this.rotateLeft = function ( angle ) {
+
+ if ( angle === undefined ) {
+
+ angle = getAutoRotationAngle();
+
+ }
+
+ thetaDelta -= angle;
+
+ };
+
+ this.rotateRight = function ( angle ) {
+
+ if ( angle === undefined ) {
+
+ angle = getAutoRotationAngle();
+
+ }
+
+ thetaDelta += angle;
+
+ };
+
+ this.rotateUp = function ( angle ) {
+
+ if ( angle === undefined ) {
+
+ angle = getAutoRotationAngle();
+
+ }
+
+ phiDelta -= angle;
+
+ };
+
+ this.rotateDown = function ( angle ) {
+
+ if ( angle === undefined ) {
+
+ angle = getAutoRotationAngle();
+
+ }
+
+ phiDelta += angle;
+
+ };
+
+ this.zoomIn = function ( zoomScale ) {
+
+ if ( zoomScale === undefined ) {
+
+ zoomScale = getZoomScale();
+
+ }
+
+ scale /= zoomScale;
+
+ };
+
+ this.zoomOut = function ( zoomScale ) {
+
+ if ( zoomScale === undefined ) {
+
+ zoomScale = getZoomScale();
+
+ }
+
+ scale *= zoomScale;
+
+ };
+
+ this.pan = function ( distance ) {
+
+ distance.transformDirection( this.object.matrix );
+ distance.multiplyScalar( scope.userPanSpeed );
+
+ this.object.position.add( distance );
+ this.center.add( distance );
+
+ };
+
+ this.update = function () {
+
+ var position = this.object.position;
+ var offset = position.clone().sub( this.center );
+
+ // angle from z-axis around y-axis
+
+ var theta = Math.atan2( offset.x, offset.z );
+
+ // angle from y-axis
+
+ var phi = Math.atan2( Math.sqrt( offset.x * offset.x + offset.z * offset.z ), offset.y );
+
+ if ( this.autoRotate ) {
+
+ this.rotateLeft( getAutoRotationAngle() );
+
+ }
+
+ theta += thetaDelta;
+ phi += phiDelta;
+
+ // restrict phi to be between desired limits
+ phi = Math.max( this.minPolarAngle, Math.min( this.maxPolarAngle, phi ) );
+
+ // restrict phi to be betwee EPS and PI-EPS
+ phi = Math.max( EPS, Math.min( Math.PI - EPS, phi ) );
+
+ var radius = offset.length() * scale;
+
+ // restrict radius to be between desired limits
+ radius = Math.max( this.minDistance, Math.min( this.maxDistance, radius ) );
+
+ offset.x = radius * Math.sin( phi ) * Math.sin( theta );
+ offset.y = radius * Math.cos( phi );
+ offset.z = radius * Math.sin( phi ) * Math.cos( theta );
+
+ position.copy( this.center ).add( offset );
+
+ this.object.lookAt( this.center );
+
+ thetaDelta = 0;
+ phiDelta = 0;
+ scale = 1;
+
+ if ( lastPosition.distanceTo( this.object.position ) > 0 ) {
+
+ this.dispatchEvent( changeEvent );
+
+ lastPosition.copy( this.object.position );
+
+ }
+
+ };
+
+
+ function getAutoRotationAngle() {
+
+ return 2 * Math.PI / 60 / 60 * scope.autoRotateSpeed;
+
+ }
+
+ function getZoomScale() {
+
+ return Math.pow( 0.95, scope.userZoomSpeed );
+
+ }
+
+ function onMouseDown( event ) {
+
+ if ( scope.enabled === false ) return;
+ if ( scope.userRotate === false ) return;
+
+ event.preventDefault();
+
+ if ( event.button === 0 ) {
+
+ state = STATE.ROTATE;
+
+ rotateStart.set( event.clientX, event.clientY );
+
+ } else if ( event.button === 1 ) {
+
+ state = STATE.ZOOM;
+
+ zoomStart.set( event.clientX, event.clientY );
+
+ } else if ( event.button === 2 ) {
+
+ state = STATE.PAN;
+
+ }
+
+ document.addEventListener( 'mousemove', onMouseMove, false );
+ document.addEventListener( 'mouseup', onMouseUp, false );
+
+ }
+
+ function onMouseMove( event ) {
+
+ if ( scope.enabled === false ) return;
+
+ event.preventDefault();
+
+ if ( state === STATE.ROTATE ) {
+
+ rotateEnd.set( event.clientX, event.clientY );
+ rotateDelta.subVectors( rotateEnd, rotateStart );
+
+ scope.rotateLeft( 2 * Math.PI * rotateDelta.x / PIXELS_PER_ROUND * scope.userRotateSpeed );
+ scope.rotateUp( 2 * Math.PI * rotateDelta.y / PIXELS_PER_ROUND * scope.userRotateSpeed );
+
+ rotateStart.copy( rotateEnd );
+
+ } else if ( state === STATE.ZOOM ) {
+
+ zoomEnd.set( event.clientX, event.clientY );
+ zoomDelta.subVectors( zoomEnd, zoomStart );
+
+ if ( zoomDelta.y > 0 ) {
+
+ scope.zoomIn();
+
+ } else {
+
+ scope.zoomOut();
+
+ }
+
+ zoomStart.copy( zoomEnd );
+
+ } else if ( state === STATE.PAN ) {
+
+ var movementX = event.movementX || event.mozMovementX || event.webkitMovementX || 0;
+ var movementY = event.movementY || event.mozMovementY || event.webkitMovementY || 0;
+
+ scope.pan( new THREE.Vector3( - movementX, movementY, 0 ) );
+
+ }
+
+ }
+
+ function onMouseUp( event ) {
+
+ if ( scope.enabled === false ) return;
+ if ( scope.userRotate === false ) return;
+
+ document.removeEventListener( 'mousemove', onMouseMove, false );
+ document.removeEventListener( 'mouseup', onMouseUp, false );
+
+ state = STATE.NONE;
+
+ }
+
+ function onMouseWheel( event ) {
+
+ if ( scope.enabled === false ) return;
+ if ( scope.userZoom === false ) return;
+
+ var delta = 0;
+
+ if ( event.wheelDelta ) { // WebKit / Opera / Explorer 9
+
+ delta = event.wheelDelta;
+
+ } else if ( event.detail ) { // Firefox
+
+ delta = - event.detail;
+
+ }
+
+ if ( delta > 0 ) {
+
+ scope.zoomOut();
+
+ } else {
+
+ scope.zoomIn();
+
+ }
+
+ }
+
+ function onKeyDown( event ) {
+
+ if ( scope.enabled === false ) return;
+ if ( scope.userPan === false ) return;
+
+ switch ( event.keyCode ) {
+
+ case scope.keys.UP:
+ scope.pan( new THREE.Vector3( 0, 1, 0 ) );
+ break;
+ case scope.keys.BOTTOM:
+ scope.pan( new THREE.Vector3( 0, - 1, 0 ) );
+ break;
+ case scope.keys.LEFT:
+ scope.pan( new THREE.Vector3( - 1, 0, 0 ) );
+ break;
+ case scope.keys.RIGHT:
+ scope.pan( new THREE.Vector3( 1, 0, 0 ) );
+ break;
+ }
+
+ }
+
+ this.domElement.addEventListener( 'contextmenu', function ( event ) { event.preventDefault(); }, false );
+ this.domElement.addEventListener( 'mousedown', onMouseDown, false );
+ this.domElement.addEventListener( 'mousewheel', onMouseWheel, false );
+ this.domElement.addEventListener( 'DOMMouseScroll', onMouseWheel, false ); // firefox
+ this.domElement.addEventListener( 'keydown', onKeyDown, false );
+
+};
+
+THREE.OrbitControls.prototype = Object.create( THREE.EventDispatcher.prototype );
View
214 docs/examples/browser/conways_2d.html
@@ -0,0 +1,214 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <meta charset="utf-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
+ <title>Conways</title>
+ <link type="text/css" rel="stylesheet" href="assets/conways.css">
+ <link type="text/css" rel="stylesheet" href="//code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css">
+ <link href='http://fonts.googleapis.com/css?family=Londrina+Shadow' rel='stylesheet' type='text/css'>
+</head>
+<body>
+
+<div class="container">
+ <header>
+ <h1>Conways Game Of Life 2D</h1>
+
+ <form>
+ <input type="submit" id="run" value="Run!"/>
+ <input type="button" id="stop" value="Stop"/>
+ <input type="button" id="clear" value="Clear"/>
+ <input type="button" id="edit" value="Edit Rules"/>
+ <select id="patterns"></select>
+ </form>
+ </header>
+ <div id="grid"></div>
+</div>
+
+<div id="editor-dialog">
+ <div id="editor"></div>
+</div>
+
+<script type="text/javascript" src="//code.jquery.com/jquery-1.10.1.min.js"></script>
+<script type="text/javascript" src="//code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
+<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/ace/0.2.0/ace.js"></script>
+<script type="text/javascript" src="../../nools.js"></script>
+<script type="text/javascript" src="src/common.js"></script>
+<script type="text/javascript" src="src/patterns.js"></script>
+<script type="text/javascript" src="src/cell.js"></script>
+<script type="text/javascript" src="rules/conways.js"></script>
+<script type="text/javascript">
+
+ (function () {
+ var session, statsListener,
+ matchPromise = promise(), currPattern = patterns.hi;
+
+
+ var grid = $("#grid"), cells = [], rows = Math.floor((window.innerHeight - 100) / 25), cols = Math.floor(window.innerWidth / 20);
+
+ function setCellState(cell, isAlive) {
+ cell.state = isAlive ? "live" : "dead";
+ cell.el.removeClass(isAlive ? "dead" : "live").addClass(isAlive ? "live" : "dead");
+ }
+
+ function promise() {
+ return {
+ then: function (cb) {
+ return cb() || this;
+ }
+ }
+ }
+
+ function createGrid() {
+ grid.empty();
+ cells = [];
+ for (var row = 0; row < rows; row++) {
+ cells[row] = [];
+ var rowDom = $("<div/>").addClass("row").appendTo(grid);
+ for (var col = 0; col < cols; col++) {
+ var cell = cells[row][col] = new Cell(row, col);
+ cell.el = $("<div class='col dead'></div>").appendTo(rowDom);
+ setCellState(cell, false);
+ if (row > 0) {
+ cell.addNeighbor(cells[cell.row - 1][cell.col]);
+ if (col < cols - 1) {
+ cell.addNeighbor(cells[cell.row - 1][cell.col + 1]);
+ }
+ if (col > 0) {
+ cell.addNeighbor(cells[cell.row - 1][cell.col - 1]);
+ }
+ }
+ if (row >= 0 && col > 0) {
+ cell.addNeighbor(cells[cell.row][cell.col - 1]);
+ }
+ }
+ }
+ }
+
+ function applyPattern(pattern) {
+ return stop().then(function () {
+ pattern = pattern || currPattern(rows, cols)
+ if (cells.length) {
+ var row;
+ for (var i = 0; i < rows; i++) {
+ row = pattern[i] || [];
+ for (var j = 0; j < cols; j++) {
+ setCellState(cells[i][j], row[j] || false);
+ }
+ }
+ }
+ });
+ }
+
+ function clear() {
+ return stop().then(function () {
+ applyPattern([]);
+ });
+ }
+
+ function run() {
+ createGrid();
+ applyPattern();
+ session = statsListener.listen(flow.getSession());
+ session.assert(cells);
+ session.focus("populate")
+ .on("cell-transition", function (cell) {
+ var isAlive = cell.state === "live";
+ cell.el
+ .removeClass(isAlive ? "dead" : "live")
+ .addClass(isAlive ? "live" : "dead");
+ });
+ return (matchPromise = session.matchUntilHalt()).then(function () {
+ session.dispose();
+ }, function (err) {
+ throw err;
+ });
+
+ }
+
+ function stop() {
+ if (session) {
+ session.dispose();
+ session.halt();
+ return matchPromise;
+ }
+ return promise();
+ }
+
+
+ $(document).ready(function () {
+ $.ajax({
+ url: "./rules/conways.nools"
+ }).then(function (res) {
+
+ var flowStr = res;
+ flow = nools.compile(res, {name: "conways2d", define: {Cell: Cell}, scope: { loop: loop}});
+
+ statsListener = stats();
+ //setup grid;
+ createGrid();
+ var $select = $("#patterns");
+ $select.append($('<option/>', {
+ value: i,
+ text: i
+ }));
+ for (var i in patterns) {
+ $select.append($('<option/>', {
+ value: i,
+ text: i
+ }));
+ }
+ $select.on("change", function () {
+ currPattern = patterns[$(this).val()];
+ stop().then(function () {
+ applyPattern();
+ });
+ });
+ $select.val("random").trigger("change");
+
+ $("form").on("submit", function () {
+ run();
+ return false;
+ });
+
+ $("#stop").on("click", function () {
+ stop();
+ });
+
+ $("#clear").on("click", function () {
+ clear();
+ });
+
+ $("#edit").on("click", function () {
+ $("#editor-dialog").dialog("open");
+ return false;
+ });
+
+ $("#editor-dialog").dialog({
+ autoOpen: false,
+ modal: true,
+ width: window.innerWidth * 0.9,
+ height: window.innerHeight * 0.9,
+ open: function () {
+ (editor = ace.edit("editor").getSession()).setValue(flowStr);
+ },
+ buttons: {
+ "Save": function () {
+ $(this).dialog("close");
+ nools.deleteFlow("conways2d");
+ stop().then(run);
+ flow = nools.compile((flowStr = editor.getValue()), {name: "conways2d", define: {Cell: Cell}, scope: { loop: loop}});
+ },
+ Cancel: function () {
+ $(this).dialog("close");
+ }
+ }
+ });
+
+ });
+ });
+ }());
+</script>
+
+</body>
+</html>
View
123 docs/examples/browser/conways_3d.html
@@ -0,0 +1,123 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <title>Conways 3d</title>
+ <meta charset="utf-8">
+ <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
+ <link type="text/css" rel="stylesheet" href="assets/conways.css">
+ <link type="text/css" rel="stylesheet" href="//code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css">
+ <link href='http://fonts.googleapis.com/css?family=Londrina+Shadow' rel='stylesheet' type='text/css'>
+</head>
+<body>
+<div class="controls">
+ <h1>Conways Game Of Life 3D</h1>
+
+
+ <input type="button" id="run" value="Run!"/>
+ <input type="button" id="stop" value="Stop"/>
+ <input type="button" id="clear" value="Clear"/>
+ <input type="button" id="reset" value="Reset"/>
+ <input type="button" id="edit" value="Edit Rules"/>
+
+ <div>
+ <label for="patterns">Patterns</label>
+ <select id="patterns"></select>
+ <label for="patterns">Dimensions</label>
+ <input type="number" id="dimensions"/>
+ <span id="fact-count"/>
+ </div>
+
+</div>
+<div class="container"></div>
+<div id="editor-dialog">
+ <div id="editor"></div>
+</div>
+
+<script type="text/javascript" src="//code.jquery.com/jquery-1.10.1.min.js"></script>
+<script type="text/javascript" src="//code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
+<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/three.js/r58/three.min.js"></script>
+<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/ace/0.2.0/ace.js"></script>
+<script type="text/javascript" src="assets/declare.js"></script>
+<script type="text/javascript" src="assets/extender.js"></script>
+<script type="text/javascript" src="assets/extended.js"></script>
+<script type="text/javascript" src="assets/is-extended.js"></script>
+<script type="text/javascript" src="assets/arguments-extended.js"></script>
+<script type="text/javascript" src="assets/function-extended.js"></script>
+<script type="text/javascript" src="assets/orbit_controls.js"></script>
+<script type="text/javascript" src="../../nools.js"></script>
+<script type="text/javascript" src="src/common.js"></script>
+<script type="text/javascript" src="src/cell.js"></script>
+<script type="text/javascript" src="src/patterns3d.js"></script>
+<script type="text/javascript" src="src/conway_3d.js"></script>
+<script type="text/javascript">
+
+ $(document).ready(function () {
+ $.ajax({
+ url: "./rules/conways3d.nools"
+ }).then(function (res) {
+ var flowStr, editor, flow, factCountDom = $("#fact-count"), dim = 15;
+
+ flowStr = res;
+ flow = nools.compile(res, {name: "conways3d", define: {Cell: Cell}, scope: { loop: loop}});
+ var conways3d = conways(".container", dim, flow);
+ var $select = $("#patterns");
+ $select.append($('<option/>', {
+ value: "none",
+ text: ""
+ }));
+ factCountDom.text("Total Cells: " + (dim * dim * dim));
+ for (var i in patterns) {
+ if (i !== "none") {
+ $select.append($('<option/>', {
+ value: i,
+ text: i
+ }));
+ }
+ }
+ $select.on("change", function () {
+ conways3d.set("pattern", $(this).val());
+ });
+ $select.val("border").trigger("change");
+ $("#run").on("click", conways3d.run);
+ $("#edit").on("click", function () {
+ $("#editor-dialog").dialog("open");
+ return false;
+ });
+ $("#stop").on("click", conways3d.stop);
+ $("#clear").on("click", conways3d.clear);
+ $("#reset").on("click", conways3d.reset);
+
+ $("#dimensions").on("change", function () {
+ var dim = parseInt($(this).val(), 10);
+ if (!isNaN(dim)) {
+ factCountDom.text("Total Cells: " + (dim * dim * dim));
+ conways3d.set("dimensions", dim);
+ }
+ });
+
+ $("#editor-dialog").dialog({
+ autoOpen: false,
+ modal: true,
+ width: window.innerWidth * 0.9,
+ height: window.innerHeight * 0.9,
+ open: function () {
+ (editor = ace.edit("editor").getSession()).setValue(flowStr);
+ },
+ buttons: {
+ "Save": function () {
+ $(this).dialog("close");
+ nools.deleteFlow("conways3d");
+ conways3d.set("flow", nools.compile((flowStr = editor.getValue()), {name: "conways3d", define: {Cell: Cell}, scope: { loop: loop}}));
+ },
+ Cancel: function () {
+ $(this).dialog("close");
+ }
+ }
+ });
+ });
+ });
+
+
+</script>
+</body>
+</html>
View
117 docs/examples/browser/fibonacci.html
@@ -0,0 +1,117 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <meta charset="utf-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
+ <link type="text/css" rel="stylesheet" href="assets/conways.css">
+ <link href='http://fonts.googleapis.com/css?family=Londrina+Shadow' rel='stylesheet' type='text/css'>
+ <title>Fibonacci</title>
+</head>
+<body>
+
+<div id="fibonacci" class="middle">
+
+ <h1>Fibonacci</h1>
+
+ <form id="fibonacci_form" action="#">
+ <div class="inline">
+ <input type="text" id="val"/>
+ </div>
+ <div class="inline">
+ <div class="large"><span>=</span></div>
+ </div>
+ <div class="inline large" id="results_container">
+ </div>
+ </form>
+</div>
+
+<script type="text/javascript" src="//code.jquery.com/jquery-1.10.1.min.js"></script>
+<script type="text/javascript" src="./src/common.js"></script>
+<script type="text/javascript" src="../../nools.js"></script>
+<script type="text/javascript">
+ (function () {
+
+ var outputDiv = document.getElementById("output"), statsListener = stats();
+
+
+ var Fibonacci = function (sequence, value) {
+ this.sequence = sequence;
+ this.value = value || -1;
+ };
+
+ var Result = function (result) {
+ this.result = result || -1;
+ };
+
+
+ var flow = nools.flow("Fibonacci Flow", function (flow) {
+
+ flow.rule("Recurse", [
+ ["not", Fibonacci, "f", "f.sequence == 1"],
+ [Fibonacci, "f1", "f1.sequence != 1"]
+ ], function (facts) {
+ var f2 = new Fibonacci(facts.f1.sequence - 1);
+ this.assert(f2);
+ });
+
+ flow.rule("Bootstrap", [
+ Fibonacci, "f", "f.value == -1 && (f.sequence == 1 || f.sequence == 2)"
+ ], function (facts) {
+ var f = facts.f;
+ f.value = 1;
+ this.modify(f);
+ });
+
+ flow.rule("Calculate", [
+ [Fibonacci, "f1", "f1.value != -1", {sequence: "s1"}],
+ [Fibonacci, "f2", "f2.value != -1 && f2.sequence == s1 + 1", {sequence: "s2"}],
+ [Fibonacci, "f3", "f3.value == -1 && f3.sequence == s2 + 1"],
+ [Result, "r"]
+ ], function (facts) {
+ var f3 = facts.f3, f1 = facts.f1, f2 = facts.f2;
+ var v = f3.value = f1.value + facts.f2.value;
+ this.emit("result", v);
+ facts.r.result = v;
+ this.modify(f3);
+ this.retract(f1);
+ });
+ });
+
+ function calculate(num) {
+ var result = new Result();
+ statsListener.listen(flow.getSession(new Fibonacci(num), result))
+ .on("result", function (res) {
+ resultsContainer.text(result.result);
+ })
+ .match().then(function () {
+ resultsContainer.text(result.result);
+ });
+ }
+
+
+ var resultsContainer = $("#results_container"), valInput = $("#val");
+ $("#fibonacci_form").on('submit', function () {
+ var num = parseInt(valInput.val(), 10);
+ resultsContainer.text("Calculating...");
+ if (!isNaN(num)) {
+ if (num > 2 && num < 1477) {
+ calculate(num);
+ } else if (num <= 2) {
+ resultsContainer.text("1");
+ } else if (num >= 1477) {
+ resultsContainer.text("I cant count that high!");
+ }
+ } else {
+ resultsContainer.text("Seriously?");
+ }
+ return false;
+ });
+
+ valInput.val(10);
+ calculate(10);
+
+ }());
+</script>
+
+</body>
+</html>
View
144 docs/examples/browser/manners.html
@@ -0,0 +1,144 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <meta charset="utf-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
+ <link type="text/css" rel="stylesheet" href="assets/conways.css">
+ <link type="text/css" rel="stylesheet" href="//code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css">
+ <link href='http://fonts.googleapis.com/css?family=Londrina+Shadow' rel='stylesheet' type='text/css'>
+ <title>Manners Benchmark</title>
+</head>
+<body>
+
+
+<div id="manners" class="middle">
+ <h1>Manners Benchmark</h1>
+
+ <form>
+
+ <select id="guests">
+ <option value="manners5">Manners 5</option>
+ <option value="manners8">Manners 8</option>
+ <option value="manners16">Manners 16</option>
+ <option value="manners32">Manners 32</option>
+ <option value="manners64">Manners 64</option>
+ <option value="manners128">Manners 128</option>
+ </select>
+ <input type="submit" value="Run"/>
+ <input type="button" id="edit" value="Edit Rules"/>
+
+ <div class="middle" id="results_container">
+ </div>
+
+ </form>
+
+</div>
+
+<div id="editor-dialog">
+ <div id="editor"></div>
+</div>
+
+<script type="text/javascript" src="//code.jquery.com/jquery-1.10.1.min.js"></script>
+<script type="text/javascript" src="//code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
+<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/ace/0.2.0/ace.js"></script>
+<script type="text/javascript" src="../../nools.js"></script>
+<script type="text/javascript" src="./src/common.js"></script>
+<script type="text/javascript" src="./src/guests.js"></script>
+<script type="text/javascript">
+
+ $(document).ready(function () {
+ $.ajax({
+ url: "./rules/manners.nools"
+ }).then(function (res) {
+
+ var session, dataset,
+ resultsContainer = $("#results_container"),
+ statsListener = stats(),
+ flowStr = res,
+ flow = nools.compile(res, {name: "manners"}),
+ Count = flow.getDefined("count");
+
+ function stop() {
+ if (session) {
+ session.dispose();
+ resultsContainer.empty();
+ session = null;
+ }
+ }
+
+ function createSeat(seating) {
+ return $("<div/>", {
+ text: seating.toString()
+ });
+ }
+
+ function run() {
+ stop();
+ var guests = loadGuests(flow, dataset);
+ session = statsListener.listen(flow.getSession());
+ for (var i = 0, l = guests.length; i < l; i++) {
+ session.assert(guests[i]);
+ }
+ session.assert(new Count({value: 1}));
+ session
+ .on("pathDone", function (obj) {
+ resultsContainer.append(createSeat(obj.seating));
+ })
+ .match().then(function () {
+ console.log("done");
+ }, function (e) {
+ console.log(e.stack);
+ })
+ }
+
+
+ var statsListener = stats();
+ //setup grid;
+
+ var $select = $("#guests");
+
+ $select.on("change", function () {
+ stop();
+ dataset = $(this).val();
+ });
+
+ $select.val("manners16").trigger("change");
+
+ $("form").on("submit", function () {
+ run();
+ return false;
+ });
+
+ $("#edit").on("click", function () {
+ $("#editor-dialog").dialog("open");
+ return false;
+ });
+
+ $("#editor-dialog").dialog({
+ autoOpen: false,
+ modal: true,
+ width: window.innerWidth * 0.9,
+ height: window.innerHeight * 0.9,
+ open: function () {
+ (editor = ace.edit("editor").getSession()).setValue(flowStr);
+ },
+ buttons: {
+ "Save": function () {
+ $(this).dialog("close");
+ nools.deleteFlow("manners");
+ stop();
+ flow = nools.compile((flowStr = editor.getValue()), {name: "manners"});
+ },
+ Cancel: function () {
+ $(this).dialog("close");
+ }
+ }
+ });
+
+ });
+ })
+ ;
+</script>
+
+</body>
+</html>
View
62 docs/examples/browser/rules/conways.nools
@@ -0,0 +1,62 @@
+rule Populate {
+ agenda-group: 'populate'
+ when {
+ cells: Array;
+ }
+ then {
+ loop(cells, function(cell){
+ assert(cell);
+ });
+ emit("evaluate");
+ focus("evaluate");
+ }
+}
+
+rule KillTheLonely{
+ agenda-group: 'evaluate'
+ when {
+ c : Cell c.state == 'live' && c.numberOfLiveNeighbors() < 2;
+ }
+ then {
+ c.queueNextState("dead");
+ }
+}
+
+rule KillTheOverCrowded{
+ agenda-group: 'evaluate'
+ when {
+ c : Cell c.state == 'live' && c.numberOfLiveNeighbors() > 3;
+ }
+ then {
+ c.queueNextState("dead");
+ }
+}
+
+rule GiveBirth{
+ agenda-group: 'evaluate'
+ when {
+ c : Cell c.state == 'dead' && c.numberOfLiveNeighbors() == 3;
+ }
+ then {
+ c.queueNextState("live");
+ }
+}
+
+
+rule Transition {
+ when {
+ cells: Array;
+ }
+ then {
+ var transitioned = false;
+ loop(cells, function(cell){
+ if(cell.transition()){
+ emit("cell-transition", cell);
+ transitioned = true;
+ }
+ retract(cell);
+ });
+ modify(cells);
+ focus("populate");
+ }
+}
View
84 docs/examples/browser/rules/conways3d.nools
@@ -0,0 +1,84 @@
+
+function loop(cells, cb){
+ var rows = cells.length, cols = cells[0].length, row, rowLength, col, colDepth;
+ for (var i = 0; i < rows; i++) {
+ row = cells[i];
+ rowLength = row.length;
+ for (var j = 0; j < rowLength; j++) {
+ col = row[j];
+ colDepth = col.length;
+ for(var k = 0; k < colDepth; k++){
+ cb(col[k], i, j, k, cells);
+ }
+ }
+ }
+}
+
+rule Populate {
+ agenda-group: 'populate'
+ when {
+ cells: Array;
+ }
+ then {
+ loop(cells, function(cell){
+ assert(cell);
+ });
+ focus("evaluate");
+ }
+}
+
+rule KillTheLonely{
+ agenda-group: 'evaluate'
+ when {
+ c : Cell c.state == 'live' && c.numberOfLiveNeighbors() < 2;
+ }
+ then {
+ c.queueNextState("dead");
+ retract(c);
+ }
+}
+
+rule KillTheOverCrowded{
+ agenda-group: 'evaluate'
+ when {
+ c : Cell c.state == 'live' && c.numberOfLiveNeighbors() > 3;
+ }
+ then {
+ c.queueNextState("dead");
+ retract(c);
+ }
+}
+
+rule GiveBirth{
+ agenda-group: 'evaluate'
+ when {
+ c : Cell c.state == 'dead' && c.numberOfLiveNeighbors() == 3;
+ }
+ then {
+ c.queueNextState("live");
+ retract(c);
+ }
+}
+
+
+rule Transition {
+ when {
+ cells: Array;
+ }
+ then {
+ var transitioned = false;
+ loop(cells, function(cell){
+ if(cell.transition()){
+ emit("cell-transition", cell);
+ transitioned = true;
+ }
+ });
+ emit("evaluate");
+ modify(cells);
+ if(transitioned){
+ focus("populate");
+ }else{
+ halt();
+ }
+ }
+}
View
50 docs/examples/browser/rules/fibonacci.nools
@@ -0,0 +1,50 @@
+//Define our object classes, you can
+//also declare these outside of the nools
+//file by passing them into the compile method
+define Fibonacci {
+ value:-1,
+ sequence:null
+}
+define Result {
+ value : -1
+}
+
+rule Recurse {
+ when {
+ //you can use not or or methods in here
+ not(f : Fibonacci f.sequence == 1);
+ //f1 is how you can reference the fact else where
+ f1 : Fibonacci f1.sequence != 1;
+ }
+ then {
+ assert(new Fibonacci({sequence : f1.sequence - 1}));
+ }
+}
+
+rule Bootstrap {
+ when {
+ f : Fibonacci f.value == -1 && (f.sequence == 1 || f.sequence == 2);
+ }
+ then{
+ modify(f, function(){
+ this.value = 1;
+ });
+ }
+}
+
+rule Calculate {
+ when {
+ f1 : Fibonacci f1.value != -1 {sequence : s1};
+ //here we define constraints along with a hash so you can reference sequence
+ //as s2 else where
+ f2 : Fibonacci f2.value != -1 && f2.sequence == s1 + 1 {sequence:s2};
+ f3 : Fibonacci f3.value == -1 && f3.sequence == s2 + 1;
+ r : Result
+ }
+ then {
+ modify(f3, function(){
+ this.value = r.result = f1.value + f2.value;
+ });
+ retract(f1);
+ }
+}
View
181 docs/examples/browser/rules/manners.nools
@@ -0,0 +1,181 @@
+//Define our models
+//can be retrieved in JS by calling by:
+//var Chosen = flow.getDefined("chosen");
+//var chosen = new Chosen({id : 1, guestName : "bob", hobby : "my hobby"});
+define Chosen {
+ id : null,
+ guestName : null,
+ hobby : null,
+ toString:function () {
+ return ["[Chosen : id=", this.id, " name=", this.guestName, " hobby=", this.hobby, "]"].join(" ");
+ }
+}
+
+define Context {
+ state : "start",
+ toString:function () {
+ return ["[Context state =", this.stringValue, "]"].join("");
+ }
+}
+
+define Count {
+ value : 0,
+ toString:function () {
+ return ["[Count value=", this.value, "]"].join("");
+ }
+}
+
+define Guest {
+ name : "",
+ sex : "",
+ hobby : "",
+ toString:function () {
+ return ["[Guest name=", this.name, ", sex=", this.sex, ", hobbies=", this.hobby, "]"].join("");
+ }
+}
+
+define LastSeat {
+ seat : null,
+ toString:function () {
+ return ["[LastSeat seat=", this.seat, "]"].join("");
+ }
+}
+
+define Path {
+ id : null,
+ seat : null,
+ guestName : null,
+ toString:function () {
+ return ["[Path id=", this.id, " name=", this.guestName, " seat=", this.seat, "]"].join("");
+ }
+}
+
+
+define Seating {
+ id : null,
+ pid : null,
+ path : null,
+ leftSeat : null,
+ leftGuestName : null,
+ rightSeat : null,
+ rightGuestName : null,
+ toString:function () {
+ return ["[Seating id=", this.id, " pid=", this.pid, " pathDone=", this.path, " leftSeat=", this.leftSeat,
+ " leftGuestName=", this.leftGuestName, " rightSeat=", this.rightSeat, " rightGuestName=", this.rightGuestName, "]"].join("")
+ }
+}
+
+rule assignFirstSeat {
+ when {
+ c : Context c.state == 'start';
+ g : Guest;
+ count : Count;
+ }
+ then {
+ var leftGuestName = g.name;
+ var seating = new Seating({
+ id : count.value,
+ pid : 0,
+ path : true,
+ leftSeat : 1,
+ leftGuestName : leftGuestName,
+ rightSeat : 1,
+ rightGuestName : leftGuestName
+ });
+ assert(seating);
+ var path = new Path({id : count.value, seat : 1, guestName : leftGuestName});
+ assert(path);
+ modify(count, function(){
+ this.value++
+ });
+ emit('assign', {seating: seating, path: path});
+ modify(c, function(){
+ this.state = 'assign';
+ });
+ }
+}
+
+
+rule findSeating {
+ when {
+ c : Context c.state == 'assign';
+ s : Seating s.path == true {id : sid, rightGuestName : seatingRightGuestName, rightSeat : rightSeat};
+ g : Guest g.name == seatingRightGuestName {sex : rightGuestSex, hobby : rightGuestHobby};
+ lg : Guest lg.sex != rightGuestSex && lg.hobby == rightGuestHobby {name : leftGuestName};
+ count : Count {value : countValue};
+ not(p : Path p.id == sid && p.guestName == leftGuestName);
+ not(chosen : Chosen chosen.id == sid && chosen.guestName == leftGuestName && chosen.hobby == rightGuestHobby);
+ }
+ then {
+ assert(new Seating({
+ id : countValue,
+ pid : sid,
+ path : false,
+ leftSeat : s.rightSeat,
+ leftGuestName : seatingRightGuestName,
+ rightSeat : rightSeat + 1,
+ rightGuestName : leftGuestName
+ }));
+ var path = new Path({id : countValue, seat : rightSeat + 1, guestName : leftGuestName});
+ assert(path);
+ assert(new Chosen({id : sid, guestName : leftGuestName, hobby : rightGuestHobby}));
+ modify(count, function(){this.value++;});
+ modify(c, function(){this.state = 'make'});
+ }
+}
+
+rule makePath {
+ when {
+ c : Context c.state == 'make';
+ s : Seating s.path == false {id : sid, pid : seatingPid};
+ p : Path p.id == seatingPid {guestName : pathGuestName, seat : pathSeat};
+ not( p2 : Path p2.id == sid && p2.guestName == pathGuestName);
+ }
+ then {
+ assert(new Path({id : sid, seat : pathSeat, guestName : pathGuestName}));
+ }
+}
+
+rule pathDone {
+ when {
+ c : Context c.state == 'make';
+ s : Seating s.path == false;
+ }
+ then {
+ modify(s, function(){
+ this.path = true;
+ });
+ modify(c, function(){
+ this.state = 'check';
+ });
+ emit('pathDone', {seating: s});
+ }
+}
+
+rule areWeDone {
+ when {
+ c : Context c.state == 'check';
+ ls : LastSeat {seat : lastSeat};
+ s : Seating s.rightSeat == lastSeat;
+ }
+ then {
+ modify(c, function(){this.state = 'print';})
+ }
+}
+
+rule continue {
+ when {
+ c : Context c.state == 'check';
+ }
+ then {
+ modify(c, function(){this.state = 'assign'});
+ }
+}
+
+rule allDone {
+ when {
+ c : Context c.state == 'print';
+ }
+ then {
+ }
+}
View
64 docs/examples/browser/src/cell.js
@@ -0,0 +1,64 @@
+(function () {
+ var Cell = this.Cell = function (row, col, colDepth) {
+ this.col = col;
+ this.row = row;
+ this.colDepth = colDepth;
+ this.neighbors = [];
+ };
+
+ var proto = Cell.prototype;
+ proto.state = "dead";
+ proto.evaluated = false;
+ proto.__queuedState = null;
+
+ proto.numberOfLiveNeighbors = function () {
+ var live = 0, neighbors = this.neighbors, neighbor;
+ for (var i = 0, l = neighbors.length; i < l; i++) {
+ if (neighbors[i].state === "live") {
+ live++;
+ }
+ }
+ return live;
+ };
+
+ proto.addNeighbor = function (neighbor) {
+ if (neighbor !== this && this.neighbors.indexOf(neighbor === -1)) {
+ this.neighbors.push(neighbor);
+ neighbor.neighbors.push(this);
+ return this;
+ } else {
+ throw new Error("duplicate neighbor");
+ }
+ };
+
+ proto.queueNextState = function (state) {
+ if (this.state !== state) {
+ this.__queuedState = state;
+ }
+ };
+
+ proto.shouldTransition = function () {
+ return this.__queuedState !== null;
+ };
+
+ proto.transition = function () {
+ var ret = false;
+ if (this.shouldTransition()) {
+ this.state = this.__queuedState;
+ this.__queuedState = null;
+ ret = true;
+ }
+ return ret;
+ };
+
+ this.loop = function loop(cells, cb) {
+ var rows = cells.length, cols = cells[0].length;
+ for (var i = 0; i < rows; i++) {
+ for (var j = 0; j < cols; j++) {
+ cb(cells[i][j], i, j, cells);
+ }
+ }
+ };
+
+
+}).call(this);
View
94 docs/examples/browser/src/common.js
@@ -0,0 +1,94 @@
+(function () {
+ /*global $*/
+
+// <div id="log" class="detail">
+// <div>
+// <span id="running_time">RunningTime: 0min</span>
+// </div>
+// <div>
+// <div class="inline">
+// <div id="assertions_count">Facts asserted: 0</div>
+// <div id="retractions_count">Facts retracted: 0</div>
+// <div id="fires_count">Rules fired: 0</div>
+// </div>
+// </div>
+// </div>
+
+ function stats() {
+
+ var container = $("<div/>").addClass("detail"),
+ runningTimeSpan = $("<span/>", {text: "running time: 0min"}),
+ assertionsSpan = $("<div/>", {text: "facts asserted: 0"}),
+ modifiesSpan = $("<div/>", {text: "facts modified: 0"}),
+ retractionsSpan = $("<div/>", {text: "facts retracted: 0"}),
+ firesSpan = $("<span/>", {text: "rules fired: 0"});
+ var currDiv = $("<div/>");
+ runningTimeSpan.appendTo(currDiv);
+ currDiv.appendTo(container);
+ currDiv = $("<div/>");
+ var inlineDiv = $("<div/>").addClass("inline");
+ assertionsSpan.appendTo(inlineDiv);
+ retractionsSpan.appendTo(inlineDiv);
+ modifiesSpan.appendTo(inlineDiv);
+ firesSpan.appendTo(inlineDiv);
+ inlineDiv.appendTo(currDiv);
+ currDiv.appendTo(container);
+ container.appendTo("body");
+ var transCum = 0,
+ aTime = new Date(),
+ assertions = 0,
+ retractions = 0,