Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(290)

Side by Side Diff: tools/perf/page_sets/tough_canvas_cases/rendering_throughput/canvas_arcs.js

Issue 1995163002: Test page for rendering throughput for canvas arcs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
Justin Novosad 2016/05/20 18:06:09 Add a reference to say this code is based on or he
sebastienlc 2016/05/20 18:43:52 Done.
4
5 function CanvasArc() {
6 var x;
7 var y;
8 var radius;
9 var width;
10 var start_angle;
11 var end_angle;
12 var arc_speed;
13 var counterclockwise;
14 var color;
15 var is_stroke;
16
17 this.init = function(arc_speed, max_width, max_height) {
18 // initialize parameters randomly
19
20
21 num_positions_x = 7;
22 position_incr_x = Math.floor(max_width / num_positions_x);
23 this.x = Math.floor(Math.random() * num_positions_x) * position_incr_x;
24
25 num_positions_y = 7;
26 position_incr_y = Math.floor(max_height / num_positions_y);
27 this.y = Math.floor(Math.random() * num_positions_y) * position_incr_y;
28
29 var max_radius = max_height / 10;
30 // radius is in [0.5*max_radius, max_radius)
31 this.radius = ((Math.random() + 1) / 2) * max_radius;
32
33 this.width = 1 + Math.pow(Math.random(), 4) * 30;
34
35 var colors = ["#101010", "#808080", "#c0c0c0",
36 "#e01040", "#10c030", "#e05010"];
37 this.color = colors[Math.floor(Math.random() * colors.length)];
38
39 this.is_stroke = (Math.floor(Math.random() * 3) == 0);
40
41 this.counterclockwise = (Math.floor(Math.random() * 2) == 0);
42
43 this.arc_speed = (Math.random() - 0.5) * Math.PI / 10;
44 this.start_angle = Math.random() * 2 * Math.PI;
45 this.end_angle = Math.random() * 2 * Math.PI;
46 }
47
48 this.draw = function(context) {
49 this.start_angle += this.arc_speed;
50 this.end_angle += this.arc_speed / 2;
51
52 // draw the canvas arc on the given context
53 if (this.is_stroke) {
54 context.strokeStyle = this.color;
55 context.lineWidth = this.width;
56 context.beginPath();
57 context.arc(this.x, this.y, this.radius,
58 this.start_angle, this.end_angle, this.counterclockwise);
59 context.stroke();
60
61 } else {
62 context.fillStyle = this.color;
63 context.beginPath();
64 context.lineTo(this.x, this,y);
65 context.arc(this.x, this.y, this.radius, this.start_angle,
66 this.end_angle, this.couterclockwise);
67 context.lineTo(this.x, this.y);
68 context.fill();
69
70 }
71 }
72 }
73
74 var arcs = (function() {
75 var initialized_arcs;
76 var width;
77 var height;
78
79 var arcs = {};
80
81 arcs.init = function(number_arcs, arc_speed, canvas_width, canvas_height) {
82 // initialize arcs and store variables
83 initialized_arcs = [];
84 for(var i = 0; i < number_arcs; i++) {
85 var new_arc = new CanvasArc();
86 new_arc.init(arc_speed, canvas_width, canvas_height);
87 initialized_arcs.push(new_arc)
88 }
89
90 };
91
92 arcs.draw = function(context) {
93 // draw all initialized_arcs on the context
94 for(var i = 0; i < initialized_arcs.length; i++) {
95 initialized_arcs[i].draw(context);
96 }
97 };
98
99 return arcs;
100 })();
101
102
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698