UNPKG

@tdurtschi/bug

Version:

Bug is a simulation that models a weevil walking around in an HTML canvas.

44 lines 1.72 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.defaultState = void 0; var victor_1 = __importDefault(require("victor")); function defaultState() { return { pos: new victor_1.default(1, 0), size: new victor_1.default(1, 1) }; } exports.defaultState = defaultState; var Plant = (function () { function Plant(id, initialState) { var _this = this; this.updateSpeed = 4; this.getAbsolutePos = function (node, accumulator, rootNode) { if (!accumulator && !rootNode) { var result = _this.getAbsolutePos(node, _this.pos.clone(), _this.graph); if (result) return result; throw new Error("Couldn't find branch in tree while calculating position"); } else if (rootNode === node) { return accumulator; } else { var checkLeft = rootNode.left && _this.getAbsolutePos(node, accumulator.clone().add(rootNode.node), rootNode.left); if (checkLeft) return checkLeft; var checkRight = rootNode.right && _this.getAbsolutePos(node, accumulator.clone().add(rootNode.node), rootNode.right); if (checkRight) return checkRight; } }; this.id = id ? id : 0; Object.assign(this, defaultState(), { graph: this.generateGraph() }, initialState); } return Plant; }()); exports.default = Plant; //# sourceMappingURL=plant.js.map