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