3 BouncingSvgShape = Utilities.createSubclass(BouncingSvgParticle,
6 BouncingSvgParticle.call(this, stage, stage.shape);
7 this._fill = stage.fill;
9 this._createShape(stage);
10 this._applyClipping(stage);
11 this._applyFill(stage);
16 _createShape: function(stage)
18 switch (this._shape) {
20 var attrs = { x: 0, y: 0, width: this.size.x, height: this.size.y };
21 this.element = Utilities.createSVGElement("rect", attrs, {}, stage.element);
26 var attrs = { cx: this.size.x / 2, cy: this.size.y / 2, r: Math.min(this.size.x, this.size.y) / 2 };
27 this.element = Utilities.createSVGElement("circle", attrs, {}, stage.element);
32 _applyFill: function(stage)
36 var gradient = stage.createGradient(2);
37 this.element.setAttribute("fill", "url(#" + gradient.getAttribute("id") + ")");
42 this.element.setAttribute("fill", Stage.randomColor());
48 BouncingSvgShapesStage = Utilities.createSubclass(BouncingSvgParticlesStage,
51 BouncingSvgParticlesStage.call(this);
54 initialize: function(benchmark, options)
56 BouncingSvgParticlesStage.prototype.initialize.call(this, benchmark, options);
57 this.parseShapeParameters(options);
58 this._gradientsCount = 0;
61 createGradient: function(stops)
63 var attrs = { id: "gradient-" + ++this._gradientsCount };
64 var gradient = Utilities.createSVGElement("linearGradient", attrs, {}, this._ensureDefsIsCreated());
66 for (var i = 0; i < stops; ++i) {
67 attrs = { offset: i * 100 / stops + "%", 'stop-color': Stage.randomColor() };
68 Utilities.createSVGElement("stop", attrs, {}, gradient);
74 createParticle: function()
76 return new BouncingSvgShape(this);
79 particleWillBeRemoved: function(particle)
81 BouncingSvgParticlesStage.prototype.particleWillBeRemoved.call(this, particle);
83 var fill = particle.element.getAttribute("fill");
84 if (fill.indexOf("url(#") != 0)
87 var gradient = this.element.querySelector(fill.substring(4, fill.length - 1));
88 this._ensureDefsIsCreated().removeChild(gradient);
92 BouncingSvgShapesBenchmark = Utilities.createSubclass(Benchmark,
95 Benchmark.call(this, new BouncingSvgShapesStage(), options);
99 window.benchmarkClass = BouncingSvgShapesBenchmark;