c6512bd9675701f0464527a294f214464253a132
[WebKit-https.git] / PerformanceTests / Animometer / tests / master / resources / dom-particles.js
1 (function() {
2
3 DOMParticle = Utilities.createSubclass(Particle,
4     function(stage)
5     {
6         this.element = document.createElement("div");
7         stage.element.appendChild(this.element);
8
9         Particle.call(this, stage);
10     }, {
11
12     reset: function()
13     {
14         Particle.prototype.reset.call(this);
15
16         var emitLocation = Stage.randomElementInArray(this.stage.emitLocation);
17         this.position = new Point(emitLocation.x, emitLocation.y);
18
19         var angle = Stage.randomInt(0, this.stage.emitSteps) / this.stage.emitSteps * Math.PI * 2 + Stage.dateCounterValue(100) * this.stage.emissionSpin;
20         this.velocity = new Point(Math.sin(angle), Math.cos(angle))
21             .multiply(Stage.random(.5, 2.5));
22
23         this.element.style.width = this.size.x + "px";
24         this.element.style.height = this.size.y + "px";
25         this.stage.colorOffset = (this.stage.colorOffset + 1) % 360;
26         this.element.style.backgroundColor = "hsl(" + this.stage.colorOffset + ", 70%, 45%)";
27     },
28
29     move: function()
30     {
31         this.element.style.transform = "translate(" + this.position.x + "px, " + this.position.y + "px)" + this.rotater.rotateZ();
32     }
33 });
34
35 DOMParticleStage = Utilities.createSubclass(ParticlesStage,
36     function()
37     {
38         ParticlesStage.call(this);
39     }, {
40
41     initialize: function(benchmark)
42     {
43         ParticlesStage.prototype.initialize.call(this, benchmark);
44         this.emissionSpin = Stage.random(0, 3);
45         this.emitSteps = Stage.randomInt(4, 6);
46         this.emitLocation = [
47             new Point(this.size.x * .25, this.size.y * .333),
48             new Point(this.size.x * .5, this.size.y * .25),
49             new Point(this.size.x * .75, this.size.y * .333)
50         ];
51         this.colorOffset = Stage.randomInt(0, 359);
52     },
53
54     createParticle: function()
55     {
56         return new DOMParticle(this);
57     },
58
59     willRemoveParticle: function(particle)
60     {
61         particle.element.remove();
62     }
63 });
64
65 DOMParticleBenchmark = Utilities.createSubclass(Benchmark,
66     function(options)
67     {
68         Benchmark.call(this, new DOMParticleStage(), options);
69     }
70 );
71
72 window.benchmarkClass = DOMParticleBenchmark;
73
74 })();