1 // === PAINT OBJECTS ===
3 function CanvasQuadraticSegment(stage) {
4 var maxSize = stage.randomInt(20, 200);
5 var toCenter = stage.randomPosition(stage.size).subtract(new Point(maxSize/2, maxSize/2));
7 this._point1 = stage.randomPosition(new Point(maxSize, maxSize)).add(toCenter);
8 this._point2 = stage.randomPosition(new Point(maxSize, maxSize)).add(toCenter);
9 this._point3 = stage.randomPosition(new Point(maxSize, maxSize)).add(toCenter);
10 this._color = stage.randomColor();
11 this._lineWidth = stage.randomInt(1, 50);
13 CanvasQuadraticSegment.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.quadraticCurveTo(this._point2.x, this._point2.y, this._point3.x, this._point3.y);
22 function CanvasBezierSegment(stage) {
23 var maxSize = stage.randomInt(20, 200);
24 var toCenter = stage.randomPosition(stage.size).subtract(new Point(maxSize/2, maxSize/2));
26 this._point1 = stage.randomPosition(new Point(maxSize, maxSize)).add(toCenter);
27 this._point2 = stage.randomPosition(new Point(maxSize, maxSize)).add(toCenter);
28 this._point3 = stage.randomPosition(new Point(maxSize, maxSize)).add(toCenter);
29 this._point4 = stage.randomPosition(new Point(maxSize, maxSize)).add(toCenter);
30 this._color = stage.randomColor();
31 this._lineWidth = stage.randomInt(1, 50);
33 CanvasBezierSegment.prototype.draw = function(context) {
34 context.strokeStyle = this._color;
35 context.lineWidth = this._lineWidth;
37 context.moveTo(this._point1.x, this._point1.y);
38 context.bezierCurveTo(this._point2.x, this._point2.y, this._point3.x, this._point3.y, this._point4.x, this._point4.y);
42 function CanvasArcToSegment(stage) {
43 var maxSize = stage.randomInt(20, 200);
44 var toCenter = stage.randomPosition(stage.size).subtract(new Point(maxSize/2, maxSize/2));
46 this._point1 = stage.randomPosition(new Point(maxSize, maxSize)).add(toCenter);
47 this._point2 = stage.randomPosition(new Point(maxSize, maxSize)).add(toCenter);
48 this._point3 = stage.randomPosition(new Point(maxSize, maxSize)).add(toCenter);
49 this._radius = stage.randomInt(20, 200);
50 this._color = stage.randomColor();
51 this._lineWidth = stage.randomInt(1, 50);
53 CanvasArcToSegment.prototype.draw = function(context) {
54 context.strokeStyle = this._color;
55 context.lineWidth = this._lineWidth;
57 context.moveTo(this._point1.x, this._point1.y);
58 context.arcTo(this._point2.x, this._point2.y, this._point3.x, this._point3.y, this._radius);
62 function CanvasArcSegment(stage) {
63 var maxSize = stage.randomInt(20, 200);
64 var toCenter = stage.randomPosition(stage.size).subtract(new Point(maxSize/2, maxSize/2));
66 this._point = stage.randomPosition(new Point(maxSize, maxSize)).add(toCenter);
67 this._radius = stage.randomInt(20, 200);
68 this._startAngle = stage.randomAngle();
69 this._endAngle = stage.randomAngle();
70 this._counterclockwise = stage.randomBool();
71 this._color = stage.randomColor();
72 this._lineWidth = stage.randomInt(1, 50);
74 CanvasArcSegment.prototype.draw = function(context) {
75 context.strokeStyle = this._color;
76 context.lineWidth = this._lineWidth;
78 context.arc(this._point.x, this._point.y, this._radius, this._startAngle, this._endAngle, this._counterclockwise);
82 function CanvasRect(stage) {
83 this._width = stage.randomInt(20, 200);
84 this._height = stage.randomInt(20, 200);
85 this._point = stage.randomPosition(stage.size).subtract(new Point(this._width/2, this._height/2));
86 this._color = stage.randomColor();
87 this._lineWidth = stage.randomInt(1, 20);
89 CanvasRect.prototype.draw = function(context) {
90 context.strokeStyle = this._color;
91 context.lineWidth = this._lineWidth;
93 context.rect(this._point.x, this._point.y, this._width, this._height);
97 function CanvasRectFill(stage) {
98 CanvasRect.call(this, stage);
100 CanvasRectFill.prototype.draw = function(context) {
101 context.fillStyle = this._color;
103 context.rect(this._point.x, this._point.y, this._width, this._height);
109 function CanvasPathBenchmark(suite, test, options, recordTable, progressBar) {
110 SimpleCanvasBenchmark.call(this, suite, test, options, recordTable, progressBar);
112 CanvasPathBenchmark.prototype = Object.create(SimpleCanvasBenchmark.prototype);
113 CanvasPathBenchmark.prototype.constructor = CanvasPathBenchmark;
114 CanvasPathBenchmark.prototype.createStage = function(element)
116 switch (this._options["pathType"]) {
118 return new SimpleCanvasStage(element, this._options, CanvasQuadraticSegment);
120 return new SimpleCanvasStage(element, this._options, CanvasBezierSegment);
122 return new SimpleCanvasStage(element, this._options, CanvasArcToSegment);
124 return new SimpleCanvasStage(element, this._options, CanvasArcSegment);
126 return new SimpleCanvasStage(element, this._options, CanvasRect);
128 return new SimpleCanvasStage(element, this._options, CanvasArcToSegmentFill);
130 return new SimpleCanvasStage(element, this._options, CanvasArcSegmentFill);
132 return new SimpleCanvasStage(element, this._options, CanvasRectFill);
136 window.benchmarkClient.create = function(suite, test, options, recordTable, progressBar) {
137 return new CanvasPathBenchmark(suite, test, options, recordTable, progressBar);