Skip to content

Instantly share code, notes, and snippets.

@ympbyc
Created March 26, 2015 09:20
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 ympbyc/9a7256768a5561ce4eba to your computer and use it in GitHub Desktop.
Save ympbyc/9a7256768a5561ce4eba to your computer and use it in GitHub Desktop.
ekolu sketch
window.Ekolu = (function () {
var ekolu = {};
ekolu.xyz = function (x, y, z) {
return {x: x, y: y, z: z};
};
ekolu._Thread = function (coordinates_system, pos_rot, ai, vision, visual) {
this.coordinates_system = coordinates_system || _.identity;
this.pos_rot = pos_rot || function (t) { return ekolu.xyz(0,0,0); };
this.ai = ai || [];
this.vision = vision || function (space) { return []; };
this.visual = visual || {};
};
ekolu.thread = function (coordinates_system, pos_rot, ai, vision, visual) {
return new ekolu._Thread(coordinates_system, pos_rot, ai, vision, visual);
};
ekolu.CS = {
circle: function (ax0, ax1) {
return function (pos) {
return _.assoc({}.
ax0, pos.radius * Math.cos(pos.theta),
ax1, pos.radius * Math.sin(pos.theta));
};
}
};
ekolu.VOC= {};
ekolu.VOC.recognize = function (name) {
return function (ss) { return ss.name === name; };
};
ekolu.VOC.vision360 = function (radius) {
return function (pos) {
return space.see(function (thr) {
return thr.x - pos.x <= radius
&& thr.y - pos.y <= radius
&& thr.z - pos.z <= radius;
});
};
};
ekolu.POS = {};
ekolu.POS.static = function (we, pos) { return pos; };
return ekolu;
}());
var ekolu = window.Ekolu;
ekolu.thread(
ekolu.CS.circle("x", "y"),
function (x, pos) { return {radius: 20, theta: x % (Math.PI * 2)}; },
[{
trigger: function (vision) {
return vision.find(ekolu.VOC.recognize("wall"));
},
position: ekolu.POS.static
}, {
trigger: function (vision) {
return vision
.filter(ekolu.VOC.recognize("hand"))
.find(_.att("smashing"));
},
position: function (x, pos) { return {radius: 20, theta: x % (Math.PI * 2)}; }
}],
ekolu.VOC.vision360(5)
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment