Refactor helper methods for getting random values for a stage.
[WebKit-https.git] / PerformanceTests / Animometer / tests / bouncing-particles / resources / bouncing-css-shapes.js
1 (function() {
2
3 BouncingCssShape = Utilities.createSubclass(BouncingParticle,
4     function(stage)
5     {
6         BouncingParticle.call(this, stage);
7
8         this.element = this._createSpan(stage);
9
10         switch (stage.fill) {
11         case "solid":
12         default:
13             this.element.style.backgroundColor = Stage.randomColor();
14             break;
15
16         case "gradient":
17             this.element.style.background = "linear-gradient(" + Stage.randomColor() + ", " + Stage.randomColor() + ")";
18             break;
19         }
20
21         this._move();
22     }, {
23
24     _createSpan: function(stage)
25     {
26         var span = document.createElement("span");
27         span.className = stage.shape + " " + stage.clip;
28         span.style.width = this.size.x + "px";
29         span.style.height = this.size.y + "px";
30         stage.element.appendChild(span);
31         return span;
32     },
33
34     _move: function()
35     {
36         this.element.style.transform = "translate(" + this.position.x + "px," + this.position.y + "px)" + this.rotater.rotateZ();
37     },
38
39     animate: function(timeDelta)
40     {
41         BouncingParticle.prototype.animate.call(this, timeDelta);
42         this.rotater.next(timeDelta);
43         this._move();
44     }
45 });
46
47 BouncingCssShapesStage = Utilities.createSubclass(BouncingParticlesStage,
48     function()
49     {
50         BouncingParticlesStage.call(this);
51     }, {
52
53     initialize: function(benchmark)
54     {
55         BouncingParticlesStage.prototype.initialize.call(this, benchmark);
56         this.parseShapeParameters(benchmark.options);
57     },
58
59     createParticle: function()
60     {
61         return new BouncingCssShape(this);
62     },
63
64     particleWillBeRemoved: function(particle)
65     {
66         particle.element.remove();
67     }
68 });
69
70 BouncingCssShapesBenchmark = Utilities.createSubclass(Benchmark,
71     function(options)
72     {
73         Benchmark.call(this, new BouncingCssShapesStage(), options);
74     }
75 );
76
77 window.benchmarkClass = BouncingCssShapesBenchmark;
78
79 })();