1 // === PAINT OBJECTS ===
3 function CanvasLineSegment(stage) {
4 var radius = stage.randomInt(10, 100);
5 var center = stage.randomPosition(stage.size);
6 var delta = Point.pointOnCircle(stage.randomAngle(), radius/2);
8 this._point1 = center.add(delta);
9 this._point2 = center.subtract(delta);
10 this._color = stage.randomColor();
11 this._lineWidth = stage.randomInt(1, 100);
13 CanvasLineSegment.prototype.draw = function(context) {
14 context.strokeStyle = this._color;
15 context.lineWidth = this._lineWidth;
17 context.moveTo(this._point1.x, this._point1.y);
18 context.lineTo(this._point2.x, this._point2.y);
22 function CanvasLinePoint(stage, coordinateMaximum) {
23 this._point = stage.randomPosition(new Point(Math.min(stage.size.x, coordinateMaximum), Math.min(stage.size.y, coordinateMaximum)));
25 CanvasLinePoint.prototype.draw = function(context) {
26 context.lineTo(this._point.x, this._point.y);
29 function CanvasQuadraticSegment(stage) {
30 var maxSize = stage.randomInt(20, 200);
31 var toCenter = stage.randomPosition(stage.size).subtract(new Point(maxSize/2, maxSize/2));
33 this._point1 = stage.randomPosition(new Point(maxSize, maxSize)).add(toCenter);
34 this._point2 = stage.randomPosition(new Point(maxSize, maxSize)).add(toCenter);
35 this._point3 = stage.randomPosition(new Point(maxSize, maxSize)).add(toCenter);
36 this._color = stage.randomColor();
37 this._lineWidth = stage.randomInt(1, 50);
39 CanvasQuadraticSegment.prototype.draw = function(context) {
40 context.strokeStyle = this._color;
41 context.lineWidth = this._lineWidth;
43 context.moveTo(this._point1.x, this._point1.y);
44 context.quadraticCurveTo(this._point2.x, this._point2.y, this._point3.x, this._point3.y);
48 function CanvasQuadraticPoint(stage, coordinateMaximum) {
49 var pointMaximum = new Point(Math.min(stage.size.x, coordinateMaximum), Math.min(stage.size.y, coordinateMaximum));
50 this._point1 = stage.randomPosition(pointMaximum);
51 this._point2 = stage.randomPosition(pointMaximum);
53 CanvasQuadraticPoint.prototype.draw = function(context) {
54 context.quadraticCurveTo(this._point1.x, this._point1.y, this._point2.x, this._point2.y);
57 function CanvasBezierSegment(stage) {
58 var maxSize = stage.randomInt(20, 200);
59 var toCenter = stage.randomPosition(stage.size).subtract(new Point(maxSize/2, maxSize/2));
61 this._point1 = stage.randomPosition(new Point(maxSize, maxSize)).add(toCenter);
62 this._point2 = stage.randomPosition(new Point(maxSize, maxSize)).add(toCenter);
63 this._point3 = stage.randomPosition(new Point(maxSize, maxSize)).add(toCenter);
64 this._point4 = stage.randomPosition(new Point(maxSize, maxSize)).add(toCenter);
65 this._color = stage.randomColor();
66 this._lineWidth = stage.randomInt(1, 50);
68 CanvasBezierSegment.prototype.draw = function(context) {
69 context.strokeStyle = this._color;
70 context.lineWidth = this._lineWidth;
72 context.moveTo(this._point1.x, this._point1.y);
73 context.bezierCurveTo(this._point2.x, this._point2.y, this._point3.x, this._point3.y, this._point4.x, this._point4.y);
77 function CanvasBezierPoint(stage, coordinateMaximum) {
78 var pointMaximum = new Point(Math.min(stage.size.x, coordinateMaximum), Math.min(stage.size.y, coordinateMaximum));
79 this._point1 = stage.randomPosition(pointMaximum);
80 this._point2 = stage.randomPosition(pointMaximum);
81 this._point3 = stage.randomPosition(pointMaximum);
83 CanvasBezierPoint.prototype.draw = function(context) {
84 context.bezierCurveTo(this._point1.x, this._point1.y, this._point2.x, this._point2.y, this._point3.x, this._point3.y);
87 function CanvasArcToSegment(stage) {
88 var maxSize = stage.randomInt(20, 200);
89 var toCenter = stage.randomPosition(stage.size).subtract(new Point(maxSize/2, maxSize/2));
91 this._point1 = stage.randomPosition(new Point(maxSize, maxSize)).add(toCenter);
92 this._point2 = stage.randomPosition(new Point(maxSize, maxSize)).add(toCenter);
93 this._point3 = stage.randomPosition(new Point(maxSize, maxSize)).add(toCenter);
94 this._radius = stage.randomInt(20, 200);
95 this._color = stage.randomColor();
96 this._lineWidth = stage.randomInt(1, 50);
98 CanvasArcToSegment.prototype.draw = function(context) {
99 context.strokeStyle = this._color;
100 context.lineWidth = this._lineWidth;
102 context.moveTo(this._point1.x, this._point1.y);
103 context.arcTo(this._point2.x, this._point2.y, this._point3.x, this._point3.y, this._radius);
107 function CanvasArcToSegmentFill(stage) {
108 CanvasArcToSegment.call(this, stage);
110 CanvasArcToSegmentFill.prototype.draw = function(context) {
111 context.fillStyle = this._color;
113 context.moveTo(this._point1.x, this._point1.y);
114 context.arcTo(this._point2.x, this._point2.y, this._point3.x, this._point3.y, this._radius);
118 function CanvasArcSegment(stage) {
119 var maxSize = stage.randomInt(20, 200);
120 var toCenter = stage.randomPosition(stage.size).subtract(new Point(maxSize/2, maxSize/2));
122 this._point = stage.randomPosition(new Point(maxSize, maxSize)).add(toCenter);
123 this._radius = stage.randomInt(20, 200);
124 this._startAngle = stage.randomAngle();
125 this._endAngle = stage.randomAngle();
126 this._counterclockwise = stage.randomBool();
127 this._color = stage.randomColor();
128 this._lineWidth = stage.randomInt(1, 50);
130 CanvasArcSegment.prototype.draw = function(context) {
131 context.strokeStyle = this._color;
132 context.lineWidth = this._lineWidth;
134 context.arc(this._point.x, this._point.y, this._radius, this._startAngle, this._endAngle, this._counterclockwise);
138 function CanvasArcSegmentFill(stage) {
139 CanvasArcSegment.call(this, stage);
141 CanvasArcSegmentFill.prototype.draw = function(context) {
142 context.fillStyle = this._color;
144 context.arc(this._point.x, this._point.y, this._radius, this._startAngle, this._endAngle, this._counterclockwise);
148 function CanvasRect(stage) {
149 this._width = stage.randomInt(20, 200);
150 this._height = stage.randomInt(20, 200);
151 this._point = stage.randomPosition(stage.size).subtract(new Point(this._width/2, this._height/2));
152 this._color = stage.randomColor();
153 this._lineWidth = stage.randomInt(1, 20);
155 CanvasRect.prototype.draw = function(context) {
156 context.strokeStyle = this._color;
157 context.lineWidth = this._lineWidth;
159 context.rect(this._point.x, this._point.y, this._width, this._height);
163 function CanvasRectFill(stage) {
164 CanvasRect.call(this, stage);
166 CanvasRectFill.prototype.draw = function(context) {
167 context.fillStyle = this._color;
169 context.rect(this._point.x, this._point.y, this._width, this._height);
175 function SimpleCanvasPathStrokeStage(element, options, canvasObject) {
176 SimpleCanvasStage.call(this, element, options, canvasObject);
178 SimpleCanvasPathStrokeStage.prototype = Object.create(SimpleCanvasStage.prototype);
179 SimpleCanvasPathStrokeStage.prototype.constructor = SimpleCanvasPathStrokeStage;
180 SimpleCanvasPathStrokeStage.prototype.animate = function() {
181 var context = this.context;
182 context.lineWidth = this.randomInt(1, 20);
183 context.strokeStyle = this.randomColor();
186 this._objects.forEach(function(object) {
187 object.draw(context);
192 function SimpleCanvasPathFillStage(element, options, canvasObject) {
193 SimpleCanvasStage.call(this, element, options, canvasObject);
195 SimpleCanvasPathFillStage.prototype = Object.create(SimpleCanvasStage.prototype);
196 SimpleCanvasPathFillStage.prototype.constructor = SimpleCanvasPathFillStage;
197 SimpleCanvasPathFillStage.prototype.animate = function() {
198 var context = this.context;
199 context.fillStyle = this.randomColor();
202 this._objects.forEach(function(object) {
203 object.draw(context);
208 function CanvasLineSegmentStage(element, options)
210 SimpleCanvasStage.call(this, element, options, CanvasLineSegment);
211 this.context.lineCap = options["lineCap"] || "butt";
213 CanvasLineSegmentStage.prototype = Object.create(SimpleCanvasStage.prototype);
214 CanvasLineSegmentStage.prototype.constructor = CanvasLineSegmentStage;
216 function CanvasLinePathStage(element, options)
218 SimpleCanvasPathStrokeStage.call(this, element, options, CanvasLinePoint);
219 this.context.lineJoin = options["lineJoin"] || "bevel";
221 CanvasLinePathStage.prototype = Object.create(SimpleCanvasPathStrokeStage.prototype);
222 CanvasLinePathStage.prototype.constructor = CanvasLinePathStage;
226 function CanvasPathBenchmark(suite, test, options, recordTable, progressBar) {
227 SimpleCanvasBenchmark.call(this, suite, test, options, recordTable, progressBar);
229 CanvasPathBenchmark.prototype = Object.create(SimpleCanvasBenchmark.prototype);
230 CanvasPathBenchmark.prototype.constructor = CanvasPathBenchmark;
231 CanvasPathBenchmark.prototype.createStage = function(element)
233 switch (this._options["pathType"]) {
235 return new CanvasLineSegmentStage(element, this._options);
237 if ("lineJoin" in this._options)
238 return new CanvasLinePathStage(element, this._options);
242 return new SimpleCanvasStage(element, this._options, CanvasQuadraticSegment);
243 case "quadraticPath":
244 return new SimpleCanvasPathStrokeStage(element, this._options, CanvasQuadraticPoint);
246 return new SimpleCanvasStage(element, this._options, CanvasBezierSegment);
248 return new SimpleCanvasPathStrokeStage(element, this._options, CanvasBezierPoint);
250 return new SimpleCanvasStage(element, this._options, CanvasArcToSegment);
252 return new SimpleCanvasStage(element, this._options, CanvasArcSegment);
254 return new SimpleCanvasStage(element, this._options, CanvasRect);
256 return new SimpleCanvasPathFillStage(element, this._options, CanvasLinePoint);
257 case "quadraticFill":
258 return new SimpleCanvasPathFillStage(element, this._options, CanvasQuadraticPoint);
260 return new SimpleCanvasPathFillStage(element, this._options, CanvasBezierPoint);
262 return new SimpleCanvasStage(element, this._options, CanvasArcToSegmentFill);
264 return new SimpleCanvasStage(element, this._options, CanvasArcSegmentFill);
266 return new SimpleCanvasStage(element, this._options, CanvasRectFill);
270 window.benchmarkClient.create = function(suite, test, options, recordTable, progressBar) {
271 return new CanvasPathBenchmark(suite, test, options, recordTable, progressBar);