1 | "use strict";
|
2 | var __extends = (this && this.__extends) || (function () {
|
3 | var extendStatics = Object.setPrototypeOf ||
|
4 | ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
5 | function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
6 | return function (d, b) {
|
7 | extendStatics(d, b);
|
8 | function __() { this.constructor = d; }
|
9 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
10 | };
|
11 | })();
|
12 | Object.defineProperty(exports, "__esModule", { value: true });
|
13 | var Graphic_1 = require("./../Graphic");
|
14 | var Module_1 = require("./../Module");
|
15 | var Tool_1 = require("./../Tool");
|
16 | var Spinner = (function (_super) {
|
17 | __extends(Spinner, _super);
|
18 |
|
19 | function Spinner() {
|
20 | var _this = _super.call(this) || this;
|
21 | |
22 |
|
23 |
|
24 | _this.lines = [];
|
25 | _this.setProps({
|
26 | lines: 16,
|
27 | lineWidth: 10,
|
28 | centerSpacing: 15,
|
29 | lineHeight: 2,
|
30 | speed: 1000,
|
31 | color: Tool_1.Color.white
|
32 | });
|
33 | _this.signals.propChange.bind(["lineWidth", "lines"], _this.onLineChange.bind(_this));
|
34 | _this.signals.propChange.bind("speed", _this.onSpeedChange.bind(_this));
|
35 | return _this;
|
36 | }
|
37 | Spinner.prototype.initialize = function (props) {
|
38 | _super.prototype.initialize.call(this, props);
|
39 | this.onSpeedChange();
|
40 | this.onLineChange();
|
41 | };
|
42 |
|
43 | |
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 | Spinner.prototype.updateLinesAlpha = function (tick, value, ratio) {
|
50 | var _this = this;
|
51 | var length = this.lines.length;
|
52 | this.lines.forEach(function (line, i) { return line.props.fillAlpha = 1 - (ratio + (i / _this.props.lines)) % 1; });
|
53 | };
|
54 | |
55 |
|
56 |
|
57 | Spinner.prototype.onLineChange = function () {
|
58 | var angleFactor = 360 / this.props.lines;
|
59 | this.lines.forEach(function (lines) { return lines.kill(); });
|
60 | this.lines = [];
|
61 | for (var i = 0; i < this.props.lines; i++) {
|
62 | this.lines.push(this.spawn(new Module_1.Shape(), this.props.centerSpacing, 0, {
|
63 | offsetX: this.props.centerSpacing,
|
64 | offsetY: 0,
|
65 | fill: this.props.color,
|
66 | fillAlpha: (i / this.props.lines) % 1,
|
67 | width: this.props.lineWidth,
|
68 | height: this.props.lineHeight,
|
69 | angle: angleFactor * i
|
70 | }));
|
71 | }
|
72 | this.lines.reverse();
|
73 | this.props.width = this.container.width;
|
74 | this.props.height = this.container.height;
|
75 | };
|
76 | Spinner.prototype.onSpeedChange = function () {
|
77 | this.timers.addTimer("spin", this.props.speed, null, {
|
78 | recurrence: -1,
|
79 | update: this.updateLinesAlpha.bind(this)
|
80 | });
|
81 | };
|
82 | return Spinner;
|
83 | }(Graphic_1.Graphic));
|
84 | exports.Spinner = Spinner;
|