Get rid of options member variable in Benchmark.
[WebKit-https.git] / PerformanceTests / Animometer / tests / bouncing-particles / resources / bouncing-canvas-particles.js
1 BouncingCanvasParticle = Utilities.createSubclass(BouncingParticle,
2     function(stage, shape)
3     {
4         BouncingParticle.call(this, stage);
5         this.context = stage.context;
6         this._shape = shape;
7         this._clip = stage.clip;
8     }, {
9
10     applyRotation: function()
11     {
12         if (this._shape == "circle")
13             return;
14
15         this.context.translate(this.size.x / 2, this.size.y / 2);
16         this.context.rotate(this.rotater.degree() * Math.PI / 180);
17         this.context.translate(-this.size.x / 2, -this.size.y / 2);
18     },
19
20     applyClipping: function()
21     {
22         var clipPoints = BouncingCanvasParticle.clips[this._clip];
23         if (!clipPoints)
24             return;
25
26         this.context.beginPath();
27         clipPoints.forEach(function(point, index) {
28             var point = this.size.multiply(point);
29             if (!index)
30                 this.context.moveTo(point.x, point.y);
31             else
32                 this.context.lineTo(point.x, point.y);
33         }, this);
34
35         this.context.closePath();
36         this.context.clip();
37     },
38
39     _draw: function()
40     {
41         throw "Not implemented";
42     },
43
44     animate: function(timeDelta)
45     {
46         BouncingParticle.prototype.animate.call(this, timeDelta);
47         this.context.save();
48             this.context.translate(this.position.x, this.position.y);
49             this._draw();
50         this.context.restore();
51     }
52 });
53
54 BouncingCanvasParticle.clips = {
55     star: [
56         new Point(0.50, 0.00),
57         new Point(0.38, 0.38),
58         new Point(0.00, 0.38),
59         new Point(0.30, 0.60),
60         new Point(0.18, 1.00),
61         new Point(0.50, 0.75),
62         new Point(0.82, 1.00),
63         new Point(0.70, 0.60),
64         new Point(1.00, 0.38),
65         new Point(0.62, 0.38)
66     ]
67 };
68
69 BouncingCanvasParticlesStage = Utilities.createSubclass(BouncingParticlesStage,
70     function()
71     {
72         BouncingParticlesStage.call(this);
73     }, {
74
75     initialize: function(benchmark, options)
76     {
77         BouncingParticlesStage.prototype.initialize.call(this, benchmark, options);
78         this.context = this.element.getContext("2d");
79     },
80
81     animate: function(timeDelta)
82     {
83         this.context.clearRect(0, 0, this.size.x, this.size.y);
84         this.particles.forEach(function(particle) {
85             particle.animate(timeDelta);
86         });
87     }
88 });