@tdurtschi/bug
Version:
Bug is a simulation that models a weevil walking around in an HTML canvas.
35 lines • 1.4 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.TreeBranchStruct = void 0;
var Victor = require("victor");
var TreeBranchStruct = (function () {
function TreeBranchStruct(depth, parent, maxDepth) {
var _this = this;
if (depth === void 0) { depth = 1; }
if (maxDepth === void 0) { maxDepth = 5; }
this.node = new Victor(0, 1);
this.update = function () {
if (_this.node.magnitude() < 100) {
var diff = 10;
var dir = _this.node.direction();
_this.node.addScalarY(Math.sin(dir) * diff);
_this.node.addScalarX(Math.cos(dir) * diff);
}
else if (!_this.left && _this.depth < _this.maxDepth) {
_this.left = new TreeBranchStruct(_this.depth + 1, _this, _this.maxDepth);
var angle = _this.node.verticalAngleDeg();
var newDirection = (Math.floor(angle));
_this.left.node.rotateDeg(newDirection);
}
_this.left && _this.left.update();
_this.right && _this.right.update();
};
this.depth = depth;
this.parent = parent;
this.maxDepth = maxDepth;
}
return TreeBranchStruct;
}());
exports.TreeBranchStruct = TreeBranchStruct;
var UP_DIRECTION = -90;
//# sourceMappingURL=treeBranchStruct.js.map