Clean referencing the options object in the graphics benchmark
[WebKit-https.git] / PerformanceTests / Animometer / tests / bouncing-particles / resources / bouncing-canvas-particles.js
1 function BouncingCanvasParticle(stage)
2 {
3     BouncingParticle.call(this, stage);
4     this._context = stage.context;
5     this._shape = "";
6     this._clip = stage.clip;
7 }
8
9 BouncingCanvasParticle.clips = {
10     star: [
11         new Point(0.50, 0.00),
12         new Point(0.38, 0.38),
13         new Point(0.00, 0.38),
14         new Point(0.30, 0.60),
15         new Point(0.18, 1.00),
16         new Point(0.50, 0.75),
17         new Point(0.82, 1.00),
18         new Point(0.70, 0.60),
19         new Point(1.00, 0.38),
20         new Point(0.62, 0.38)
21     ],
22 };
23
24 BouncingCanvasParticle.prototype = Object.create(BouncingParticle.prototype);
25 BouncingCanvasParticle.prototype.constructor = BouncingCanvasParticle;
26
27 BouncingCanvasParticle.prototype._applyRotation = function()
28 {
29     if (this._shape == "circle")
30         return;
31
32     this._context.translate(this._size.x / 2, this._size.y / 2);
33     this._context.rotate(this._rotater.degree() * Math.PI / 180);
34     this._context.translate(-this._size.x / 2, -this._size.y / 2);
35 }
36
37 BouncingCanvasParticle.prototype._applyClipping = function()
38 {
39     var clipPoints = BouncingCanvasParticle.clips[this._clip];
40     if (!clipPoints)
41         return;
42         
43     this._context.beginPath();
44     clipPoints.forEach(function(point, index) {
45         var point = this._size.multiply(point);
46         if (!index)
47             this._context.moveTo(point.x, point.y);
48         else
49             this._context.lineTo(point.x, point.y);
50     }, this);
51
52     this._context.closePath();
53     this._context.clip();
54 }
55
56 BouncingCanvasParticle.prototype._draw = function()
57 {
58     throw "Not implemented";
59 }
60
61 BouncingCanvasParticle.prototype.animate = function(timeDelta)
62 {
63     BouncingParticle.prototype.animate.call(this, timeDelta);
64     this._context.save();
65         this._context.translate(this._position.x, this._position.y);
66         this._draw();
67     this._context.restore();
68 }
69
70 function BouncingCanvasParticlesStage(element, options)
71 {
72     BouncingParticlesStage.call(this, element, options);
73     this.context = this.element.getContext("2d");
74 }
75
76 BouncingCanvasParticlesStage.prototype = Object.create(BouncingParticlesStage.prototype);
77 BouncingCanvasParticlesStage.prototype.constructor = BouncingCanvasParticlesStage;
78
79 function BouncingCanvasParticlesAnimator(benchmark, options)
80 {
81     BouncingParticlesAnimator.call(this, benchmark, options);
82     this._context = benchmark._stage.context;
83 }
84
85 BouncingCanvasParticlesAnimator.prototype = Object.create(BouncingParticlesAnimator.prototype);
86 BouncingCanvasParticlesAnimator.prototype.constructor = BouncingCanvasParticlesAnimator;
87
88 BouncingCanvasParticlesAnimator.prototype.animate = function()
89 {
90     this._context.clearRect(0, 0, this._benchmark._stage.size.x, this._benchmark._stage.size.y);
91     return BouncingParticlesAnimator.prototype.animate.call(this);
92 }
93
94 function BouncingCanvasParticlesBenchmark(suite, test, options, recordTable, progressBar)
95 {
96     StageBenchmark.call(this, suite, test, options, recordTable, progressBar);
97 }
98
99 BouncingCanvasParticlesBenchmark.prototype = Object.create(StageBenchmark.prototype);
100 BouncingCanvasParticlesBenchmark.prototype.constructor = BouncingCanvasParticlesBenchmark;
101
102 BouncingCanvasParticlesBenchmark.prototype.createAnimator = function()
103 {
104     return new BouncingCanvasParticlesAnimator(this, this._options);
105 }