1 function CanvasStar(stage)
3 this._context = stage.context;
4 this._stageSize = stage.size;
6 this._size = stage.randomSquareSize(5, 20);
7 this._center = stage.randomPosition(stage.size.subtract(this._size)).add(this._size.center);
9 this._rotateDeltaX = stage.random(0.3, 0.7);
12 CanvasStar.prototype._draw = function()
15 this._context.translate(this._center.x, this._center.y);
17 this._context.fillStyle = 'yellow';
18 this._context.strokeStyle = 'white';
20 this._context.lineWidth = 1;
22 this._context.beginPath();
23 this._context.moveTo( 0, -this._size.y / 2);
24 this._context.lineTo(+this._size.x / 20 - this._rotateX / 5, -this._size.y / 10);
25 this._context.lineTo(+this._size.x / 4 - this._rotateX, 0);
26 this._context.lineTo(+this._size.x / 20 - this._rotateX / 5, +this._size.y / 10);
27 this._context.lineTo( 0, +this._size.y / 2);
28 this._context.lineTo(-this._size.x / 20 + this._rotateX / 5, +this._size.y / 10);
29 this._context.lineTo(-this._size.x / 4 + this._rotateX, 0);
30 this._context.lineTo(-this._size.x / 20 + this._rotateX / 5, -this._size.y / 10);
31 this._context.lineTo( 0, -this._size.y / 2);
34 this._context.stroke();
35 this._context.closePath();
36 this._context.restore();
39 CanvasStar.prototype.animate = function(timeDelta)
41 this._rotateX += this._rotateDeltaX;
43 if (this._rotateX > this._size.x / 4 || this._rotateX < -this._size.x / 4) {
44 this._rotateDeltaX = -this._rotateDeltaX;
45 this._rotateX += this._rotateDeltaX;
51 function CanvasStarsStage(element, options)
53 Stage.call(this, element, options);
54 this.context = this.element.getContext("2d");
59 CanvasStarsStage.prototype = Object.create(Stage.prototype);
60 CanvasStarsStage.prototype.constructor = CanvasStarsStage;
62 CanvasStarsStage.prototype.tune = function(count)
65 return this._objects.length;
68 for (var i = 0; i < count; ++i)
69 this._objects.push(new CanvasStar(this));
70 return this._objects.length;
73 count = Math.min(-count, this._objects.length);
74 this._objects.splice(-count, count);
76 return this._objects.length;
79 CanvasStarsStage.prototype.animate = function(timeDelta)
81 this._objects.forEach(function(object) {
82 object.animate(timeDelta);
86 function CanvasStarsAnimator(benchmark)
88 Animator.call(this, benchmark);
89 this._context = benchmark._stage.context;
92 CanvasStarsAnimator.prototype = Object.create(StageAnimator.prototype);
93 CanvasStarsAnimator.prototype.constructor = CanvasStarsAnimator;
95 CanvasStarsAnimator.prototype.animate = function()
97 this._context.beginPath();
98 this._context.fillStyle = 'black';
99 this._context.rect(0, 0, this._benchmark._stage.size.width, this._benchmark._stage.size.height);
100 this._context.fill();
101 return StageAnimator.prototype.animate.call(this);
104 function CanvasStarsBenchmark(suite, test, options, recordTable, progressBar)
106 StageBenchmark.call(this, suite, test, options, recordTable, progressBar);
109 CanvasStarsBenchmark.prototype = Object.create(StageBenchmark.prototype);
110 CanvasStarsBenchmark.prototype.constructor = CanvasStarsBenchmark;
112 CanvasStarsBenchmark.prototype.createStage = function(element)
114 // Attach the stage to the benchmark.
115 return new CanvasStarsStage(element, this._options);
118 CanvasStarsBenchmark.prototype.createAnimator = function()
120 // Attach the animator to the benchmark.
121 return new CanvasStarsAnimator(this);
124 window.benchmarkClient.create = function(suite, test, options, recordTable, progressBar)
126 // This function is called from the test harness which starts the
127 // test by creating your benchmark object.
128 return new CanvasStarsBenchmark(suite, test, options, recordTable, progressBar);