6f9433555a97966a72e0db5c3acd9de62ab44955
[WebKit-https.git] / PerformanceTests / Animometer / tests / bouncing-particles / resources / bouncing-css-shapes.js
1 function BouncingCssShape(stage)
2 {
3     BouncingParticle.call(this, stage);
4
5     this.element = this._createSpan(stage);
6         
7     switch (stage.fill) {
8     case "solid":
9     default:
10         this.element.style.backgroundColor = stage.randomColor();
11         break;
12         
13     case "gradient":
14         this.element.style.background = "linear-gradient(" + stage.randomColor() + ", " + stage.randomColor() + ")";
15         break;
16     }
17
18     this._move();
19 }
20
21 BouncingCssShape.prototype = Object.create(BouncingParticle.prototype);
22 BouncingCssShape.prototype.constructor = BouncingCssShape;
23
24 BouncingCssShape.prototype._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 BouncingCssShape.prototype._move = function()
35 {
36     this.element.style.transform = "translate(" + this._position.x + "px," + this._position.y + "px)" + this._rotater.rotateZ();
37 }
38     
39 BouncingCssShape.prototype.animate = function(timeDelta)
40 {
41     BouncingParticle.prototype.animate.call(this, timeDelta);
42     this._rotater.next(timeDelta);
43     this._move();
44 }
45
46 function BouncingCssShapesStage(element, options)
47 {
48     BouncingParticlesStage.call(this, element, options);
49     this.parseShapeParamters(options);
50 }
51
52 BouncingCssShapesStage.prototype = Object.create(BouncingParticlesStage.prototype);
53 BouncingCssShapesStage.prototype.constructor = BouncingCssShapesStage;
54
55 BouncingCssShapesStage.prototype.createParticle = function()
56 {
57     return new BouncingCssShape(this);
58 }
59
60 BouncingCssShapesStage.prototype.particleWillBeRemoved = function(particle)
61 {
62     particle.element.remove();
63 }
64
65 function BouncingCssShapesBenchmark(suite, test, options, progressBar)
66 {
67     BouncingParticlesBenchmark.call(this, suite, test, options, progressBar);
68 }
69
70 BouncingCssShapesBenchmark.prototype = Object.create(BouncingParticlesBenchmark.prototype);
71 BouncingCssShapesBenchmark.prototype.constructor = BouncingCssShapesBenchmark;
72
73 BouncingCssShapesBenchmark.prototype.createStage = function(element)
74 {
75     return new BouncingCssShapesStage(element, this._options);
76 }
77
78 window.benchmarkClient.create = function(suite, test, options, progressBar)
79 {
80     return new BouncingCssShapesBenchmark(suite, test, options, progressBar);
81 }