summaryrefslogtreecommitdiffstats
path: root/third_party/webkit/PerformanceTests/MotionMark/tests/bouncing-particles/resources/bouncing-canvas-shapes.js
blob: 49a31cf40d49a6d6047a751b665302887e29dba0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
(function() {

BouncingCanvasShape = Utilities.createSubclass(BouncingCanvasParticle,
    function(stage)
    {
        BouncingCanvasParticle.call(this, stage, stage.shape);
        this._fill = stage.fill;
        this._color0 = Stage.randomColor();
        this._color1 = Stage.randomColor();
    }, {

    _applyFill: function()
    {
        switch (this._fill) {
        case "gradient":
            var gradient = this.context.createLinearGradient(0, 0, this.size.width, 0);
            gradient.addColorStop(0, this._color0);
            gradient.addColorStop(1, this._color1);
            this.context.fillStyle = gradient;
            break;

        case "solid":
        default:
            this.context.fillStyle = this._color0;
            break;
        }
    },

    _drawShape: function()
    {
        this.context.beginPath();

        switch (this._shape) {
        case "rect":
            this.context.rect(0, 0, this.size.width, this.size.height);
            break;

        case "circle":
        default:
            var center = this.size.center;
            var radius = Math.min(this.size.x, this.size.y) / 2;
            this.context.arc(center.x, center.y, radius, 0, Math.PI * 2, true);
            break;
        }

        this.context.fill();
    },

    _draw: function()
    {
        this.context.save();
            this._applyFill();
            this.applyRotation();
            this.applyClipping();
            this._drawShape();
        this.context.restore();
    }
});

BouncingCanvasShapesStage = Utilities.createSubclass(BouncingCanvasParticlesStage,
    function ()
    {
        BouncingCanvasParticlesStage.call(this);
    }, {

    initialize: function(benchmark, options)
    {
        BouncingCanvasParticlesStage.prototype.initialize.call(this, benchmark, options);
        this.parseShapeParameters(options);
    },

    createParticle: function()
    {
        return new BouncingCanvasShape(this);
    }
});

BouncingCanvasShapesBenchmark = Utilities.createSubclass(Benchmark,
    function(options)
    {
        Benchmark.call(this, new BouncingCanvasShapesStage(), options);
    }
);

window.benchmarkClass = BouncingCanvasShapesBenchmark;

})();