b04e4dd096665078d046afa928207d491a81402f
[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 = this.stage.emitLocation[Stage.randomInt(0, this.stage.emitLocation.length - 1)];
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.element.style.backgroundColor = Stage.rotatingColor(2000, .7, .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 Utilities.extendObject(ParticlesStage.prototype, {
35     createParticle: function()
36     {
37         return new DOMParticle(this);
38     },
39
40     willRemoveParticle: function(particle)
41     {
42         particle.element.remove();
43     }
44 });
45
46 ParticlesBenchmark = Utilities.createSubclass(Benchmark,
47     function(options)
48     {
49         Benchmark.call(this, new ParticlesStage(), options);
50     }
51 );
52
53 window.benchmarkClass = ParticlesBenchmark;
54
55 })();