3 var MultiplyStage = Utilities.createSubclass(Stage,
11 initialize: function(benchmark, options)
13 Stage.prototype.initialize.call(this, benchmark, options);
14 var tileSize = Math.round(this.size.height / 20);
16 // Fill the scene with elements
17 var x = Math.round((this.size.width - tileSize) / 2);
18 var y = Math.round((this.size.height - tileSize) / 2);
19 var tileStride = tileSize;
21 var spiralCounter = 2;
23 var maxSide = Math.floor(this.size.height / tileStride);
24 var centerSpiralCount = maxSide * maxSide;
25 for (var i = 0; i < centerSpiralCount; ++i) {
26 this._addTile(x, y, tileSize, i % 360);
29 direction = (direction + 1) % 4;
31 nextIndex += spiralCounter >> 1;
35 else if (direction == 1)
37 else if (direction == 2)
43 centerSpiralCount = maxSide * (maxSide + (maxSide & 1));
44 for (var i = 0; i < centerSpiralCount; ++i) {
45 var sideX = x + Math.floor(Math.floor(i / maxSide) / 2) * tileStride;
46 var sideY = y - tileStride * (i % maxSide);
48 if (Math.floor(i / maxSide) % 2 == 1)
49 sideX = this.width - sideX - tileSize + 1;
50 this._addTile(sideX, sideY, tileSize, (6 * i) % 360);
54 _addTile: function(x, y, tileSize, rotateDeg)
56 var tile = Utilities.createElement("div", { class: "div-" + Stage.randomInt(0,6) }, this.element);
57 var halfTileSize = tileSize / 2;
58 tile.style.left = x + 'px';
59 tile.style.top = y + 'px';
60 tile.style.width = tileSize + 'px';
61 tile.style.height = tileSize + 'px';
63 var distance = 1.5 / tileSize * this.size.multiply(0.5).subtract(new Point(x + halfTileSize, y + halfTileSize)).length();
68 step: Math.max(1, distance / 4),
74 complexity: function()
76 return this._offsetIndex;
81 this._offsetIndex = Math.max(0, Math.min(this._offsetIndex + count, this.tiles.length));
86 var distanceFactor = 1 / Math.sqrt(this._offsetIndex);
88 var progress = this._benchmark.timestamp % 10000 / 10000;
89 var bounceProgress = Math.sin(2 * Math.abs( 0.5 - progress));
90 var l = this._lerp(bounceProgress, 20, 50);
91 var hslPrefix = "hsla(" + this._lerp(progress, 0, 360) + ",100%,";
93 for (var i = 0; i < this._offsetIndex; ++i) {
94 var tile = this.tiles[i];
96 tile.rotate += tile.step;
97 tile.element.style.transform = "rotate(" + tile.rotate + "deg)";
99 var influence = 1 - (tile.distance * distanceFactor);
100 tile.element.style.backgroundColor = hslPrefix + l * Math.tan(influence / 1.25) + "%," + influence + ")";
103 for (var i = this._offsetIndex; i < this.tiles.length && this.tiles[i].active; ++i) {
104 this.tiles[i].active = false;
105 this.tiles[i].element.style.backgroundColor = "";
109 _lerp: function(value, min, max)
111 return min + ( max - min ) * value;
115 var MultiplyBenchmark = Utilities.createSubclass(Benchmark,
118 Benchmark.call(this, new MultiplyStage(), options);
122 window.benchmarkClass = MultiplyBenchmark;