UNPKG

@tdurtschi/bug

Version:

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

80 lines 2.86 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Jade = void 0; var victor_1 = __importDefault(require("victor")); var plant_1 = __importDefault(require("../plant")); var Jade = (function (_super) { __extends(Jade, _super); function Jade() { return _super !== null && _super.apply(this, arguments) || this; } Jade.prototype.generateGraph = function () { return this.generateGraphRecursive(jadeTree); }; Jade.prototype.generateGraphRecursive = function (segment, parent, depth) { if (depth === void 0) { depth = 0; } var newSegment = new PlantSegment(depth, parent, new victor_1.default(segment.node.x, segment.node.y), undefined, undefined); if (segment.children && segment.children.length) { newSegment.left = this.generateGraphRecursive(segment.children[0], newSegment, depth + 1); if (segment.children.length > 1) { newSegment.right = this.generateGraphRecursive(segment.children[1], newSegment, depth + 1); } } if (segment.flipY) { newSegment.flipY = true; } return newSegment; }; Jade.prototype.update = function () { }; return Jade; }(plant_1.default)); exports.Jade = Jade; var jadeTree = { node: { x: 9, y: 92 }, flipY: true, children: [ { node: { x: 40, y: 8 } }, { node: { x: 1, y: 54 }, flipY: true, children: [ { node: { x: 2, y: 66 }, flipY: true, children: [ { node: { x: -3, y: 33 } }, { node: { x: 66, y: 29 } } ], }, ], }, ], }; var PlantSegment = (function () { function PlantSegment(depth, parent, node, left, right) { this.depth = depth; this.parent = parent; this.node = node; this.left = left; this.right = right; this.flipY = false; } return PlantSegment; }()); //# sourceMappingURL=jade.js.map