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)
64 count = count > 0 ? Math.floor(count) : Math.ceil(count);
67 return this._objects.length;
70 for (var i = 0; i < count; ++i)
71 this._objects.push(new CanvasStar(this));
72 return this._objects.length;
75 count = Math.min(-count, this._objects.length);
76 this._objects.splice(-count, count);
78 return this._objects.length;
81 CanvasStarsStage.prototype.animate = function(timeDelta)
83 this._objects.forEach(function(object) {
84 object.animate(timeDelta);
88 function CanvasStarsAnimator(benchmark)
90 Animator.call(this, benchmark);
91 this._context = benchmark._stage.context;
94 CanvasStarsAnimator.prototype = Object.create(StageAnimator.prototype);
95 CanvasStarsAnimator.prototype.constructor = CanvasStarsAnimator;
97 CanvasStarsAnimator.prototype.animate = function()
99 this._context.beginPath();
100 this._context.fillStyle = 'black';
101 this._context.rect(0, 0, this._benchmark._stage.size.width, this._benchmark._stage.size.height);
102 this._context.fill();
103 return StageAnimator.prototype.animate.call(this);
106 function CanvasStarsBenchmark(suite, test, options, recordTable, progressBar)
108 StageBenchmark.call(this, suite, test, options, recordTable, progressBar);
111 CanvasStarsBenchmark.prototype = Object.create(StageBenchmark.prototype);
112 CanvasStarsBenchmark.prototype.constructor = CanvasStarsBenchmark;
114 CanvasStarsBenchmark.prototype.createStage = function(element)
116 // Attach the stage to the benchmark.
117 return new CanvasStarsStage(element, this._options);
120 CanvasStarsBenchmark.prototype.createAnimator = function()
122 // Attach the animator to the benchmark.
123 return new CanvasStarsAnimator(this);
126 window.benchmarkClient.create = function(suite, test, options, recordTable, progressBar)
128 // This function is called from the test harness which starts the
129 // test by creating your benchmark object.
130 return new CanvasStarsBenchmark(suite, test, options, recordTable, progressBar);