1 function Rotater(rotateInterval)
4 this._rotateInterval = rotateInterval;
11 return this._rotateInterval;
14 next: function(timeDelta)
16 this._timeDelta = (this._timeDelta + timeDelta) % this._rotateInterval;
21 return (360 * this._timeDelta) / this._rotateInterval;
26 return "rotateZ(" + Math.floor(this.degree()) + "deg)";
29 rotate: function(center)
31 return "rotate(" + Math.floor(this.degree()) + ", " + center.x + "," + center.y + ")";
35 function Stage(element, options)
37 this.element = element;
44 var styles = window.getComputedStyle(this.element);
45 var padding = new Insets(
46 parseFloat(styles.paddingTop),
47 parseFloat(styles.paddingRight),
48 parseFloat(styles.paddingBottom),
49 parseFloat(styles.paddingTop));
50 return new Point(this.element.clientWidth - padding.width, this.element.clientHeight - padding.height);
53 random: function(min, max)
55 return (Math.random() * (max - min)) + min;
58 randomBool: function()
60 return !!Math.round(this.random(0, 1));
63 randomInt: function(min, max)
65 return Math.round(this.random(min, max));
68 randomPosition: function(maxPosition)
70 return new Point(this.randomInt(0, maxPosition.x), this.randomInt(0, maxPosition.y));
73 randomSquareSize: function(min, max)
75 var side = this.random(min, max);
76 return new Point(side, side);
79 randomVelocity: function(maxVelocity)
81 return this.random(maxVelocity / 8, maxVelocity);
84 randomAngle: function()
86 return this.random(0, Math.PI * 2);
89 randomColor: function()
94 + this.randomInt(min, max).toString(16)
95 + this.randomInt(min, max).toString(16)
96 + this.randomInt(min, max).toString(16);
99 randomRotater: function()
101 return new Rotater(this.random(1000, 10000));
106 throw "Not implemented";
111 throw "Not implemented";
116 return this.tune(-this.tune(0));
120 function StageAnimator(benchmark)
122 Animator.call(this, benchmark);
125 StageAnimator.prototype = Object.create(Animator.prototype);
126 StageAnimator.prototype.constructor = StageAnimator;
128 StageAnimator.prototype.animate = function()
130 if (!Animator.prototype.animate.call(this))
132 this._benchmark._stage.animate(this.timeDelta());
136 function StageBenchmark(suite, test, options, recordTable, progressBar)
138 Benchmark.call(this, options);
140 var element = document.getElementById("stage");
141 element.setAttribute("width", document.body.offsetWidth);
142 element.setAttribute("height", document.body.offsetHeight);
144 this._stage = this.createStage(element);
145 this._animator = this.createAnimator();
148 this._recordTable = recordTable;
149 this._progressBar = progressBar;
152 StageBenchmark.prototype = Object.create(Benchmark.prototype);
153 StageBenchmark.prototype.constructor = StageBenchmark;
155 StageBenchmark.prototype.createStage = function(element)
157 return new Stage(element, this._options);
160 StageBenchmark.prototype.createAnimator = function()
162 return new StageAnimator(this);
165 StageBenchmark.prototype.tune = function(count)
167 return this._stage.tune(count);
170 StageBenchmark.prototype.clear = function()
172 return this._stage.clear();
175 StageBenchmark.prototype.showResults = function(message, progress)
177 if (!this._recordTable || !this._progressBar || !this._test)
180 if (this.options["show-running-results"])
181 this._recordTable.showRecord(this._test.name, message, this._sampler.toJSON(true, false));
183 this._progressBar.setPos(progress);